码迷,mamicode.com
首页 > 系统相关 > 详细

Linux查看所有子文件夹及文件的数量

时间:2014-09-18 09:42:53      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   使用   文件   sp   问题   c   amp   

find命令查看(推荐):

所有子目录的数量:

[root@localhost ~]# find afish -type d | wc -l
158
[root@localhost ~]# find afish/ -type d | wc -l
158
[root@localhost ~]# find afish/* -type d | wc -l
157 --正确

结果不同的原因:
[root@localhost ~]# find afish -type d | more
afish --输出结果首行
[root@localhost ~]# find afish/* -type d | more
afish/examples --输出结果首行

总结:使用afish/*不包含afish这个父目录,只输出其下的子目录。

所有文件的数量:

[root@localhost ~]# find afish -type f | wc -l
981
[root@localhost ~]# find afish/ -type f | wc -l
981
[root@localhost ~]# find afish/* -type f | wc -l
981

tree命令查看(不推荐):

[root@localhost ~]# tree afish
……
157 directories, 978 files
-----------------------------------------
[root@localhost ~]# tree afish/
……
157 directories, 978 files

du命令查看:

[root@localhost ~]# du -ah afish/* | wc -l
1138

总结:du查看的结果为1138,子目录的数量为157,文件数量为:1138-157=981,所以tree命令查看的结果应该是不准确,至于少计算了哪个文件,没再查这个问题,推荐使用find命令查看。

 

Linux查看所有子文件夹及文件的数量

标签:style   color   os   使用   文件   sp   问题   c   amp   

原文地址:http://www.cnblogs.com/afish/p/3978521.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!