列出当前目录和所有子目录中特定大小的文件 [英] List files over a specific size in current directory and all subdirectories
问题描述
如何在当前目录及其子目录中显示所有大于 10k 字节的文件.
How can I display all files greater than 10k bytes in my current directory and it's subdirectories.
试过 ls -size +10k
但没用.
推荐答案
find .-size +10k -exec ls -lh {} +
第一部分与@sputnicks 答案相同,并成功找到目录中超过 10k 的所有文件(不要将 k 与 K 混淆),我的补充是,第二部分然后执行 ls -lh
或 ls 按人类可读大小 (-h) 列出 (-l) 文件.如果您愿意,请否定 h.当然 {}
是文件本身,而 +
只是 ;
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 ;
实际上 ;
会重复或:
ls -l found.file;ls -l 找到.file.2;ls -l found.file.3
其中 +
将其显示为一个语句或:
where +
display it as one statement or:
ls -l found.file found.file.2 found.file.3
更多关于 ;vs + with find
more on ; vs + with find
此外,您可能希望商品按尺寸排序.这是相对容易实现的.我会在 -s
选项到 ls
,所以 ls -ls
然后将它通过管道传送到 sort -n
按数字排序
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
会变成:
找到 .-size +10k -exec ls -ls {} + |排序-n
或以相反的顺序添加 -r :
or in reverse order add an -r :
找到 .-size +10k -exec ls -ls {} + |排序-nr
最后,你的标题说 find biggest file in directory.您可以通过将代码管道传输到 tail
finally, your title says find biggest file in directory. You can do that by then piping the code to tail
找到 .-size +10k -exec ls -ls {} + |排序-n |尾 -1
会在目录及其子目录中找到最大的文件.
find . -size +10k -exec ls -ls {} + | sort -n | tail -1
would find you the largest file in the directory and its sub directories.
请注意,您还可以使用 -S 按大小对文件进行排序,而无需排序.但是要找到最大的文件,您需要使用 head 所以
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
找到 .-size +10k -exec ls -lS {} + |头-1
使用 -S 而不是 sort
的好处是一,您不必键入 sort -n
,二您也可以使用 -h
人类可读的大小选项.这是我最喜欢使用的一种,但不适用于旧版本的 ls
,例如我们有一个旧的 centOs 4 服务器在工作,它没有 -h
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
这篇关于列出当前目录和所有子目录中特定大小的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!