Bash - 如何找到目录及其子目录中的最大文件? [英] Bash - How to find the largest file in a directory and its subdirectories?
问题描述
我们刚刚开始一个UNIX类,正在学习各种Bash命令。我们的任务包括在目录下执行各种命令,目录下也有多个文件夹。
We're just starting a UNIX class and are learning a variety of Bash commands. Our assignment involves performing various commands on a directory that has a number of folders under it as well.
我知道如何使用以下方式从根文件夹中列出和计数所有常规文件:
I know how to list and count all the regular files from the root folder using:
find . -type l | wc -l
但是我想知道从那里去哪里,以找到最大的文件在整个目录。我已经看到关于 du
命令的一些事情,但是我们还没有学到,所以在我们学到的东西的曲目中,我假设我们需要以某种方式连接到 ls -t
命令。
But I'd like to know where to go from there in order to find the largest file in the whole directory. I've seen somethings regarding a du
command, but we haven't learned that, so in the repertoire of things we've learned I assume we need to somehow connect it to the ls -t
command.
如果我的lingo不正确,请原谅我,我还是习惯了!
And pardon me if my 'lingo' isn't correct, I'm still getting used to it!
推荐答案
从此链接 -
如果您想要查找和打印特定目录及其子目录中的前十大最大文件名(而不是
目录)
If you want to find and print the top 10 largest files names (not directories) in a particular directory and its sub directories
$找 。 -printf'%s%p\\\
'| sort -nr | head
要将搜索限制在当前目录中,请使用 - maxdepth 1with
find。
To restrict the search to the present directory use "-maxdepth 1" with find.
$ find。 -maxdepth 1 -printf'%s%p\\\
'| sort -nr | head
并打印前十大最大的文件和目录:
And to print the top 10 largest "files and directories":
$ du -a。 |排序-nr |头部
**使用head -n X代替上面唯一的head打印顶部的X最大文件上述例子)
** Use "head -n X" instead of the only "head" above to print the top X largest files (in all the above examples)
这篇关于Bash - 如何找到目录及其子目录中的最大文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!