如何在目录及其子目录中找到最大的文件? [英] How to find the largest file in a directory and its subdirectories?

查看:132
本文介绍了如何在目录及其子目录中找到最大的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们刚刚开始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.

如果我的行话"不正确,请原谅我,我仍然会习惯它!

And pardon me if my 'lingo' isn't correct, I'm still getting used to it!

推荐答案

链接-

如果要查找和打印前10个最大的文件名(不是 目录)及其特定子目录中

If you want to find and print the top 10 largest files names (not directories) in a particular directory and its sub directories

$ find . -printf '%s %p\n'|sort -nr|head

要将搜索范围限制为当前目录,请使用"-maxdepth 1" 找到.

To restrict the search to the present directory use "-maxdepth 1" with find.

$ find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head

并打印出前10个最大的文件和目录":

And to print the top 10 largest "files and directories":

$ du -a . | sort -nr | head

**使用"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)

这篇关于如何在目录及其子目录中找到最大的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆