写一个shell脚本来看看你最喜欢敲的命令是哪个?然后列出你最喜欢敲的命令top10。
思路:我们要用到一个文件就是.bash_history,然后再去sort、uniq,剩下的就不用我多说了吧。很简单一个shell。
思路:我们要用到一个文件就是.bash_history,然后再去sort、uniq,剩下的就不用我多说了吧。很简单一个shell。
0
本帖最后由 butterfly梧桐雨 于 2014-9-17 20:04 编辑
[root@myCentOS sbin]# cat ~/.bash_history | sort | uniq -c | sort -rn | head -n 10 | sed 's/[0-9]//g'
ls
ll
bash check.sh
vim check.sh
ifconfig
cd ..
cd .ssh
head .txt| awk '{print $NR}'
fdisk -l
exit
感觉不太完美,显示出来的结果,最后的那些行,是统计次数为个位数的,空格还在,所以没有对齐,感觉sed用得不太好,可是用awk,只会awk '{print $1}', 不知道怎么打印除了$1以外的列, 等待大家更好的答案
明白了,只要命令不需要命令的参数,所以只要第2列就可以了
[root@myCentOS ~]# cat ~/.bash_history | awk '{print $1}' | sort |uniq -c | sort -rn |head -n 10 |sed "$i"'p' -n | awk '{print $2}'
ls
head
cd
cat
ll
vim
grep
yum
bash
ifconfig
[root@myCentOS sbin]# cat ~/.bash_history | sort | uniq -c | sort -rn | head -n 10 | sed 's/[0-9]//g'
ls
ll
bash check.sh
vim check.sh
ifconfig
cd ..
cd .ssh
head .txt| awk '{print $NR}'
fdisk -l
exit
感觉不太完美,显示出来的结果,最后的那些行,是统计次数为个位数的,空格还在,所以没有对齐,感觉sed用得不太好,可是用awk,只会awk '{print $1}', 不知道怎么打印除了$1以外的列, 等待大家更好的答案
明白了,只要命令不需要命令的参数,所以只要第2列就可以了
[root@myCentOS ~]# cat ~/.bash_history | awk '{print $1}' | sort |uniq -c | sort -rn |head -n 10 |sed "$i"'p' -n | awk '{print $2}'
ls
head
cd
cat
ll
vim
grep
yum
bash
ifconfig
0
本帖最后由 wyatt88 于 2014-9-16 23:31 编辑
#!/bin/bash
#ww
for i in `seq 1 10`
do
#echo $i
topi=`cat /root/.bash_history | awk '{print $1}' | sort |uniq -c | sort -rn |head -n 10 |sed "$i"'p' -n`
echo "top $i is `echo $topi | awk '{print $2}'` ","count: `echo $topi | awk '{print $1}'`"
done
结果:
top 1 is ls ,count: 99
top 2 is vim ,count: 60
top 3 is cd ,count: 54
top 4 is man ,count: 36
top 5 is sh ,count: 23
top 6 is date ,count: 21
top 7 is ifconfig ,count: 19
top 8 is df ,count: 15
top 9 is cat ,count: 15
top 10 is yum ,count: 14
#!/bin/bash
#ww
for i in `seq 1 10`
do
#echo $i
topi=`cat /root/.bash_history | awk '{print $1}' | sort |uniq -c | sort -rn |head -n 10 |sed "$i"'p' -n`
echo "top $i is `echo $topi | awk '{print $2}'` ","count: `echo $topi | awk '{print $1}'`"
done
结果:
top 1 is ls ,count: 99
top 2 is vim ,count: 60
top 3 is cd ,count: 54
top 4 is man ,count: 36
top 5 is sh ,count: 23
top 6 is date ,count: 21
top 7 is ifconfig ,count: 19
top 8 is df ,count: 15
top 9 is cat ,count: 15
top 10 is yum ,count: 14
0
本帖最后由 程城 于 2014-9-17 02:05 编辑
#!/bin/bash
#written by chengcheng.
haha=`less ~/.bash_history |sort -n |uniq -c|sort -rn|head -10`
echo "$haha"
或者:
haha=`less ~/.bash_history |sort -n |uniq -c|sort -rn|head -10`
echo "$haha" | awk '{print $2}'
#!/bin/bash
#written by chengcheng.
haha=`less ~/.bash_history |sort -n |uniq -c|sort -rn|head -10`
echo "$haha"
或者:
haha=`less ~/.bash_history |sort -n |uniq -c|sort -rn|head -10`
echo "$haha" | awk '{print $2}'
0
[root@localhost ~]# cat ~/.bash_history | awk '{print $1}' | sort | uniq -c | sort -nr | head
147 ll
129 sh
102 vim
96 sed
86 cd
71 cat
63 grep
49 ls
32 rm
23 echo
147 ll
129 sh
102 vim
96 sed
86 cd
71 cat
63 grep
49 ls
32 rm
23 echo
0
- awk '{print $1}' .bash_history |sort |uniq -c |sort -rn |head
- 164 cat
- 134 ls
- 97 vim
- 69 sh
- 56 ps
- 46 cd
- 27 awk
- 26 date
- 17 yum
- 17 ping
0
我怎么还有显示中文
[root@centos33 shell]# cat /root/.bash_history |sort -n|uniq -c|sort -nr|head -10|awk '{ print $1,$2}'
68 ls
17 echo
8 ssh
7 cd
6 service
6 cd
5 openssl
5 getenforce
4 正在启动
4 vi
[root@centos33 shell]# cat /root/.bash_history |sort -n|uniq -c|sort -nr|head -10|awk '{ print $1,$2}'
68 ls
17 echo
8 ssh
7 cd
6 service
6 cd
5 openssl
5 getenforce
4 正在启动
4 vi
0
cat /root/.bash_history |awk '{print $1}'|sed 's/[^a-z]//g'|sed '/^$/d'|sort -n|uniq -c|sort -nr|head
78 ls
72 cd
26 cat
25 service
17 echo
15 vi
15 rootcentos
14 yum
13 make
10 awk
78 ls
72 cd
26 cat
25 service
17 echo
15 vi
15 rootcentos
14 yum
13 make
10 awk
0
本帖最后由 jaws1689 于 2014-9-17 20:08 编辑
cat /root/.bash_history |awk '{print $1}'|sort|uniq -c|sort -nr|head -10
125 sed
108 vim
89 sh
82 cat
80 grep
72 awk
59 ls
55 printf
44 date
44 cd
cat /root/.bash_history |awk '{print $1}'|sort|uniq -c|sort -nr|head -10
125 sed
108 vim
89 sh
82 cat
80 grep
72 awk
59 ls
55 printf
44 date
44 cd
0
cat .bash_history | sort | uniq -c | sort -rn | head
252 ls
109 cd ..
49 cd bin
27 cd logs
25 vi catalina.out
23 ./startup.sh
23 ./shutdown.sh
21 bash 1.sh
19 vi 1.sh
15 cd webapps
252 ls
109 cd ..
49 cd bin
27 cd logs
25 vi catalina.out
23 ./startup.sh
23 ./shutdown.sh
21 bash 1.sh
19 vi 1.sh
15 cd webapps
0
cat .bash_history| awk '{sum[$1]++}END{for(i in sum) print sum,i}' | sort -nr | head
或者是
awk '{sum[$1]++}END{for(i in sum) print sum,i}' .bash_history | sort -nr | head
459 ls
198 cd
197 sudo
97 exit
63 ssh
54 ll
46 vim
46 ping
40 rm
37 svn
或者是
awk '{sum[$1]++}END{for(i in sum) print sum,i}' .bash_history | sort -nr | head
459 ls
198 cd
197 sudo
97 exit
63 ssh
54 ll
46 vim
46 ping
40 rm
37 svn
0
你这是经常重启tomcat的人啊,工作环境常用?
chenzudao1234 发表于 2014-9-17 16:44
cat .bash_history | sort | uniq -c | sort -rn | head
252 ls
109 cd ..
你这是经常重启tomcat的人啊,工作环境常用?
0
- cat ~/.bash_history | awk '{print $1}' |sort | uniq -c |sort -rn|head
- 133 ll
- 88 vi
- 87 cd
- 62 tail
- 60 bash
- 55 more
- 38 sh
- 32 service
- 32 df
- 30 ls
0
- #!/bin/bash
- ## This script is for list top 10 commands you have inputted in history.
- ## Written by Louis at 2014/09/17 17:45
- awk '{print $1}' ~/.bash_history|sort|uniq -c|sort -nr|head
- 结果:
- 137 vim
- 123 ls
- 96 bash
- 74 df
- 65 cat
- 41 cd
- 33 touch
- 32 grep
- 29 if
- 27 find
0
#!/bin/bash
msg=`sort /root/.bash_history |uniq -c >/tmp/17.txt`
top=`sort -nr -k1 /tmp/17.txt |head|awk '{print $2}'`
echo "command top10 is $top"
msg=`sort /root/.bash_history |uniq -c >/tmp/17.txt`
top=`sort -nr -k1 /tmp/17.txt |head|awk '{print $2}'`
echo "command top10 is $top"
0
#/bin/bash
top=`cat /root/.bash_history |awk '{print $1}'|sort -n|uniq -c|sort -nr|head|awk '{print $2}'|cat -n`
echo "The top 10 usesul commond:"
echo "$top"
执行结果:
[root@arthur sbin]# sh top.sh
The top 10 usesul commond:
1 vim
2 ls
3 head
4 cd
5 apachectl
6 sh
7 cat
8 yum
9 grep
10 ifconfig
top=`cat /root/.bash_history |awk '{print $1}'|sort -n|uniq -c|sort -nr|head|awk '{print $2}'|cat -n`
echo "The top 10 usesul commond:"
echo "$top"
执行结果:
[root@arthur sbin]# sh top.sh
The top 10 usesul commond:
1 vim
2 ls
3 head
4 cd
5 apachectl
6 sh
7 cat
8 yum
9 grep
10 ifconfig
0
本帖最后由 qq20847697 于 2015-3-11 09:15 编辑
cat ~/.bash_history |awk '{print $1}'|sort|uniq -c|sort -nr|head
cat ~/.bash_history |awk '{print $1}'|sort|uniq -c|sort -nr|head
0
本帖最后由 蓝色风暴 于 2015-12-24 14:23 编辑
cat .bash_history | awk '{print $1}' | sort | uniq -c | sort -nt' ' -k1 | tail -10
cat .bash_history | awk '{print $1}' | sort | uniq -c | sort -nt' ' -k1 | tail -10
0
[root@aliyun-63 309]# history | awk '{print $2}' | sort | uniq -c | sort -nr | head -10
229 awk
115 cat
81 sed
81 ll
45 find
35 cd
33 vi
33 dstat
32 date
31 nmap
[root@aliyun-63 309]#
229 awk
115 cat
81 sed
81 ll
45 find
35 cd
33 vi
33 dstat
32 date
31 nmap
[root@aliyun-63 309]#
0
cat /root/.bash_history |sort -n|uniq -c|sort -n|awk '{print $2}'|sort -n|uniq -c|sort -nr|head -n 10
0
你牛啊,兄弟,哈哈{:4_117:}
木字当头 发表于 2014-9-17 10:49
我怎么还有显示中文
[root@centos33 shell]# cat /root/.bash_history |sort -n|uniq -c|sort -nr|head -1 ...
你牛啊,兄弟,哈哈{:4_117:}
编辑回复