在Linux上按大小列出文件和目录
This page will show us how to create a list of files and folders ordered by size using standard Linux commands.
該頁面將向我們展示如何使用標準Linux命令創(chuàng)建按大小排序的文件和文件夾列表。
命令 (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參數(shù)將返回以兆字節(jié)為單位的列表(請注意,您可以使用-h使其易于閱讀,但無法正確排序)
Now we will want to run this through the sort command, sorting in reverse order -r and numeric -n:
現(xiàn)在,我們將要通過sort命令運行此命令,以相反的順序-r和數(shù)字-n進行排序:
du -sm * | sort -nrThe 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 | moreOr we can just return the top 15 largest items:
或者,我們可以返回前15個最大的項目:
du -sm * | sort -nr | head -15This 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/
總結(jié)
以上是生活随笔為你收集整理的在Linux上按大小列出文件和目录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: chromebook刷机_如何在Chro
- 下一篇: 如何在Linux上使用端口敲门(以及为什