admin管理员组

文章数量:1660164

Linux du 命令 - estimate file space usage [计算文件空间使用情况]

  • References

Summarize disk usage of the set of FILEs, recursively for directories.
汇总每个文件占用磁盘空间情况,递归汇总目录的大小。

Mandatory arguments to long options are mandatory for short options too.
long options 的强制性参数对于 short options 也是必需的。

-d, --max-depth=N

print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument; --max-depth=0 is the same as --summarize.

-h, --human-readable

print sizes in human readable format (e.g., 1K 234M 2G)
提高信息的可读性。

-l, --count-links

count sizes many times if hard linked

(base) yongqiang@yongqiang:~$ du -sh ./miniconda3/
2.6G    ./miniconda3/
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ du -sh ./yongqiang.txt
0       ./yongqiang.txt
(base) yongqiang@yongqiang:~$

-s, --summarize

display only a total for each argument
仅显示总计,当前文件夹的大小。

(base) yongqiang@yongqiang:~$ du -s
5467433 .
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ du -sh
5.3G    .
(base) yongqiang@yongqiang:~$

du -sh * - 查看当前目录下的文件和文件夹大小

(base) yongqiang@yongqiang:~$ ls
cheng  foreverstrong.txt  miniconda3  pycharm_work  pytorch_work  software  t2t_data  tensor2tensor  tensorflow_work  yongqiang  yongqiang.txt
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ du -sh *
0       cheng
0       foreverstrong.txt
2.6G    miniconda3
16K     pycharm_work
622K    pytorch_work
892M    software
733M    t2t_data
18M     tensor2tensor
0       tensorflow_work
0       yongqiang
0       yongqiang.txt
(base) yongqiang@yongqiang:~$

ls | wc -l - 查看当前目录下的文件和文件夹数量

(base) yongqiang@yongqiang:~$ ls | wc -l
11
(base) yongqiang@yongqiang:~$

du -s * | sort -n - 当前目录下的文件和文件夹大小排序,由小到大

(base) yongqiang@yongqiang:~$ du -sh * | sort -n
0       cheng
0       foreverstrong.txt
0       tensorflow_work
0       yongqiang
0       yongqiang.txt
2.6G    miniconda3
16K     pycharm_work
18M     tensor2tensor
622K    pytorch_work
733M    t2t_data
892M    software
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ du -s * | sort -n
0       cheng
0       foreverstrong.txt
0       tensorflow_work
0       yongqiang
0       yongqiang.txt
16      pycharm_work
622     pytorch_work
17592   tensor2tensor
749728  t2t_data
912842  software
2719084 miniconda3
(base) yongqiang@yongqiang:~$

du -s * | sort -nr - 当前目录下的文件和文件夹大小排序,由大到小

(base) yongqiang@yongqiang:~$ du -s * | sort -nr
2719084 miniconda3
912842  software
749728  t2t_data
17592   tensor2tensor
622     pytorch_work
16      pycharm_work
0       yongqiang.txt
0       yongqiang
0       tensorflow_work
0       foreverstrong.txt
0       cheng
(base) yongqiang@yongqiang:~$

du -s * | sort -nr | head - 当前目录下的文件和文件夹大小排序,由大到小,列出排在前面的 10 个

(base) yongqiang@yongqiang:~$ du -s * | sort -nr | head
2719084 miniconda3
912842  software
749728  t2t_data
17592   tensor2tensor
622     pytorch_work
16      pycharm_work
0       yongqiang.txt
0       yongqiang
0       tensorflow_work
0       foreverstrong.txt
(base) yongqiang@yongqiang:~$

du -s * | sort -nr | tail - 当前目录下的文件和文件夹大小排序,由大到小,列出排在后面的 10 个

(base) yongqiang@yongqiang:~$ du -s * | sort -nr | tail
912842  software
749728  t2t_data
17592   tensor2tensor
622     pytorch_work
16      pycharm_work
0       yongqiang.txt
0       yongqiang
0       tensorflow_work
0       foreverstrong.txt
0       cheng
(base) yongqiang@yongqiang:~$

The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,… (powers of 1000).

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn/

本文标签: 命令情况文件空间Linux