shell学习之查找当前目录下文件以及文件夹大小-'du'命令和'df'命令
经过前几天的磁盘写满的事件之后,发现自己对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/persistent 532 ./.mozilla/firefox/reo52zta.default/storage 13220 ./.mozilla/firefox/reo52zta.default/adblockplus 38788 ./.mozilla/firefox/reo52zta.default 38812 ./.mozilla/firefox 4 ./.mozilla/extensions 38820 ./.mozilla 2080040 .
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/adblockplus 38M ./.mozilla/firefox/reo52zta.default 38M ./.mozilla/firefox 4.0K ./.mozilla/extensions 38M ./.mozilla 2.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.html 8.0K ./self-learning/intro-linux/sect_07_08.html 12K ./self-learning/intro-linux/sect_06_01.html 12K ./self-learning/intro-linux/sect_05_01.html 12K ./self-learning/intro-linux/sect_01_05.html 800K ./self-learning/intro-linux/intro-linux.html 8.0K ./self-learning/intro-linux/sect_05_05.html 16K ./self-learning/intro-linux/sect_07_01.html 2.7M ./self-learning/intro-linux 9.4M ./self-learning 309M .
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 ./jumei 800 ./bigchance 284 ./self-learning/Bash-Beginners-Guide/images 1692 ./self-learning/Bash-Beginners-Guide 2920 ./self-learning/advanced bash-guide 752 ./self-learning/intro-linux/images 2748 ./self-learning/intro-linux 9620 ./self-learning 315752 . 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 ./jumei 800 ./bigchance 284 ./self-learning/Bash-Beginners-Guide/images 1408 ./self-learning/Bash-Beginners-Guide 2920 ./self-learning/advanced bash-guide 752 ./self-learning/intro-linux/images 1996 ./self-learning/intro-linux 2260 ./self-learning 4 .
注意下,这里的当前文件夹已经没有被计算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%‘元素以百分比的形式显示了使用率(这个是有用的哟).
不太全,但是先凑合着发布吧,哈哈
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。