Linux中查看各文件夹大小命令 estimate file space usage

du -h –max-depth=1

NAME

du – estimate file space usage

SYNOPSIS

du [OPTION]… [FILE]…

EXAMPLES

DESCRIPTION

Summarize disk usage of each FILE, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.

-a, –all
write counts for all files, not just directories
-B, –block-size=SIZE use SIZE-byte blocks
-b, –bytes
print size in bytes
-c, –total
produce a grand total
-D, –dereference-args
dereference FILEs that are symbolic links
-h, –human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-H, –si
likewise, but use powers of 1000 not 1024
-k
like –block-size=1K
-l, –count-links
count sizes many times if hard linked
-L, –dereference
dereference all symbolic links
-S, –separate-dirs
do not include size of subdirectories
-s, –summarize
display only a total for each argument
-x, –one-file-system
skip directories on different filesystems
-X FILE, –exclude-from=FILE
Exclude files that match any pattern in FILE.
–exclude=PATTERN Exclude files that match PATTERN.
–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
–help
display this help and exit
–version
output version information and exit
du [-abcDhHklmsSx] [-L <符号连接>][-X <文件>][–block-size][–exclude=<目录或文件>] [–max-depth=<目录层数>][–help][–version][目录或文件]
常用参数:
-a或-all 为每个指定文件显示磁盘使用情况,或者为目录中每个文件显示各自磁盘使用情况。
-b或-bytes 显示目录或文件大小时,以byte为单位。
-c或–total 除了显示目录或文件的大小外,同时也显示所有目录或文件的总和。
-D或–dereference-args 显示指定符号连接的源文件大小。
-h或–human-readable 以K,M,G为单位,提高信息的可读性。
-H或–si 与-h参数相同,但是K,M,G是以1000为换算单位,而不是以1024为换算单位。
-k或–kilobytes 以1024 bytes为单位。
-l或–count-links 重复计算硬件连接的文件。
-L<符号连接>或–dereference<符号连接> 显示选项中所指定符号连接的源文件大小。
-m或–megabytes 以1MB为单位。
-s或–summarize 仅显示总计,即当前目录的大小。
-S或–separate-dirs 显示每个目录的大小时,并不含其子目录的大小。
-x或–one-file-xystem 以一开始处理时的文件系统为准,若遇上其它不同的文件系统目录则略过。
-X<文件>或–exclude-from=<文件> 在<文件>指定目录或文件。
–exclude=<目录或文件> 略过指定的目录或文件。
–max-depth=<目录层数> 超过指定层数的目录后,予以忽略。
–help 显示帮助。
–version 显示版本信息。
1> 要显示一个目录树及其每个子树的磁盘使用情况
du /home/linux
这在/home/linux目录及其每个子目录中显示了磁盘块数。
2> 要通过以1024字节为单位显示一个目录树及其每个子树的磁盘使用情况
du -k /home/linux
这在/home/linux目录及其每个子目录中显示了 1024 字节磁盘块数。
3> 以MB为单位显示一个目录树及其每个子树的磁盘使用情况
du -m /home/linux
这在/home/linux目录及其每个子目录中显示了 MB 磁盘块数。
4> 以GB为单位显示一个目录树及其每个子树的磁盘使用情况
du -g /home/linux
这在/home/linux目录及其每个子目录中显示了 GB 磁盘块数。
5>查看当前目录下所有目录以及子目录的大小:
du -h .
“.”代表当前目录下。也可以换成一个明确的路径
-h表示用K、M、G的人性化形式显示
6>查看当前目录下user目录的大小,并不想看其他目录以及其子目录:
du -sh user
-s表示总结的意思,即只列出一个总结的值
du -h –max-depth=0 user
–max-depth=n表示只深入到第n层目录,此处设置为0,即表示不深入到子目录。
7>列出user目录及其子目录下所有目录和文件的大小:
du -ah user
-a表示包括目录和文件
8>列出当前目录中的目录名不包括xyz字符串的目录的大小:
du -h –exclude=’*xyz*’
9>想在一个屏幕下列出更多的关于user目录及子目录大小的信息:
du -0h user
-0(杠零)表示每列出一个目录的信息,不换行,而是直接输出下一个目录的信息。
10>只显示一个目录树的全部磁盘使用情况
du -s /home/linux
11>查看各文件夹大小:du -h –max-depth=1

3 Responses so far.

  1. quest bars says:
    Wonderful blog! I found it while searching on Yahoo News.
    Do you have any tips on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to
    get there! Cheers
  2. quest bars says:
    of course like your website however you have to check the
    spelling on quite a few of your posts. Many of
    them are rife with spelling issues and I find it very bothersome to inform the truth on the other
    hand I will surely come again again.
  3. Hello! I’m at work browsing your blog from my new apple iphone! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the superb work!

Leave a Reply to quest bars Cancel reply