linux快速统计文件夹大小,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, –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 use SIZE-byte blocks

-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

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

names specified in file F

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

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

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

–si like -h, but use powers of 1000 not 1024

-k like –block-size=1K

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

-m like –block-size=1M

-L, –dereference dereference all symbolic links

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

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

-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 file systems

-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

–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 STYLE:

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

FORMAT is interpreted like `date’

–help display this help and exit

–version output 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 2009-12-03 19:25 a

-bash-3.2$ ll -ks a

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

-bash-3.2$ du a

4 a

-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 .

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值