Chinaunix首页 | 论坛 | 博客
  • 博客访问: 483311
  • 博文数量: 401
  • 博客积分: 244
  • 博客等级: 入伍新兵
  • 技术积分: 2215
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-04 10:02
文章分类

全部博文(401)

文章存档

2013年(37)

2012年(364)

分类:

2012-09-21 13:57:30

需求:找出某一目录下只有一行内容的文件,很多时候都会有类似的需要,代码都是如出一辙。

  1. [root@station1 ~]# mkdir findtest
  2. [root@station1 ~]# cd findtest
  3. [root@station1 findtest]# mkdir abc
  4. [root@station1 findtest]# echo "nihao" > 123.txt
  5. [root@station1 findtest]# echo "nihao" > abc/345.txt
  6. [root@station1 findtest]# echo -e "nihao\nhaha" > abc/567.txt
  7. [root@station1 findtest]# echo -e "nihao\nhaha" > 789.txt
  8. [root@station1 findtest]# find . -type f | xargs -n 1 awk 'END{printf NR == 1 ? FILENAME"\n" : ""}'
  9. ./abc/345.txt
  10. ./123.txt
  11. [root@station1 findtest]#

如果想打印出文件的全路径可以如下操作:

  1. [root@station1 ~]# find /root/findtest -type f | xargs -n 1 awk 'END{printf NR==1 ? FILENAME"\n" : ""}'
  2. /root/findtest/abc/345.txt
  3. /root/findtest/123.txt
  4. [root@station1 ~]#


阅读(302) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~