Linux 列出当前目录和所有子目录中超过特定大小的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13282786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
List files over a specific size in current directory and all subdirectories
提问by eveo
How can I display all files greater than 10k bytes in my current directory and it's subdirectories.
如何在当前目录及其子目录中显示所有大于 10k 字节的文件。
Tried ls -size +10k
but that didn't work.
试过了,ls -size +10k
但没有奏效。
采纳答案by matchew
find . -size +10k -exec ls -lh {} \+
find . -size +10k -exec ls -lh {} \+
the first part of this is identical to @sputnicks answer, and sucesffully finds all files in the directory over 10k (don't confuse k with K), my addition, the second part then executes ls -lh
or ls that lists(-l) the files by human readable size(-h). negate the h if you prefer. of course the {}
is the file itself, and the \+
is simply an alternative to \;
第一部分与@sputnicks 答案相同,并且成功地找到了目录中超过 10k 的所有文件(不要将 k 与 K 混淆),我的补充,然后第二部分执行ls -lh
或 ls 列出(-l)文件通过人类可读的大小(-h)。如果您愿意,请否定 h。当然,这{}
是文件本身,而这\+
只是替代\;
which in practice \;
would repeat or:
在实践中\;
会重复或:
ls -l found.file; ls -l found.file.2; ls -l found.file.3
ls -l found.file; ls -l found.file.2; ls -l found.file.3
where \+
display it as one statement or:
将其\+
显示为一个语句或:
ls -l found.file found.file.2 found.file.3
ls -l found.file found.file.2 found.file.3
more on \; vs +with find
更多关于\; vs +与find
Additionaly, you may want the listing ordered by size. Which is relatively easy to accomplish. I would at the -s
option to ls
, so ls -ls
and then pipe it to sort -n
to sort numerically
此外,您可能希望按尺寸排序列表。这是比较容易实现的。我可以-s
选择ls
, sols -ls
然后通过管道将其sort -n
按数字排序
which would become:
这将成为:
find . -size +10k -exec ls -ls {} \+ | sort -n
find . -size +10k -exec ls -ls {} \+ | sort -n
or in reverse order add an -r :
或以相反的顺序添加 -r :
find . -size +10k -exec ls -ls {} \+ | sort -nr
find . -size +10k -exec ls -ls {} \+ | sort -nr
finally, your title says find biggestfile in directory. You can do that by then piping the code to tail
最后,你的标题说在目录中找到最大的文件。您可以通过将代码管道化到tail
find . -size +10k -exec ls -ls {} \+ | sort -n | tail -1
would find you the largest file in the directory and its sub directories.
find . -size +10k -exec ls -ls {} \+ | sort -n | tail -1
会找到目录及其子目录中最大的文件。
note you could also sort files by size by using -S, and negate the need for sort. but to find the largest file you would need to use head so
请注意,您还可以使用 -S 按大小对文件进行排序,并且不需要排序。但是要找到最大的文件,您需要使用 head 所以
find . -size +10k -exec ls -lS {} \+ | head -1
find . -size +10k -exec ls -lS {} \+ | head -1
the benefit of doing it with -S and not sort
is one, you don't have to type sort -n
and two you can also use -h
the human readable size option. which is one of my favorite to use, but is not available with older versisions of ls
, for example we have an old centOs 4 server at work that doesn't have -h
使用 -S 而不是这样做的好处sort
是一,您不必键入sort -n
,二您还可以使用-h
人类可读的大小选项。这是我最喜欢使用的一种,但不适用于旧版本的ls
,例如我们有一个旧的centOs 4服务器在工作,它没有-h
回答by Gilles Quenot
Try doing this:
尝试这样做:
find . -size +10k -ls
And if you want to use the binary ls
:
如果你想使用二进制文件ls
:
find . -size +10k -exec ls -l {} \;
回答by jens-na
You may use lslike that:
你可以像这样使用ls:
ls -lR | egrep -v '^d' | awk '>10240{print}'
Explanation:
解释:
ls -lR # list recursivly
egrep -v '^d' # only print lines which do not start with a 'd'. (files)
only print lines where the fifth column (size) is greater that 10240 bytes:
仅打印第五列(大小)大于 10240 字节的行:
awk '>10240{print}'
回答by holychiz
I'll add to @matchew answer (not enough karma points to comment):
我将添加到@matchew 答案(没有足够的业力点来评论):
find . -size +10k -type f -maxdepth 1 -exec ls -lh {} \; > myLogFile.txt
-type f :specify regular file type
-type f :指定常规文件类型
-maxdepth 1 :make sure it only find files in the current directory
-maxdepth 1 :确保它只在当前目录中找到文件
回答by UnixMakesMeSad
I realize the assignment is likely long over. For anyone else:
我意识到任务可能早就结束了。对于其他人:
You are overcomplicating.
你太复杂了。
find . -size +10k