教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 找出某一目录下只有一行内容的文件的shell脚本

找出某一目录下只有一行内容的文件的shell脚本

发布时间:2014-09-19   编辑:jiaochengji.com
需求:找出某一目录下只有一行内容的文件。

需求:找出某一目录下只有一行内容的文件。

演示例子,如下所示:
 

复制代码 代码如下:
[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 ~]#

您可能感兴趣的文章:
找出某一目录下只有一行内容的文件的shell脚本
python shell是什么
bash shell脚本执行的几种方法
source命令执行shell文件与shell script文件名直接运行的区别
inux shell初级入门教程
(原创)shell查找符号链接及其指向目标的方法介绍
cat命令和EOF标识输出多行文件
查找目录及子目录中同名文件的shell脚本(图文)
深入解析tcsh的初始化配置文件
Linux Source命令解析

[关闭]
~ ~