Linux Command & Shell Tips (1)
此文用于记录使用 Linux 过程中的与 shell 和 commands 有关的有意思的小知识。
1. The problem of ftp url:
在写一个自动备份的脚本时发现,如果 username 中有 @ 符号时,使用 curl ftp://username:password@host/file 是不行的。这可能是 ftp url 地址格式的一个瑕疵。具体参考 Google Group上的一个讨论 (对于该讨论的正确性本人没有特别考证, 根据作者的观点,在整个URL中出现 “:”、”/”、”@” 都是不可行的。如果您发现此论断有问题请留言)。 还好 curl 可以使用 -n 指定使用 ~/.netrc 中的登录标识。
2. 直接使用 sed 命令批量替换文件中的内容
sed -i 's/\/var\/svn/d:\/data\/svn/g' `grep /var/svn -rl ./*/conf/trac.ini`
sed 命令还有很多用法,可惜平时用得不多,经常忘记了要查资料。
3. 使用 find 命令批量操作 Trac 项目同步SVN
find -maxdepth 1 -mindepth 1 -type d -print -exec trac-admin {} resync \;对仅仅处理当前目录下的子目录的限定方法比较笨,也许有更好的方法。
4. tar error message.
Removing leading `/’ from member names
It’s really annoying when it present in a crontab script. That is why (refer from here):
what do you want suggestions about? tar archives don’t contain absolute paths, only relative ones. this is correct behaviour, as the alternative is really nasty and illogical. this is the same way that other compression programs like winzip work. when you untar somethign you provide an destination directory, which implicity is ‘/’ in your case… but it should be explicit for logical operation
The resolution is using relative path. e.g.
cd /var/www tar -cf /home/user/backup/wp-backup.tar web # NOT below # cd /home/user/backup # tar -cf wp-backup.tar /var/www/web
5. svn: Delete unversioned files
svn status --no-ignore | grep '^[I?]' | sed 's/^[I?]//' | xargs rm -rf
Here are more frequent ask questions on subversion.
6. 防火墙后面的git通过代理访问:
设置GIT_PROXY_COMMAND系统变量即可。具体参考:Using Git with a SOCKS proxy
7. Ubuntu添加sudo用户:
Edit file /etc/sudoers, add line:
bob ALL=(ALL) ALL
参考:http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch09_:_Linux_Users_and_Sudo
最近评论