CLI的几个小技巧

时间:2014-10-31 14:28来源:未知 作者:众诚志联撰 点击:
1 让man手册更智能 man () { /usr/bin/man $@ || (help $@ 2 /dev/null help $@ | less) }有时候可能寻找某些命令的man而无果,这里将man包装成一个函数,首先调用man,不成功则调用help来查询帮助,当然不仅仅可以使用help,还有比如whatis whereis apropos whic

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上关闭或者重启Windownet 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中文社区,在每个帖子下边总有可爱的tips2 commandlinefu.com是个非常好的。
 

友情链接:沈阳服务器托管 沈阳服务器租用 幼儿园监控 高考试题

地址:辽宁省沈阳市和平区三好街79号A1501室
技术支持:沈阳市众诚志联网络技术有限公司