How can I find all zero-byte files in a directory and even in subdirectories?
如何在目录甚至子目录中找到所有的零字节文件?
I have done this:
我所做的:
#!/bin/bash
lns=`vdir -R *.* $dir| awk '{print $8"\t"$5}'`
temp=""
for file in $lns
do
if test $file = "0"
then
printf $temp"\t"$file"\n"
fi
temp=$file
done
but I only get results in that directory file not all files and if any file name has a space then I get only first word followed by tab
但是我只在那个目录文件中得到结果而不是所有的文件,如果任何文件名都有空格,那么我只会得到第一个单词后面跟着tab
Can anyone help me?
谁能帮我吗?
4 个解决方案
#1
103
To print the names of all files in and below $dir of size 0:
打印大小为0的$dir内及以下所有文件的名称:
find "$dir" -size 0
Note that not all implementations of find
will produce output by default, so you may need to do:
注意,并不是所有find的实现都默认生成输出,所以您可能需要这样做:
find "$dir" -size 0 -print
#2
16
As addition to the answers above:
除上述答案外:
If you would like to delete those files
如果您想删除这些文件。
find $dir -size 0 -type f -delete
#3
5
No, you don't have to bother grep.
不,你不必麻烦grep。
find $dir -size 0 ! -name "*.xml"
#4
2
This is the correct way to search for size 0:
这是搜索0码的正确方法:
find /path/to/dir -size 0 -type f -name "*.xml"
Search for multiple file extensions of size 0:
搜索多个大小为0的文件扩展名:
find /path/to/dir -size 0 -type f \( -iname \*.css -o -iname \*.js \)
Note: If you removed the \( ... \) the results would be all of the files that meet this requirement hence ignoring the size 0.
注意:如果你去掉了\(……)结果将是所有满足此要求的文件,因此忽略大小0。
#1
103
To print the names of all files in and below $dir of size 0:
打印大小为0的$dir内及以下所有文件的名称:
find "$dir" -size 0
Note that not all implementations of find
will produce output by default, so you may need to do:
注意,并不是所有find的实现都默认生成输出,所以您可能需要这样做:
find "$dir" -size 0 -print
#2
16
As addition to the answers above:
除上述答案外:
If you would like to delete those files
如果您想删除这些文件。
find $dir -size 0 -type f -delete
#3
5
No, you don't have to bother grep.
不,你不必麻烦grep。
find $dir -size 0 ! -name "*.xml"
#4
2
This is the correct way to search for size 0:
这是搜索0码的正确方法:
find /path/to/dir -size 0 -type f -name "*.xml"
Search for multiple file extensions of size 0:
搜索多个大小为0的文件扩展名:
find /path/to/dir -size 0 -type f \( -iname \*.css -o -iname \*.js \)
Note: If you removed the \( ... \) the results would be all of the files that meet this requirement hence ignoring the size 0.
注意:如果你去掉了\(……)结果将是所有满足此要求的文件,因此忽略大小0。