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/