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

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

问题描述

我们刚刚开始在UNIX类,并正在学习各种猛砸命令。我们的工作包括对具有若干在它之下的文件夹,以及一个目录执行各种命令。

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

不过,我想知道从哪里里去,以便找到在整个目录中的最大文件。我看过一个关于命令出头,但我们还没有了解到,所以在对事物的剧目,我们已经了解到我认为,我们需要以某种方式将其连接到在 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

$找到。 -printf'%S%P \\ N'|排序-nr |头

要限制搜索到present目录,使用-maxdepth 1
  找到的。

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

$找到。 -maxdepth 1 -printf'%S%P \\ N'|排序-nr |头

和打印前10大文件和目录

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

$杜-a。 |排序-nr |头

**使用头-n X代替唯一的头的上述打印顶的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天全站免登陆