文章标签 » shell

[bookmark]统计最常使用的命令

v2ex看到一条统计最常用命令的脚本,收藏一下~

$ history | awk '{CMD[$2]++;count++;} END { for (a in CMD )print CMD[ a ]" " CMD[ a ]/count*100 "% " a }' | grep -v "./" | column -c3 -s " " -t |sort -nr | nl | head -n10
1 167 33.4% vim
2 104 20.8% ls
3 75 15% make
4 25 5% cd
5 13 2.6% sshgo
6 11 2.2% telnet
7 11 2.2% sudo
8 10 2% find
9 5 1% mv
10 4 0.8% ps

from:http://v2ex.com/t/98373

backup:批量的顺序编辑文件

实践证明,不记一下,一个错误真的会犯n次都不长记性。。。之前shell备份里已有笨办法一个

find -name "*.php"|xargs grep -l "<script"|sudo xargs sudo vim

报错:

Vim: Warning: Input is not from a terminal

原因:http://stackoverflow.com/questions/3852616/xargs-with-command-that-open-editor-leaves-shell-in-weird-state
The problem is that since you’re running xargs (and hence git and hence vim) in a pipeline, its stdin is taken from the output of cat projectPaths rather than the terminal; this is confusing vim. Fortunately, the solution is simple: add the -o flag to xargs, and it’ll start git (and hence vim) with input from /dev/tty, instead of its own stdin.

乱马~

~/.bashrc

#flex sdk在ubuntu上好好的,到了mac os下就乱码了~~!
mxmlc()
{
    /Users/hualu/opt/flex_sdk_4.1.0.16076/bin/mxmlc $* | iconv -f gb2312 -t utf-8
}
 
#tree,一条基本不用的命令,给同学发目录列表用过一次,中文会被编码
tree()
{
    /opt/local/bin/tree $* | ascii2uni -aK
}

shell下批量标记mp3标签

#设置歌手
mid3v2 -a "歌手" *.mp3
#设置专辑名
mid3v2 -A "专辑名" *.mp3
#用文件名标记mp3的title
find -name "*.mp3" | while read file;do mid3v2 -t "`echo $file|sed -e 's/^\.\///g' -e 's/.mp3$//g'`" "$file";done

———–
post by gmail~

shell中获取登录用户名

获取当前用户登录的终端号

lu@hualu-laptop:~$ tty|cut -d/ -f 3-
pts/2
lu@hualu-laptop:~$ ps |grep $$ |awk '{print $2}'
pts/2

如果大家都su到同一帐号下,$USER就不可信了,可以根据终端号查到真正的用户名

tty=`ps|grep $$|awk '{print $2}'`
user=`who|grep ${tty}|awk '{print $1}'`

参考:http://www.ixpub.net/thread-1460130-1-1.html

———–
post by gmail~