1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > linux快速统计目录大小 linux下统计文件夹 文件的大小--du

linux快速统计目录大小 linux下统计文件夹 文件的大小--du

时间:2021-01-09 05:28:34

相关推荐

linux快速统计目录大小 linux下统计文件夹 文件的大小--du

Linux下统计文件夹大小

du -sh ./

统计文件夹占用的空间

find ./ -type f xargs ls -l awk ‘BEGIN { size=0;}{size+=$5};END{print size}’

统计所有文件的大小

du == disk usage(磁盘使用量,占用的磁盘空间)

一个文件占用的磁盘空间和一个文件的大小是两码事情。占用空间取决于文件系统的块(block)的大小,linux一般默认是4k(4096) ,因此,一个大小为1个字节的文件,最小也要

占用4k,如果你创建文件系统的时候制定块大小是16K,那么即便一个文件只有1个字节,占用空间也是 16K。

如果一个分区上主要放大文件,那么block可以大一些,有利于减少磁盘碎片,如果主要放小文件,那么block设置小一下,否则太浪费磁盘空间。

通常情况下,ls 显示的文件大小比du显示的磁盘占用空间小,比如文件系统的block是4K,一个13K的文件占用的空间是 13k/4k = 3.25 个block,一个block只能被一个文件占用

,因此实际占用空间就是4个block,就是16K。

如果一个文件有比较大的黑洞,那么会出现文件大小比磁盘空间占用大的情况。

du -s s参数是可以统计硬盘空大小的,

如 du -skh web

-k或–kilobytes以1024 bytes为单位。

-h或–human-readable以K,M,G为单位,提高信息的可读性

-s或–summarize统计目录或文件

-bash-3.2$ du –help

Usage: du [OPTION]… [FILE]…

or:du [OPTION]… –files0-from=F

Summarize disk usage of each FILE, recursively for directories.

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

-a, –allwrite counts for all files, not just directories

–apparent-sizeprint 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=SIZEuse SIZE-byte blocks

-b, –bytesequivalent to `–apparent-size –block-size=1′

-c, –totalproduce a grand total

-D, –dereference-argsdereference only symlinks that are listed on the

command line

–files0-from=Fsummarize disk usage of the NUL-terminated file

names specified in file F

-Hlike –si, but also evokes a warning; will soon

change to be equivalent to –dereference-args (-D)

-h, –human-readableprint sizes in human readable format (e.g., 1K 234M 2G)

–silike -h, but use powers of 1000 not 1024

-klike –block-size=1K

-l, –count-linkscount sizes many times if hard linked

-mlike –block-size=1M

-L, –dereferencedereference all symbolic links

-P, –no-dereferencedon’t follow any symbolic links (this is the default)

-0, –nullend each output line with 0 byte rather than newline

-S, –separate-dirsdo not include size of subdirectories

-s, –summarizedisplay only a total for each argument

-x, –one-file-systemskip directories on different file systems

-X FILE, –exclude-from=FILEExclude files that match any pattern in FILE.

–exclude=PATTERNExclude files that match PATTERN.

–max-depth=Nprint 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

–timeshow time of the last modification of any file in the

directory, or any of its subdirectories

–time=WORDshow time as WORD instead of modification time:

atime, access, use, ctime or status

–time-style=STYLEshow times using style STYLE:

full-iso, long-iso, iso, +FORMAT

FORMAT is interpreted like `date’

–helpdisplay this help and exit

–versionoutput version information and exit

SIZE may be (or may be an integer optionally followed by) one of following:

kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

Report bugs to .

[root@dhcp ~]# tune2fs -l /dev/mapper/VolGroup00-LogVol00 |grep ‘Block size’

Block size:4096

[root@dhcp ~]#

tune2fs – adjust tunable filesystem parameters on ext2/ext3 filesystems

大部分人都搞错了 du 的作用,du 不是显示文件大小,而是显示文件所占用的 block 大小,

你的分区的 block size 是 4k ,也就是说即使文件只有1个字节,也会占用 4KB 。

ls 默认是显示文件大小,-s 就可以达到和 du 一样的效果

测试结果如下

-bash-3.2$ touch a

-bash-3.2$ echo “1″>>a

-bash-3.2$ ll a

-rw-r–r– 1 Zianed member 2 -12-03 19:25 a

-bash-3.2$ ll -ks a

4 -rw-r–r– 1 Zianed member 1 -12-03 19:25 a

-bash-3.2$ du a

4a

-bash-3.2$

-bash-3.2$ find ./ -type f xargs ls -l awk ‘BEGIN { size=0;}{size+=$5};END{print size}’

23107050

-bash-3.2$ du -sh ./

28M.

-bash-3.2$

References

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。