看看你用得最多的命令是什么
来源:互联网 发布:php json 汉字乱码 编辑:程序博客网 时间:2024/04/29 23:52
在 Ubuntu China 的论坛上看到一个比较有意思的帖子,楼主用一行命令查看自己最近使用的最多的命令。
history | awk '{print $2}' | awk 'BEGIN {FS="|"} {print $1}' | sort -rn | uniq -c | sort -rn | head
由于 Ubuntu 限制 root 用户的滥用,所以很多 Ubuntu 用户使用系统命令时往往都是通过 sudo 来执行的,而上面的命令没有考虑到这种情况。于是我自己试着用 Ruby 写了一个类似功能的脚本程序,这样可以将 sudo 所执行的命令也计算进来。刚刚运行了一下我的程序
history | ruby top_command.rb | head
结果为
105 ls
73 cd
43 vim
42 ll
25 sudo
22 ruby
18 history
17 grep
13 rm
12 mv
我没事就习惯性的 ls 一下,看来比例还是满高的,呵呵。
脚本程序内容如下:
#!/usr/bin/ruby
# Filename: top_command.rb
# Author: Patrick He
# Date: 10/01/2006
commands = Hash.new(0)
ARGF.each do |line|
words = line.split
commands[words[1]] = commands[words[1]] + 1
if words[1] == 'sudo'
commands[words[2]] = commands[words[2]] + 1
end
end
comArr = commands.sort {|a, b| b[1]<=>a[1]}
comArr.each {|line| print "#{line[1]}/t#{line[0]}/n"}
history | awk '{print $2}' | awk 'BEGIN {FS="|"} {print $1}' | sort -rn | uniq -c | sort -rn | head
由于 Ubuntu 限制 root 用户的滥用,所以很多 Ubuntu 用户使用系统命令时往往都是通过 sudo 来执行的,而上面的命令没有考虑到这种情况。于是我自己试着用 Ruby 写了一个类似功能的脚本程序,这样可以将 sudo 所执行的命令也计算进来。刚刚运行了一下我的程序
history | ruby top_command.rb | head
结果为
105 ls
73 cd
43 vim
42 ll
25 sudo
22 ruby
18 history
17 grep
13 rm
12 mv
我没事就习惯性的 ls 一下,看来比例还是满高的,呵呵。
脚本程序内容如下:
#!/usr/bin/ruby
# Filename: top_command.rb
# Author: Patrick He
# Date: 10/01/2006
commands = Hash.new(0)
ARGF.each do |line|
words = line.split
commands[words[1]] = commands[words[1]] + 1
if words[1] == 'sudo'
commands[words[2]] = commands[words[2]] + 1
end
end
comArr = commands.sort {|a, b| b[1]<=>a[1]}
comArr.each {|line| print "#{line[1]}/t#{line[0]}/n"}
- 看看你用得最多的命令是什么
- 想看看你是什么星座的吗
- 看看你得眼光与投资人的差距有多远
- 看看全球用户在线时间最多的20个网站是什么
- 让我看看你是什么颜色的性格
- 卸下你的 眼镜看看这个是什么!!!好玩啊
- IT认证薪水大比拼 看看谁拿得最多
- IT认证薪水大比拼 看看谁拿得最多
- 你你你你你你得看看
- 查看你使用最多的10条shell命令
- 看看你这个软件测试人是什么水平
- 我的面试题:你重写次数最多的代码的场景是什么?
- 我的面试题:你重写次数最多的代码的场景是什么?
- 测试一下看看你是不是通得过自已对自已的考验
- 看看这个最简单的代码,你能看得懂吗
- 电梯里被按得最多的键
- 自我分析软件V1.0 - 预览版 - 看看你的内在星座是什么?
- 看看你的殺毒軟件有多強!
- CC_JS
- Eassay_JS
- asp.net WebForm页面间传值方法
- 配置新的电脑桌
- 国庆七天为国七天
- 看看你用得最多的命令是什么
- Clean Command
- 使用 Linux 文本工具简化数据的提取
- Petri网计算系统讲义
- 郑昀的推荐中文十大知名技术Blog
- 数据库连接池
- In Search Of ASP.Net Controls
- 模版页中引用文件路径的问题
- 根据html页面模板动态生成html页面(c#类)