我只想统计目录中的所有文件。我使用了两种方法:
tree /home/bkp
使用此方法的输出是2177879文件。find /home/bkp -type f | wc -l
并且还有2176704文件
有什么区别?我如何计算所有目录和子目录下的所有文件?
谢谢你!
答案1
tree
# Also output directories but not hidden files
.
├── Directory1
├── Directory2
├── File1
└── File2
tree -a
# Also output hidden files and hidden directories
.
├── Directory1
├── Directory2
├── File1
├── File2
├── .Hidden_Directory1
├── .Hidden_Directory2
├── .Hidden_File1
└── .Hidden_File2
find -type f
# Files and hidden files
./File1
./File2
./.Hidden_File1
./.Hidden_File2
tree -aifF | grep -v '/$'
# Output files and hidden files
.
./File1
./File2
./.Hidden_File1
./.Hidden_File2
-i
和参数-f
导致tree
在每行输出完整路径,而不是缩进。 参数-F
导致它在目录名称后附加一个/
,这些目录名称会被反向 grep (grep -v '/$'
) 过滤掉。
man tree
-f Prints the full path prefix for each file.
-i Makes tree not print the indentation lines, useful when
used in conjunction with the -f option. Also removes as much
whitespace as possible when used with the -J or -x options.