標籤:
經過前幾天的磁碟寫滿的事件之後,發現自己對du這個命令完全不知道,所以下決心要學習一番。
我就當一盤搬運工吧,外網找到一個教程
‘du‘就是尋找檔案夾的大小
du
Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes.
譯:就是說吧當前的檔案夾下的目錄的size列印出來,在最後一行列印的是整個檔案夾包括其子檔案夾的總size,size包含目當前錄下的所有檔案、子目錄。需要注意的是,預設情況下單位是kb
du /home/sunyuw
The above command would give you the directory size of the directory /home/sunyuw
這個就不翻了,部分輸出如下:
528 ./.mozilla/firefox/reo52zta.default/storage/persistent532 ./.mozilla/firefox/reo52zta.default/storage13220 ./.mozilla/firefox/reo52zta.default/adblockplus38788 ./.mozilla/firefox/reo52zta.default38812 ./.mozilla/firefox4 ./.mozilla/extensions38820 ./.mozilla2080040 .
du -h
This command gives you a better output than the default one. The option ‘-h‘ stands for human readable format. So the sizes of the files / directories are this time suffixed with a ‘k‘ if its kilobytes and ‘M‘ if its Megabytes and ‘G‘ if its Gigabytes.
譯:這個命令輸出的要比預設的好的多(更加貼近人類的閱讀方式).選項‘-h‘代表‘人類可讀的格式’.所以這個時候檔案和檔案夾的size被以合適的單位作為尾碼,比如K、M、G分別對應kb、mb、gb
部分輸出是這樣的:
13M ./.mozilla/firefox/reo52zta.default/adblockplus38M ./.mozilla/firefox/reo52zta.default38M ./.mozilla/firefox4.0K ./.mozilla/extensions38M ./.mozilla2.0G .
du -ah
This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that ‘du‘ always counts all files and directories while giving the final size in the last line. But the ‘-a‘ displays the filenames along with the directory names in the output. ‘-h‘ is once again human readable format.
譯:(樓主親測)這個命令會將整個當前檔案夾下的檔案全部都遍曆輸出出來.需要注意的是du總會將所有檔案總和size輸出在最後一行,但因為-a參數的原因,檔案名稱將會單獨於檔案輸出,但是-h仍然會輸出人類可讀的格式,部分輸出如下:
32K ./self-learning/intro-linux/sect_03_01.html8.0K ./self-learning/intro-linux/sect_07_08.html12K ./self-learning/intro-linux/sect_06_01.html12K ./self-learning/intro-linux/sect_05_01.html12K ./self-learning/intro-linux/sect_01_05.html800K ./self-learning/intro-linux/intro-linux.html8.0K ./self-learning/intro-linux/sect_05_05.html16K ./self-learning/intro-linux/sect_07_01.html2.7M ./self-learning/intro-linux9.4M ./self-learning309M .
du -c
This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be
譯:這個將會再最後添加一個total這麼一行,所以如果檔案夾佔據了30mb空間那麼在最後兩行都會顯示
輸出如下:
305328 ./jumei800 ./bigchance284 ./self-learning/Bash-Beginners-Guide/images1692 ./self-learning/Bash-Beginners-Guide2920 ./self-learning/advanced bash-guide752 ./self-learning/intro-linux/images2748 ./self-learning/intro-linux9620 ./self-learning315752 .315752 total
du -ch | grep total
這個,呵呵不翻譯了,不解釋了,看不懂面壁去
du -s
This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.
譯:這個會輸出一個概要,是擷取當前檔案夾size最簡單的方法
輸出:
315752 .
du -S
This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.
譯:(樓主親測)這個會每個羅列檔案以及檔案夾的大小,這個是查詢本檔案夾下直接的files的總size的方法
輸出如下:
305328 ./jumei800 ./bigchance284 ./self-learning/Bash-Beginners-Guide/images1408 ./self-learning/Bash-Beginners-Guide2920 ./self-learning/advanced bash-guide752 ./self-learning/intro-linux/images1996 ./self-learning/intro-linux2260 ./self-learning4 .
注意下,這裡的當前檔案夾已經沒有被計算sub file或者sub dir的size了。
du --exculde=mp3
The above command would display the size of the current directory along with all its subdirectories, but it would exclude all the files having the given pattern present in their filenames. Thus in the above case if there happens to be any mp3 files within the current directory or any of its subdirectories, their size would not be included while calculating the total directory size.
譯:這條命令將會統計目前的目錄下以及子目錄的size,但是將會忽略能夠匹配運算式的檔案。(後面不翻譯了,就是說mp3在這個例子裡面不成)
樓主沒有mp3放在linux裡面的,所以輸出就部署出了吧,格式參照預設的du命令
接下來是df命令了,查看磁碟使用率
df
Typing the above, outputs a table consisting of 6 columns. All the columns are very easy to understand. Remember that the ‘Size‘, ‘Used‘ and ‘Avail‘ columns use kilobytes as the unit. The ‘Use%‘ column shows the usage as a percentage which is also very useful.
譯:輸出的表格具有6個元素,每個元素都很容易理解,請記住‘Size‘,‘Used‘,‘Avail‘元素以kb為單位,‘Use%‘元素以百分比的形式顯示了使用率(這個是有用的喲).
不太全,但是先湊合著發布吧,哈哈
shell學習之尋找目前的目錄下檔案以及檔案夾大小-'du'命令和'df'命令