在Linux上按大小列出文件和目录

This page will show us how to create a list of files and folders ordered by size using standard Linux commands.

该页面将向我们展示如何使用标准Linux命令创建按大小排序的文件和文件夹列表。

命令 (Command)

To get a list with the size of each item in a folder, you’ll want to use the du command like this:

要获得一个文件夹中每个项目的大小的列表,您将需要使用du命令,如下所示:

du -sm *

The -m argument will return the listing in megabytes (note that you can use -h for human readable, but it won’t sort correctly)

-m参数将返回以兆字节为单位的列表(请注意,您可以使用-h使其易于阅读,但无法正确排序)

Now we will want to run this through the sort command, sorting in reverse order -r and numeric -n:

现在,我们将要通过sort命令运行此命令,以相反的顺序-r和数字-n进行排序:

du -sm * | sort -nr

The only problem here is that we’ll get way too much output if there are a lot of files and folders, so we can either pipe it through the more command:

唯一的问题是,如果文件和文件夹很多,我们将获得过多的输出,因此我们可以通过more命令将其传递给管道:

du -sm * | sort -nr | more

Or we can just return the top 15 largest items:

或者,我们可以返回前15个最大的项目:

du -sm * | sort -nr | head -15

This will return a listing something like this:

这将返回如下列表:

2907    Files1
993     Files2
38      Somefile.txt

翻译自: https://www.howtogeek.com/168135/list-files-and-directories-by-size-on-linux/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值