du -a 显示当前目录下所有文件(包括隐藏文件和子目录的文件)
du -s 显示当前目录的总大小
du -h 更加人杏花的显示
du -sh 人性化的显示当前目录的总大小
du -sh /etc/quan
du -h --max-depth=1 /usr/local/ 只显示第一层目录的大小
du -a 显示当前目录下所有文件(包括隐藏文件和子目录的文件)
du -s 显示当前目录的总大小
du -h 更加人杏花的显示
du -sh 人性化的显示当前目录的总大小
du -sh /etc/quan
du -h --max-depth=1 /usr/local/ 只显示第一层目录的大小
转载于:https://www.cnblogs.com/betterquan/p/11486496.html
文章目录
du命令
NAME
du - estimate file space usage
估计文件空间使用情况SYNOPSIS
du [OPTION]… [FILE]…
du [OPTION]… --files0-from=FDESCRIPTION
Summarize disk usage of the set of FILEs, recursively for directories.
递归地总结一组文件的磁盘使用情况。(du命令的对象是目录)Mandatory arguments to long options are mandatory for short options too. 长期权的强制参数对于短期权也是强制参数。
查看指定目录大小
查看指定文件大小
递归查询文件大小
-0, --null end each output line with NUL, not newline 用NUL结束每个输出行,而不是换行 -a, --all write counts for all files, not just directories 递归式写计数的所有文件,不只是目录
可见如果只是du则递归查询当前所有目录的大小
如果指定-a,则也也递归查询所有文件大小--apparent-size print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in ('sparse') files, internal fragmentation, indirect blocks, and the like -B, --block-size=SIZE scale sizes by SIZE before printing them; e.g., '-BM' prints sizes in units of 1,048,576 bytes; see SIZE format below
按指定内存单位查看
-b, --bytes equivalent to '--apparent-size --block-size=1' 内存单位为字节
-k like --block-size=1K
-m like --block-size=1M
打印出total总大小
-c, --total produce a grand total 合计 打印多了一个total
-D, --dereference-args dereference only symlinks that are listed on the command line
指定递归层级
-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 仅当目录(或文件)在命令行参数以下N个或更少的级别时,才打印目录(或文件)的total;——max-depth=0等于——summary
只打印第一级目录
--files0-from=F summarize disk usage of the NUL-terminated file names specified in file F; if F is -, then read names from standard input -H equivalent to --dereference-args (-D)
人性化输出结果(带单位)
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) 以人类可读格式列印尺寸(例如1K 234M 2G)
–inodes
list inode usage information instead of block usage-L, --dereference dereference all symbolic links -l, --count-links count sizes many times if hard linked -P, --no-dereference don't follow any symbolic links (this is the default) -S, --separate-dirs for directories do not include size of subdirectories --si like -h, but use powers of 1000 not 1024
只显示文件总大小(-s 常用)
-s, --summarize display only a total for each argument 只显示每个参数的总数
显示当前目录下各个文件大小(包括目录和文件夹)
-t, --threshold=SIZE
exclude entries smaller than SIZE if positive, or entries greater than SIZE if negative--time show time of the last modification of any file in the directory, or any of its subdirectories --time=WORD show time as WORD instead of modification time: atime, access, use, ctime or status --time-style=STYLE show times using STYLE, which can be: full-iso, long-iso, iso, or +FORMAT; FORMAT is interpreted like in 'date' -X, --exclude-from=FILE exclude files that match any pattern in FILE --exclude=PATTERN exclude files that match PATTERN -x, --one-file-system skip directories on different file systems --help display this help and exit --version output version information and exit Display values are in units of the first available SIZE from --block-size, and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set). 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).
PATTERNS
PATTERN is a shell pattern (not a regular expression). The pattern ? matches any one character, whereas * matches any string (composed of zero, one or multiple characters). For example, *.o will match any files whose names
end in .o. Therefore, the commanddu --exclude='*.o' will skip all files and subdirectories ending in .o (including the file .o itself).
df命令
df - report file system disk space usage 报告文件系统磁盘空间使用情况
SYNOPSIS
df [OPTION]… [FILE]…DESCRIPTION
This manual page documents the GNU version of df. df displays the amount of disk space available on the file system containing each file name argument. If no file name is given, the space available on all currently mounted
file systems is shown. Disk space is shown in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
此手册页记录了df的GNU版本。df显示包含每个文件名参数的文件系统上可用的磁盘空间量。如果没有指定文件名,则当前挂载的所有文件上的可用空间
显示了文件系统。磁盘空间默认显示为1K块,除非设置了环境变量POSIXLY_CORRECT,在这种情况下使用512字节的块。df命令用于显示磁盘分区上的可使用的磁盘空间。默认显示单位为KB。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息 If an argument is the absolute file name of a disk device node containing a mounted file system, df shows the space available on that file system rather than on the file system containing the device node. This version of df cannot show the space available on unmounted file systems, because on most kinds of systems doing so requires very nonportable intimate knowledge of file system structures.
OPTIONS
Show information about the file system on which each FILE resides, or all file systems by default.
显示每个文件所在的文件系统的信息,默认情况下显示所有文件系统的信息。
没有指定挂载点时,显示所有挂载点的文件系统:Mandatory arguments to long options are mandatory for short options too.
查看全部文件系统,单位默认KB
-a, --all include pseudo, duplicate, inaccessible file systems 包括伪、复制、不可访问的文件系统
-B, --block-size=SIZE
scale sizes by SIZE before printing them; e.g., ‘-BM’ prints sizes in units of 1,048,576 bytes; see SIZE format below查看指定文件系统
人性化打印(-h)
-h, --human-readable print sizes in powers of 1024 (e.g., 1023M) 列印尺寸以1024倍(例如1023M)为单位
-H, --si
print sizes in powers of 1000 (e.g., 1.1G)
列印尺寸(例如1.1G)-i, --inodes list inode information instead of block usage -k like --block-size=1K -l, --local limit listing to local file systems --no-sync do not invoke sync before getting usage info (default) --output[=FIELD_LIST] use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted. -P, --portability use the POSIX output format --sync invoke sync before getting usage info --total elide all entries insignificant to available space, and produce a grand total -t, --type=TYPE limit listing to file systems of type TYPE -T, --print-type print file system type -x, --exclude-type=TYPE limit listing to file systems not of type TYPE -v (ignored) --help display this help and exit --version output version information and exit Display values are in units of the first available SIZE from --block-size, and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set). 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). FIELD_LIST is a comma-separated list of columns to be included. Valid field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent', 'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).
Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的.
1.命令格式:
du [选项][文件]
2.命令功能:
显示每个文件和目录的磁盘使用空间。
3.命令参数:
-a或-all 显示目录中个别文件的大小。
-b或-bytes 显示目录或文件大小时,以byte为单位。
-c或--total 除了显示个别目录或文件的大小外,同时也显示所有目录或文件的总和。
-k或--kilobytes 以KB(1024bytes)为单位输出。
-m或--megabytes 以MB为单位输出。
-s或--summarize 仅显示总计,只列出最后加总的值。
-h或--human-readable 以K,M,G为单位,提高信息的可读性。
-x或--one-file-xystem 以一开始处理时的文件系统为准,若遇上其它不同的文件系统目录则略过。
-L<符号链接>或--dereference<符号链接> 显示选项中所指定符号链接的源文件大小。
-S或--separate-dirs 显示个别目录的大小时,并不含其子目录的大小。
-X<文件>或--exclude-from=<文件> 在<文件>指定目录或文件。
--exclude=<目录或文件> 略过指定的目录或文件。
-D或--dereference-args 显示指定符号链接的源文件大小。
-H或--si 与-h参数相同,但是K,M,G是以1000为换算单位。
-l或--count-links 重复计算硬件链接的文件。
4.使用实例:
实例1:显示目录或者文件所占空间
命令:
du
输出:
[root@localhost test]# du
608 ./test6
308 ./test4
4 ./scf/lib
4 ./scf/service/deploy/product
4 ./scf/service/deploy/info
12 ./scf/service/deploy
16 ./scf/service
4 ./scf/doc
4 ./scf/bin
32 ./scf
8 ./test3
1288 .
[root@localhost test]#
说明:
只显示当前目录下面的子目录的目录大小和当前目录的总的大小,最下面的1288为当前目录的总大小
实例2:显示指定文件所占空间
命令:
du log2012.log
输出:
[root@localhost test]# du log2012.log
300 log2012.log
[root@localhost test]#
说明:
实例3:查看指定目录的所占空间
命令:
du scf
输出:
[root@localhost test]# du scf
4 scf/lib
4 scf/service/deploy/product
4 scf/service/deploy/info
12 scf/service/deploy
16 scf/service
4 scf/doc
4 scf/bin
32 scf
[root@localhost test]#
说明:
实例4:显示多个文件所占空间
命令:
du log30.tar.gz log31.tar.gz
输出:
[root@localhost test]# du log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
[root@localhost test]#
说明:
实例5:只显示总和的大小
命令:
du -s
输出:
[root@localhost test]# du -s
1288 .
[root@localhost test]# du -s scf
32 scf
[root@localhost test]# cd ..
[root@localhost soft]# du -s test
1288 test
[root@localhost soft]#
说明:
实例6:方便阅读的格式显示
命令:
du -h test
输出:
[root@localhost soft]# du -h test
608K test/test6
308K test/test4
4.0K test/scf/lib
4.0K test/scf/service/deploy/product
4.0K test/scf/service/deploy/info
12K test/scf/service/deploy
16K test/scf/service
4.0K test/scf/doc
4.0K test/scf/bin
32K test/scf
8.0K test/test3
1.3M test
[root@localhost soft]#
说明:
实例7:文件和目录都显示
命令:
输出:
[root@localhost soft]# du -ah test
4.0K test/log31.tar.gz
4.0K test/test13.tar.gz
0 test/linklog.log
0 test/test6/log2014.log
300K test/test6/linklog.log
0 test/test6/log2015.log
4.0K test/test6/log2013.log
300K test/test6/log2012.log
0 test/test6/log2017.log
0 test/test6/log2016.log
608K test/test6
0 test/log2015.log
0 test/test4/log2014.log
4.0K test/test4/log2013.log
300K test/test4/log2012.log
308K test/test4
4.0K test/scf/lib
4.0K test/scf/service/deploy/product
4.0K test/scf/service/deploy/info
12K test/scf/service/deploy
16K test/scf/service
4.0K test/scf/doc
4.0K test/scf/bin
32K test/scf
4.0K test/log2013.log
300K test/log2012.log
0 test/log2017.log
0 test/log2016.log
4.0K test/log30.tar.gz
4.0K test/log.tar.bz2
4.0K test/log.tar.gz
0 test/test3/log2014.log
4.0K test/test3/log2013.log
8.0K test/test3
4.0K test/scf.tar.gz
1.3M test
[root@localhost soft]#
说明:
实例8:显示几个文件或目录各自占用磁盘空间的大小,还统计它们的总和
命令:
du -c log30.tar.gz log31.tar.gz
输出:
[root@localhost test]# du -c log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
8 总计
[root@localhost test]#
说明:
加上-c选项后,du不仅显示两个目录各自占用磁盘空间的大小,还在最后一行统计它们的总和。
实例9:按照空间大小排序
命令:
du|sort -nr|more
输出:
[root@localhost test]# du|sort -nr|more
1288 .
608 ./test6
308 ./test4
32 ./scf
16 ./scf/service
12 ./scf/service/deploy
8 ./test3
4 ./scf/service/deploy/product
4 ./scf/service/deploy/info
4 ./scf/lib
4 ./scf/doc
4 ./scf/bin
[root@localhost test]#
说明:
实例10:输出当前目录下各个子目录所使用的空间
命令:
du -h --max-depth=1
输出:
[root@localhost test]# du -h --max-depth=1
608K ./test6
308K ./test4
32K ./scf
8.0K ./test3
1.3M .
[root@localhost test]#
df -h
查看系统中文件的使用情况Size 分割区总容量
Used 已使用的大小
Avail 剩下的大小
Use% 使用的百分比
Mounted on 路径地址FreeBSD下,当硬盘容量已满时,您可能会看到已使用的百分比超过 100%,因为 FreeBSD 会留一些空间给 root,让 root 在档案系统满时,还是可以写东西到该档案系统中,以进行管理。
du -sh *
查看当前目录下各个文件及目录占用空间大小大小 文件名
4.0K test.txt
du -h --max-depth=1 /root/*
查看目录下的说有文件大小du -h --max-depth=1 /root
列出root目录下面所有的一级目录文件大小;rm
删除命令rm -f *
切换到要删除的目录,删除目录下的所有文件rm -rf log/*
删除logs文件夹下的所有文件,而不删除文件夹本身df -h
和du -sh
显示的磁盘大小不一致原因及解决办法
df -hT
显示132G空间全部占用,du -sh
显示只占用30G
使用
rm
命令删除文件时,只有当该文件不存在任何link才会被删除
当有进程访问这个文件时,这个文件的实际占用空间就不会释放
du
是根据文件名进行的空间统计,使用rm时该文件对系统来说已经不可见,所以不会统计这个文件。
df
则是磁盘实际占用的数量