CLI的几个小技巧

4
2011
# 作者: freetstar / 本文采用CC BY-NC-SA 2.5协议授权,转载请注明本文链接

1 让man手册更智能

man () {
/usr/bin/man $@ || (help $@ 2> /dev/null && help $@ | less)
}
有时候可能寻找某些命令的man而无果,这里将man包装成一个函数,首先调用man,不成功则调用help来查询帮助,当然不仅仅可以使用help,
还有比如whatis whereis apropos which
将此函数放到.bashrc或者shell对应的rc配置文件中,然后重启shell或者source之
2让显示dd的进度
dd if=/dev/zero of=/tmp/foo&
watch -n 10 pkill -USR1 ^dd$    

dd接收到SIGUSR1信号时会输出当前的读写进度,这样子加上watch就可以动态查看dd的进度了

3 安全使用rm,避免一个空格引起的血案^_^

#safe remove, mv the files to .Trash with unique name
#and log the acction
function rm()
{
 trash="$HOME/.Trash"
 log="/var/log/trash.log"
 stamp=`date "+%Y-%m-%d %H:%M:%S"` #current time

 while [ -f "$1" ]; do

 #remove the possible ending /
 file=`echo $1 |sed 's#\/$##' `

 pure_filename=`echo $file  |awk -F / '{print $NF}' |sed -e "s#^\.##" `

 if [ `echo $pure_filename | grep "\." ` ]; then
   new_file=` echo $pure_filename |sed -e "s/\([^.]*$\)/$RANDOM.\1/" `
   else
   new_file="$pure_filename.$RANDOM"
 fi

 trash_file="$trash/$new_file"
 mv "$file" "$trash_file"

 if [ -w $log ]; then
   echo -e "[$stamp]\t$file\t=>\t[$trash_file]" |tee -a $log
   else
   echo -e "[$stamp]\t$file\t=>\t[$trash_file]"
 fi

 shift   #increment the loop
 done
}
4 在Linux上关闭或者重启Window
net rpc shutdown -I ipAddressOfWindowsPC -U username%password //关闭
net rpc shutdown -r : reboot the Windows machine //重启
net rpc abortshutdown : abort shutdown of the Windows machine //放弃关闭
需要安装samba-common包,并且username必须为administrator

几个获取有趣和高效CLI Tips的途径
1 多多围观Ubuntu中文社区,在每个帖子下边总有可爱的tips
2 commandlinefu.com是个非常好的,汇集了n多好点子的网站
3 多有心留意大家日常交流来获取

资料按顺序分别引自:here,here,here

作者:freetstar

Bio: 关注和奉献Tianjin Linux User Group的建设,关注开源社区,Linux爱好者,python lover,希望成为一名geek,求交流求指导
链接:Blog - Twitter - Facebook - 此作者的更多文章

4 Responses to CLI的几个小技巧

Avatar

btw616

Firefox 5.0 Firefox 5.0 GNU/Linux GNU/Linux

七月 4th, 2011 at 9:30 下午

第一个和第三个很赞。

[Reply]

Avatar

T2

Google Chrome 12.0.742.112 Google Chrome 12.0.742.112 GNU/Linux GNU/Linux

七月 5th, 2011 at 1:31 上午

dd和rm的很实用,最近正准备把rm改一下。

[Reply]

Avatar

张刚

Google Chrome 12.0.742.112 Google Chrome 12.0.742.112 GNU/Linux GNU/Linux

七月 5th, 2011 at 8:37 上午

还好一直都知道cli的强大,使用的时候都非常的小心

[Reply]

Avatar

CLI 的几个小技巧 : OSMSG

WordPress 3.1.3 WordPress 3.1.3

七月 6th, 2011 at 9:29 上午

[...] –#原文链接 [...]

Comment Form

top

无觅相关文章插件,快速提升流量