LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 866|回复: 5

求助几个命令

[复制链接]
发表于 2007-6-8 17:39:01 | 显示全部楼层 |阅读模式
1.Use a single command line to display all entries in the /etc/httpd/conf/httpd.conf file that are not blank and do not contain a "#". In the same command line, sort these in alphabetical order, ensuring that exact duplicate lines are only displayed once. Still in the same command line, output this to the file /tmp/sortedlines. Verify the contents of this file.

2.Display a sorted long listing, from largest to smallest, of the 10 largest files on the system.

谢谢  查了很久了  就是搞不对
发表于 2007-6-9 08:28:21 | 显示全部楼层
第一个问题可以分成几步来理解(unix):
1. display all entries (cat, sed, awk, etc) to do the display
2. filter - not blank, not "#". (sed, awk) should do.
3. sort - alpha, no dup (sort)
4. redirect.
所以,我们可以做下面的命令:
  1. sed -n '/^$\|^#/!p' | sort -u > /tmp/shortedlines
复制代码

2. just a little complex sort command. You can take a look the sort manpage.
回复 支持 反对

使用道具 举报

发表于 2007-6-10 22:39:34 | 显示全部楼层
第一个问题还可以用grep
grep "^[^#]" | sort -u > /tmp/sortedlines
回复 支持 反对

使用道具 举报

发表于 2007-6-11 08:16:15 | 显示全部楼层
获取配置文件中有效的配置:
grep -v ^\S*#  将获取那些不以#号开头的语句或者以空白符+#开头的那些语句
grep -v ^\S*$ 将获取那些不是空白行的语句

因此  grep -v ^\S*#  配置文件 | grep -v ^\S*$  将取得所有有效的配置语句

如果每个设置都是在一行的话,而且相互之间没有关联的话
grep -v ^\S*# filename | grep -v ^\S*$ | sort -bu 将得到按字符方式排序,并且相同行被忽略的配置信息

如果是需要输入到文件中,用一个重定向就可以了
grep -v ^\S*# filename | grep -v ^\S*$ | sort -bu > outfile
回复 支持 反对

使用道具 举报

发表于 2007-6-11 08:39:53 | 显示全部楼层
find ./ -type f -printf "%s %p\n" 2>/dev/null | sort -rn | head -n 10

将获取当前目录及子目录下文件大小排名前10位的文件(排列顺序从大到小)


ls -alR | grep -- ^- | sort -nr --key=5 | head -n 10
也能够获取10个文件大小最大的文件,但是不能得到全路径名
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-6-12 10:45:18 | 显示全部楼层
谢谢大家的帮忙
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表