需求:列出使用最多的命令是哪些并且将这些命令输入到chy1.txt中
思路:我们的命令都是存在了历史文件/root/.bash_history 这个文件里面,这里需要将用到的命令进行排序
[root@chyshell]#vimhistory.sh #!/bin/bash #thisisliechuhistoryzuiduodmingling sort/root/.bash_history|uniq-c|sort-nr|head>/tmp/chy1.txt (脚本命令解释:uniq-c显示出现重复的次数,sort-nr以数字的形式将数字大的排在前面小的排在后面) [root@chyshell]#shhistory.sh (执行此脚本) [root@chyshell]#cat/tmp/chy1.txt 49ls 47/usr/local/apache2.4/bin/apachectlgraceful 39vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf 32ipaddr 28init0 25vim/etc/keepalived/keepalived.conf 19psaux|grepnginx 19gitpush 19cdchenhaiying/ 17mysql-uroot (并且查看输入到chy1.txt的历史内容) 希望看过的童鞋多多指教,谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。