您的位置:首页 > 运维架构 > Shell

shell 练习题01:列出使用最多的命令是哪些并且将这些命令输入到chy1.txt中

2017-09-12 23:51 267 查看
需求:列出使用最多的命令是哪些并且将这些命令输入到chy1.txt中
思路:我们的命令都是存在了历史文件/root/.bash_history 这个文件里面,这里需要将用到的命令进行排序
[root@chy shell]# vim history.sh
#!/bin/bash
#this is liechu history zuiduodmingling
sort /root/.bash_history |uniq -c |sort -nr |head >/tmp/chy1.txt
(脚本命令解释:uniq -c 显示出现重复的次数,sort -nr以数字的形式将数字大的排在前面小的排在后面)
[root@chy shell]# sh history.sh
(执行此脚本)
[root@chy shell]# cat /tmp/chy1.txt
49 ls
47 /usr/local/apache2.4/bin/apachectl graceful
39 vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
32 ip addr
28 init 0
25 vim /etc/keepalived/keepalived.conf
19 ps aux |grep nginx
19 git push
19 cd chenhaiying/
17 mysql -uroot
(并且查看输入到chy1.txt的历史内容)
希望看过的童鞋多多指教,谢谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell 练习题 01
相关文章推荐