查看文件大小du命令,查找文件或者目录find命令,查看磁盘剩余df命令
du命令使用介绍
Linux查看文件夹大小及统计总数等
from JavaEye
统计总数大小
du -sh xmldb/
du -sm * | sort -n //统计当前目录大小 并安大小 排序
du -sk * | sort -n
du -sk * | grep guojf //看一个文件的大小
du -m | cut -d "/" -f 2 //看第二个/ 字符前的文字
查看此文件夹有多少文件 * 有多少文件
du xmldb/
du xmldb* |wc -l
40752
解释:
wc [-lmw]
参数说明:
-l :多少行
-m:多少字符
-w:多少字
du 命令
用途
概述磁盘使用。
语法
du [ -a | -s ] [ -k ] [ -m ] [ -g ][ -l ] [ -r ] [ -x ] [ -H | -L ][ File … ]
描述
du命令显示用于文件的块的数量。如果指定的File参数实际上是一个目录,就要报告该目录内的所有文件。如果没有提供 File参数,du命令使用当前目录内的文件。
如果File参数是一个目录,那么报告的块的数量就是分配到目录中文件以及分配到目录自身的块之和。
指定-a标志,报告个体文件中块数量。不管是否使用了-a标志,由File参数指定的个体文件总是要列出。
指定-s标志,报告用于所有指定文件和目录中所有文件的全部块。
块计数包括每个文件的间接块。块计数是通过 512 字节单位计算的,它与系统使用的群集大小无关。指定-k标志,通过 1024 字节单位计算块数。
注:
具有多个链接的文件只为一个条目计数和书写。
由于块计数只基于文件大小,所以在报告的块数中,未分配的块是没有包含进去的。
如果du得不到文件属性,或者无法读取目录,它就报告一个错误,并且会影响命令的退出状态。
标志
-a 为每个指定文件显示磁盘使用情况,或者为目录中每个文件显示各自磁盘使用情况。将该标志与-s标志进行对比。
-g 用 GB 单位计算块数,而不是用缺省的 512 字节单位。对磁盘使用情况的输出值要用浮点数,这是因为如果用字节为单位的话,值会非常大。
-H 如果在命令行指定了符号链接,du 命令将统计链接引用的文件或文件层次结构的大小。
-k 用 1024 字节单位计算块数,而不是用缺省的 512 字节单位。
-l 在文件链接和多链接之间均匀地分配块。根据缺省值,有两个或者更多链接的文件只计数一次。
-L 如果在命令行指定了符号链接或者在文件层次结构的遍历中多次遇到符号链接,则 du 命令应统计链接引用的文件或文件层次结构的大小。
-m 用 MB 单位计算块数,而不是用缺省的 512 字节单位。对磁盘使用情况的输出值要用浮点数,这是因为如果用字节为单位的话,值会非常大。
-r 报告不可访问的文件或者目录名。此为缺省设置。
-s 为所有指定文件显示整个磁盘使用情况,或者为一个目录中的所有文件显示总的磁盘使用情况。将该标志与-a标志进行对比。
-x 在评估文件大小时,只评估那些与File参数指定的文件或者目录驻留在相同设备上的文件。例如,您可以指定一个在多个设备上包含文件的目录。这种情况下,-x标志就为与目录驻留在相同设备的所有文件显示块的大小。
如果指定了全部-k、-m和-g标志,或者是其中任意两个,最后指定的那个起作用。用标志-m和-g输出磁盘使用情况就会近似成最接近的第二位十进制数。
退出状态
此命令返回下列出口值:
0 成功结束。>0 发生错误。
示例
要概述一个目录树及其每个子树的磁盘使用情况,请输入:
du /home/fran这在/home/fran目录及其每个子目录中显示了磁盘块数。
要通过 1024 字节块概述一个目录树及其每个子树的磁盘使用情况,请输入:
du -k /home/fran这在/home/fran目录及其每个子目录中显示了 1024 字节磁盘块数。
要通过 MB 磁盘块概述一个目录树及其每个子树的磁盘使用情况,请输入:
du -m /home/fran这在/home/fran目录及其每个子目录中显示了 MB 磁盘块数(近似到最接近的第二位十进制数)。
要通过 GB 块概述一个目录树及其每个子树的磁盘使用情况,请输入:
du -g /home/fran这在/home/fran目录及其每个子目录中显示了 GB 磁盘块数(近似到最接近的第二位十进制数)。
要显示每个文件磁盘使用情况,请输入:
du -a /home/fran这显示了包含在每个文件以及目录/home/fran的子目录中的磁盘块数。在目录旁的数字就是该目录树的磁盘使用情况。在常规文件旁的数字就是该文件单独的磁盘使用情况。
要只显示一个目录树的全部磁盘使用情况,请输入:
du -s /home/fran-s标志控制du命令,只显示/home/fran目录和其中包含的文件的磁盘使用情况的总和。通过缺省值,如果du命令无法读取一个文件或者目录,就显示一条错误消息。
除了在 /home/fran 的遍历中找到的常规文件,还要显示所有符号链接引用的文件或文件层次结构的磁盘使用,请输入:
du -L /home/fran要报告符号链接 mylink 引用的文件或文件层次结构的磁盘使用,请输入:
du -H mylink
文件
/usr/bin/du 包含命令du。
linux中du命令参数的用法,并用示例进一步说明其使用方法。
du:Disk Usage的缩写,命令功能为显示目录(或文件)所占磁盘空间的大小。
语 法:du [-abcDhHklmsSx0] [-L][-X File][–block-size=SIZE][–exclude=PATTERN] [–max-depth=N][–help][–version][FILE-OR-PATH]
参数说明:
-0 每个结果显示后不换行
-a或–all 为每个指定文件显示磁盘使用情况,或者为目录中每个文件显示各自磁盘使用情况。
–apparent-size 显示目录或文件自身的大小
-B或–block-size=SIZE 以SIZE为计量单位显示目录或文件大小;SIZE可以为任意整数,也可以为KB 1000, K 1024, MB 10001000, M 10241024, 类似地对于G, T, P, E, Z, Y。
-b或–bytes 以byte为单位显示目录或文件大小,等价于’–apparent-size --block-size=1’
-c或–total 除了显示目录或文件的大小外,同时显示所有目录或文件的总和。
-D或–dereference-args 显示指定符号连接的源文件大小。
–files0-from=F 显示文件F 中以NUL 结尾的文件名对应占用的磁盘空间;如果F 的值是"-",则从标准输入读入文件名
-h或–human-readable 以K,M,G为单位,提高信息的可读性。
-H或–si 与-h参数相同,但是K,M,G是以1000为换算单位,而不是以1024为换算单位。
-k或–kilobytes 以1024 bytes为单位,等价于–block-size=1K。
-l或–count-links 重复计算硬连接的文件。
-L或–dereference 统计符号连接源文件大小。
-P或–no-dereference 不同符号链接源文件的大小,默认。
-m或–megabytes 以1MB为单位,等价于–block-size=1M。
-s或–summarize 仅显示总计,即当前目录的大小。
-S或–separate-dirs 显示每个目录的大小时,并不含其子目录的大小。
-x或–one-file-system 忽略位于其他文件系统上的目录。
-X FILE或–exclude-from=FILE 忽略在FILE文件中指定目录或文件。
–exclude=PATTERN 忽略符合PATTERN规则的目录或文件。
- -max-depth=N 只显示N层内的目录大小,–max-depth=0等同于–summarize。
–time 显示目录或子目录中文件的最后修改时间。
–time=WORD 以WORD指定的时间代替修改时间;WORD取值atime, access, use, ctime, status之一。
–time-style=STYLE 以STYLE指定的格式显示时间;STYLE取值full-iso, long-iso, iso, +FORMAT之一,其中FORMAT格式同date命令。
–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、只显示一个目录树的全部磁盘使用情况
[root@cos7 ~ ]#man du
DU(1) User Commands DU(1)
NAME
du - estimate file space usage
SYNOPSIS
du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
DESCRIPTION
Summarize disk usage of each FILE, recursively for directories.
Mandatory arguments to long options are mandatory for short options too.
-0, --null
end each output line with 0 byte rather than newline
-a, --all
write counts for all files, not just directories
--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'
-c, --total
produce a grand 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
--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)
--inodes
list inode usage information instead of block usage
-k like --block-size=1K
Manual page du(1) line 1 (press h for help or q to quit)...skipping...
DU(1) User Commands DU(1)
NAME
du - estimate file space usage
SYNOPSIS
du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
DESCRIPTION
Summarize disk usage of each FILE, recursively for directories.
Mandatory arguments to long options are mandatory for short options too.
-0, --null
end each output line with 0 byte rather than newline
-a, --all
write counts for all files, not just directories
--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'
-c, --total
produce a grand 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
--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)
--inodes
list inode usage information instead of block usage
-k like --block-size=1K
-L, --dereference
dereference all symbolic links
-l, --count-links
count sizes many times if hard linked
-m like --block-size=1M
-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, --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).
SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report du translation bugs to <http://translationproject.org/team/>
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 multi‐
ple characters). For example, *.o will match any files whose names end in .o. Therefore, the command
du --exclude='*.o'
will skip all files and subdirectories ending in .o (including the file .o itself).
AUTHOR
Written by Torbjorn Granlund, David MacKenzie, Paul Eggert, and Jim Meyering.
COPYRIGHT
Copyright © 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
The full documentation for du is maintained as a Texinfo manual. If the info and du programs are properly installed at your site, the command
info coreutils 'du invocation'
should give you access to the complete manual.
GNU coreutils 8.22 April 2018 DU(1)
Manual page du(1) line 50/131 (END) (press h for help or q to quit)
本文主要介绍了Linux系统中du命令的使用。du命令用于显示目录或文件所占磁盘空间大小,文中详细说明了其语法、参数含义,如 -a、-s、-k 等,并通过多个示例,如查看不同目录的磁盘使用情况、以不同单位显示等,进一步展示了du命令的具体用法。
868

被折叠的 条评论
为什么被折叠?



