为什么du命令与xwindows或者ls显示的大小不一致

在man du命令给出的命令详解是这样的,有两个选项,一个是

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

       -S, --separate-dirs
              do not include size of subdirectories

       -s, --summarize

              display only a total for each argument

-a, --all
              write counts for all files, not just directories


即-s命令是显示整个磁盘使用情况,或者为一个目录中的所有文件 显示总的磁盘使用情况。将该标志与-a标志进行对比。

-a显示文件,递归的显示目录下所有的文件。-s只显示本目录下的文件大小和文件夹的总大小。

而默认du显示的disk usage,即占用的blocksize,blocksize可以是1k也可以是4k,不能整除的上取整,就是就算占用半个block也会算作一个大小。

apparent size是实际大小,有的文件中有空洞,空洞不占用磁盘block,但是有大小,即holes,内部碎片fragmentation和indirect blocks不知道是什么情况,找了两张图片放在下面

External and Internal Fragmentation

External fragmentation is the phenomenon in which free storage becomes divided into many small pieces over time. It occurs when an application allocates and deallocates regions of storage of varying sizes, and the allocation algorithm responds by leaving the allocated and deallocated regions interspersed. The result is that although free storage is available, it is effectively unusable because it is divided into pieces that are too small to satisfy the demands of the application.

Internal fragmentation is the space wasted inside of allocated memory blocks because of restriction on the allowed sizes of allocated blocks.




'--apparent-size'
Print apparent sizes, rather than disk usage. The apparent size of a file is the number of bytes reported by wc -c on regular files, or more generally, ls -l --block-size=1 or stat --format=%s. For example, a file containing the word 'zoo' with no newline would, of course, have an apparent size of 3. Such a small file may require anywhere from 0 to 16 KiB or more of disk space, depending on the type and configuration of the file system on which the file resides. However, a sparse file created with this command:

      dd bs=1 seek=2GiB if=/dev/null of=big

has an apparent size of 2 GiB, yet on most modern systems, it actually uses almost no disk space.

这是国外一个论坛的帖子给出的一个解释
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
linux命令大全,中文版本 Linux命令大全(修改版) 进行重新编译的说明 文件传输 bye ftp ftpcount ftpshut ftpwho ncftp tftp uucico uucp uupick uuto 备份压缩 ar bunzip2 bzip2 bzip2recover compress cpio dump gunzip gzexe gzip lha restore tar unarj unzip zip zipinfo 文件管理 diff diffstat file find git gitview ln locate lsattr mattrib mc mcopy mdel mdir mktemp mmove mread mren mshowfat mtools mtoolstest mv od paste patch rcp rhmask rm slocate split tee tmpwatch touch umask whereis which cat chattr chgrp chmod chown cksum cmp cp cut indent 磁盘管理 cd df dirs du edquota eject lndir ls mcd mdeltree mdu mkdir mlabel mmd mmount mrd mzip pwd quota quotacheck quotaoff quotaon repquota rmdir rmt stat tree umount 磁盘维护 badblocks cfdisk dd e2fsck ext2ed fdisk fsck.ext2 fsck fsck.minix fsconf hdparm losetup mbadblocks mformat mkbootdisk mkdosfs mke2fs mkfs.ext2 mkfs mkfs.minix mkfs.msdos mkinitrd mkisofs mkswap mpartition sfdisk swapoff swapon symlinks sync 系统设置 alias apmd aumix bind chkconfig chroot clock crontab declare depmod dircolors dmesg enable eval export fbset grpconv grpunconv hwclock insmod kbdconfig lilo liloconfig lsmod minfo mkkickstart modinfo modprobe mouseconfig ntsysv passwd pwconv pwunconv rdate resize rmmod rpm set setconsole setenv setup sndconfig SVGAText Mode timeconfig ulimit unalias unset 系统管理 adduser chfn chsh date exit finger free fwhois gitps groupdel groupmod halt id kill last lastb login logname logout logrotate newgrp nice procinfo ps pstree reboot renice rlogin rsh rwho screen shutdown sliplogin su sudo suspend swatch tload top uname useradd userconf userdel usermod vlock w who whoami whois 文档编辑 col colrm comm csplit ed egrep ex fgrep fmt fold grep ispell jed joe join look mtype pico rgrep sed sort spell tr uniq wc 网络通讯 dip getty mingetty ppp-off smbd(samba daemon) telnet uulog uustat uux cu dnsconf efax httpd ifconfig mesg minicom nc netconf netconfig netstat ping pppstats samba setserial shapecfg(shaper configuration) smbd(samba daemon) statserial(status ofserial port) talk tcpdump testparm(te

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值