shell 練習題01:列出使用最多的命令是哪些並且將這些命令輸入到chy1.txt中
阿新 • • 發佈:2017-09-13
shell 練習題01
需求:列出使用最多的命令是哪些並且將這些命令輸入到chy1.txt中
思路:我們的命令都是存在了歷史文件/root/.bash_history 這個文件裏面,這裏需要將用到的命令進行排序
[[email protected] 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以數字的形式將數字大的排在前面小的排在後面) [[email protected] shell]# sh history.sh (執行此腳本) [[email protected] 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:列出使用最多的命令是哪些並且將這些命令輸入到chy1.txt中