找出某一目录下只有一行内容的文件的shell脚本
时间:2014-09-10 21:56 来源:linux.it.net.cn 作者:it
需求:找出某一目录下只有一行内容的文件。
演示例子,如下所示:
复制代码代码如下:
[root@station1 ~]# mkdir findtest
[root@station1 ~]# cd findtest
[root@station1 findtest]# mkdir abc
[root@station1 findtest]# echo "nihao" > 123.txt
[root@station1 findtest]# echo "nihao" > abc/345.txt
[root@station1 findtest]# echo -e "nihaonhaha" > abc/567.txt
[root@station1 findtest]# echo -e "nihaonhaha" > 789.txt
[root@station1 findtest]# find . -type f | xargs -n 1 awk 'END{printf NR == 1 ? FILENAME"n" : ""}'
./abc/345.txt
./123.txt
[root@station1 findtest]#
打印出文件的全路径,可以这样操作:
复制代码代码如下:
[root@station1 ~]# find /root/findtest -type f | xargs -n 1 awk 'END{printf NR==1 ? FILENAME"n" : ""}'
/root/findtest/abc/345.txt
/root/findtest/123.txt
[root@station1 ~]#
(责任编辑:IT)
需求:找出某一目录下只有一行内容的文件。
演示例子,如下所示:
复制代码代码如下:
[root@station1 ~]# mkdir findtest
[root@station1 ~]# cd findtest [root@station1 findtest]# mkdir abc [root@station1 findtest]# echo "nihao" > 123.txt [root@station1 findtest]# echo "nihao" > abc/345.txt [root@station1 findtest]# echo -e "nihaonhaha" > abc/567.txt [root@station1 findtest]# echo -e "nihaonhaha" > 789.txt [root@station1 findtest]# find . -type f | xargs -n 1 awk 'END{printf NR == 1 ? FILENAME"n" : ""}' ./abc/345.txt ./123.txt [root@station1 findtest]#
打印出文件的全路径,可以这样操作:
复制代码代码如下:
[root@station1 ~]# find /root/findtest -type f | xargs -n 1 awk 'END{printf NR==1 ? FILENAME"n" : ""}'
(责任编辑:IT)/root/findtest/abc/345.txt /root/findtest/123.txt [root@station1 ~]# |