Linux学习笔记3--du命令

上次学习了查看磁盘空间的命令df,昨天再学习了du的命令,现在记录一下学习过程。[@more@]先man du查看du命令的说明:
None.gif du - estimate file space usage
None.gifSYNOPSIS
None.gif du [ OPTION ] dot.gif [ FILE ] dot.gif
None.gifDESCRIPTION
None.gif Summarize disk usage of each FILE , recursively for directories.
None.gif Mandatory arguments to long options are mandatory for short options
None.gif too.
None.gif -a , --all
None.gif write counts for all files , not just directories
None.gif --apparent-size
None.gif print apparent sizes , rather than disk usage ; although the
None.gif apparent size is usually smaller , it may be larger due to holes
None.gif in (鈥榮parse鈥? files , internal fragmentation , indirect blocks ,
None.gif and the like
None.gif -B , --block-size = SIZE use SIZE-byte blocks
None.gif
None.gif -b , --bytes
None.gif equivalent to 鈥?-apparent-size --block-size = 1鈥?
None.gif
None.gif -c , --total
None.gif produce a grand total
None.gif
None.gif -D , --dereference-args
None.gif dereference FILEs that are symbolic links
None.gif
None.gif -H like --si , but also evokes a warning ; will soon change to be
None.gif equivalent to --dereference-args (-D)
None.gif
None.gif -h , --human-readable
None.gif print sizes in human readable format (e.g. , 1K 234M 2G)
None.gif
None.gif --si like -h , but use powers of 1000 not 1024
None.gif
None.gif -k like --block-size = 1K
None.gif
None.gif -l , --count-links
None.gif count sizes many times if hard linked
None.gif
None.gif -L , --dereference
None.gif dereference all symbolic links
None.gif
None.gif -P , --no-dereference
None.gif don鈥檛 follow any symbolic links (this is the default)
None.gif
None.gif - 0 , --null
None.gif end each output line with 0 byte rather than newline
None.gif
None.gif -S , --separate-dirs
None.gif do not include size of subdirectories
None.gif
None.gif -s , --summarize
None.gif display only a total for each argument
None.gif
None.gif -x , --one-file-system
None.gif skip directories on different filesystems
None.gif
None.gif -X FILE , --exclude-from = FILE
None.gif Exclude files that match any pattern in FILE.
None.gif
None.gif --exclude = PATTERN Exclude files that match PATTERN.
None.gif
None.gif --max-depth = N
None.gif print the total for a directory (or file , with --all) only if
None.gif it is N or fewer levels below the command line argument ;
None.gif --max-depth = 0 is the same as --summarize
中文解释

du(disk usage)
功能说明:显示目录或文件的大小。

语  法:
du [-abcDhHklmsSx][-L ][-X ][--block-size][--exclude=][--max-depth=][--help][--version][目录或文件]

补充说明:
du会显示指定的目录或文件所占用的磁盘空间。
-a或-all 显示目录中个别文件的大小。
-b或-bytes 显示目录或文件大小时,以byte为单位。
-c或--total 除了显示个别目录或文件的大小外,同时也显示所有目录或文件的总和。
-D或--dereference-args 显示指定符号连接的源文件大小。
-h或--human-readable 以K,M,G为单位,提高信息的可读性。
-H或--si 与-h参数相同,但是K,M,G是以1000为换算单位。
-k或--kilobytes 以1024 bytes为单位。
-l或--count-links 重复计算硬件连接的文件。
-L或--dereference
显示选项中所指定符号连接的源文件大小。
-m或--megabytes 以1MB为单位。
-s或--summarize 仅显示总计。
-S或--separate-dirs 显示个别目录的大小时,并不含其子目录的大小。
-x或--one-file-xystem 以一开始处理时的文件系统为准,若遇上其它不同的文件系统目录则略过。
-X或--exclude-from= 在指定目录或文件。
--exclude= 略过指定的目录或文件。

操作过程:
None.gif [root @CentOS4 ~ ] # cd ok_008 --转到OK_008目录
None.gif [root @CentOS4 ok_008] # du -sh --统计OK_008目录的文件大小
None.gif 32K .
None.gif[root @CentOS4 ok_008] # du -sH --统计OK_008目录的文件大小,注意这里的H大写,与上一条命令不同。
None.gif du : WARNING : use -- si , not - H; the meaning of the - H option will soon
None.gifchange to be the same as that of -- dereference - args ( - D)
None.gif33k . -- 由于统计单位的不同,所以显示的大小不一样,其实物理都是都是一样。
None.gif[root @CentOS4 ok_008] # du -Sh --统计当前各子目录大小。
None.gif 8 . 0K ./ ok / 008
None.gif 8 . 0K ./ ok
None.gif16K . -- 细心发现这里是16K,而上面使用du - sh显示的是32k,那么其中的16k哪里去了呢。
None.gif
None.gif[root @CentOS4 ok_008] # cd ..
None.gif [root @CentOS4 ~ ] # du -Sh
None.gif 16K ./. gstreamer - 0.8
None.gif 8 . 0K ./. gnome / mime - info
None.gif 8 . 0K ./. gnome / application - info
None.gif 8 . 0K ./. gnome
None.gif52K ./. gconfd
None.gif dot.gif dot.gif
None.gif 8 . 0K ./ ok_008 / ok / 008 -- 这里我们可以发现,原来 / ok_008目录就占了16k的大小。
None.gif 8 . 0K ./ ok_008 / ok -- 由此我们可以区别命令du - Sh 和du - sH的不同之处。
None.gif16K ./ ok_008
None.gif dot.gif ..
None.gif
None.gif -- 为了更方便的验证命令du - Sh 和du - sH的不同,我们可以这样:
None.gif命令du - Sh 和du - sH
None.gif[root @CentOS4 ~ ] # cd ok_008 --除了显示ok_008目录或文件的大小外,同时也显示所有子目录或文件的总和。
None.gif [root @CentOS4 ok_008] # du -ch
None.gif 8 . 0K ./ ok / 008
None.gif16K ./ ok
None.gif32K .
None.gif32K total -- 其实就是如数学中的数的累加一样,统计目录或文件的大小。
None.gif
None.gif[root @CentOS4 ok_008] # du -cb --这是以字节为单元大小表示。
None.gif 4096 ./ ok / 008
None.gif 8192 ./ ok
None.gif 12301 .
None.gif 12301 total
None.gif
None.gif[root @CentOS4 ok_008] # du -ck --这命令与du -ch有点相似点,这里只不过少了单位k。
None.gif 8 ./ ok / 008
None.gif 16 ./ ok
None.gif 32 .
None.gif 32 total
None.gif
None.gif -- 为了更好的验证命令du - ck 和命令du - ch的不同,可以使用测试:
None.gif[root @CentOS4 ~ ] # du -ck
None.gif 16 ./. gstreamer - 0.8
None.gif 8 ./. gnome / mime - info
None.gif 8 ./. gnome / application - info
None.gif dot.gif dot.gif
None.gif 24 ./. thumbnails / fail
None.gif 32 ./. thumbnails
None.gif 8 ./ ok_008 / ok / 008
None.gif 16 ./ ok_008 / ok
None.gif 32 ./ ok_008
None.gif 1116 .
None.gif 1116 total
None.gif
None.gif[root @CentOS4 ~ ] # du -ch
None.gif 16K ./. gstreamer - 0.8
None.gif 8 . 0K ./. gnome / mime - info
None.gif 8 . 0K ./. gnome / application - info
None.gif dot.gif dot.gif
None.gif24K ./. thumbnails / fail
None.gif32K ./. thumbnails
None.gif 8 . 0K ./ ok_008 / ok / 008
None.gif16K ./ ok_008 / ok
None.gif32K ./ ok_008
None.gif 1 . 1M .
None.gif 1 . 1M total
None.gif
None.gif -- 不难看出命令du - ck 是以k单位来统计,而du - ch在统计过程中自动根据实际以K,M,G为单位,达到提高信息的可读性。
None.gif
None.gif
None.gif[root @CentOS4 ok_008] # du -h mytest --查看文件mytest的大小
None.gif 8 . 0K mytest
None.gif[root @CentOS4 ok_008] # du -h /ok --查看ok目录包含ok所有子目录的大小
None.gif 8 . 0K / ok / 008
None.gif16K / ok
None.gif
None.gif怎么样查多的文件大大小呢?
None.gif现在我们使用vi建立一新的文件叫oktest
None.gif[root @CentOS4 ok_008] # vi oktest
None.gif 随便输入一些数据然后保存oktest文件。
None.gif
None.gif[root @CentOS4 ok_008] # ls -l
None.gif total 24
None.gif - rw - r -- r -- 1 root root 13 Sep 13 22 : 36 mytest
None.gifdrwxr - xr -x 3 root root 4096 Sep 13 22 : 51 ok
None.gif - rw - r -- r -- 1 root root 21 Sep 17 20 : 45 oktest
None.gif现在我们要查询文件mytest和oktest的大小。可以这样:
None.gif[root @CentOS4 ok_008] # du -h mytest oktest
None.gif 8 . 0K mytest
None.gif 8 . 0K oktest
None.gif
None.gif我们还可以同时查文件与目录的大小,如:
None.gif[root @CentOS4 ok_008] # du -h mytest /ok
None.gif 8 . 0K mytest -- 文件
None.gif 8 . 0K / ok / 008 -- 目录
None.gif16K / ok -- 目录
None.gif
None.gif
None.gif另外:
None.gif[root @CentOS4 ok_008] # du -h ./
None.gif 8 . 0K ./ ok / 008
None.gif16K ./ ok
None.gif40K ./
None.gif[root @CentOS4 ok_008] # du -h
None.gif 8 . 0K ./ ok / 008
None.gif16K ./ ok
None.gif40K .
None.gif这两个命令等效。习惯du - h 这样写法。
None.gif None.gif
None.gif
None.gif
None.gif

在学习过程中感觉参数 - D或 -- dereference - args显示指定符号连接的源文件大小,
None.gif目前还不知道具体怎么样使用。当然这一参数不影响学习的进程,到以后用到的时候,再回头了解
None.gif也不迟。

好了,今天就学到这里,同事要休息,不能边开音响边学习,也该休息了,闪了,做个好梦! ~-~

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7764484/viewspace-982562/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7764484/viewspace-982562/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值