我怎样才能确定什么是占用这么多的空间?

我正在使用df -h打印出人类可读的磁盘使用情况。 我想弄清楚什么是占用这么多的空间。 例如,有没有办法pipe这个命令,以便打印出大于1GB大小的文件? 其他想法?

谢谢

我用这个很多。

 du -kscx * 

可能需要一段时间才能运行,但会告诉您磁盘空间的使用情况。

您可能想要尝试在http://dev.yorhel.nl/ncdufind的ncdu实用程序

它会快速地总结一个文件系统或目录树的内容并打印结果,按大小sorting。 这是一个非常好的交互方式,深入了解消耗的驱动器空间。

另外,它可以比一些du组合更快。

典型的输出如下所示:

 ncdu 1.7 ~ Use the arrow keys to navigate, press ? for help --- /data ---------------------------------------------------------------------------------------------------------- 163.3GiB [##########] /docimages 84.4GiB [##### ] /data 82.0GiB [##### ] /sldata 56.2GiB [### ] /prt 40.1GiB [## ] /slisam 30.8GiB [# ] /isam 18.3GiB [# ] /mail 10.2GiB [ ] /export 3.9GiB [ ] /edi 1.7GiB [ ] /io 1.2GiB [ ] /dmt 896.7MiB [ ] /src 821.5MiB [ ] /upload 691.1MiB [ ] /client 686.8MiB [ ] /cocoon 542.5MiB [ ] /hist 358.1MiB [ ] /savsrc 228.9MiB [ ] /help 108.1MiB [ ] /savbin 101.2MiB [ ] /dm 40.7MiB [ ] /download 

您可以使用find命令。 例:

 find /home/ -size +1073700000c -print 

我自己用

 du -c --max-depth = 4 / dir | 分类

这返回一个目录及其子目录使用的空间量达4深, sort -n将把最后的最大。

sort新版本可以处理“人类可读的”大小,所以可以使用更多的可读性

 du -hc --max-depth=4 /dir | sort -h 

随着人类可读的大小:

 du -hscx * 

recursionsearch一个目录中的大文件

我已经决定要占用这么多空间了吗? 很多时间,我写了这个小脚本,以便在特定设备上search大型职业(没有参数,这将浏览当前目录,search> 256Mb目录条目):

 #!/bin/bash humansize() { local _c=$1 _i=0 _a=(b KMGTP) while [ ${#_c} -gt 3 ] ;do ((_i++)) _c=$((_c>>10)) done _c=$(( ( $1*1000 ) >> ( 10*_i ) )) printf ${2+-v} $2 "%.2f%s" ${_c:0:${#_c}-3}.${_c:${#_c}-3} ${_a[_i]} } export device=$(stat -c %d "${1:-.}") export minsize=${2:-$((256*1024**2))} rdu() { local _dir="$1" _spc="$2" _crt _siz _str while read _crt;do if [ $(stat -c %d "$_crt") -eq $device ];then _siz=($(du -xbs "$_crt")) if [ $_siz -gt $minsize ];then humansize $_siz _str printf "%s%12s%14s_%s\n" "$_spc" "$_str" \\ "${_crt##*/}" [ $d "$_crt" ] && rdu "$_crt" " $_spc" fi fi done < <( find "$_dir" -mindepth 1 -maxdepth 1 -print ) } rdu "${1:-.}" 

使用示例:

 ./rdu.sh /usr 100000000 1.53G \_lib 143.52M \_i386-linux-gnu 348.16M \_x86_64-linux-gnu 107.80M \_jvm 100.20M \_java-6-openjdk-amd64 100.17M \_jre 99.65M \_lib 306.63M \_libreoffice 271.75M \_program 107.98M \_chromium 99.57M \_lib32 452.47M \_bin 2.50G \_share 139.63M \_texlive 129.74M \_texmf-dist 478.36M \_locale 124.49M \_icons 878.09M \_doc 364.02M \_texlive-latex-extra-doc 359.36M \_latex 

小检查:

 du -bs /usr/share/texlive/texmf-dist 136045774 /usr/share/texlive/texmf-dist echo 136045774/1024^2 | bc -l 129.74336051940917968750 

注意:使用-b而不是-k告诉du仅使用已使用的字节,但没有有效的保留空间(以512字节为单位)。 为了处理区块的大小,你必须通过du -xks来更改line du -xbs ... ,在_a=(KMGTP)禁止b并将参数大小除以1024。

…有一个修改后的版本(我会自己保留)默认使用大小,但接受-b作为字节计算的第一个参数:

编辑:新版本

经过一番工作后,有一个更新的版本更快 ,输出按降序大小顺序sorting:

 #!/bin/bash if [ "$1" == "-b" ] ;then shift export units=(b KMGTP) export duargs="-xbs" export minsize=${2:-$((256*1024**2))} else export units=(KMGTP) export duargs="-xks" export minsize=${2:-$((256*1024))} fi humansize() { local _c=$1 _i=0 while [ ${#_c} -gt 3 ] ;do ((_i++)) _c=$((_c>>10)) done _c=$(( ( $1*1000 ) >> ( 10*_i ) )) printf ${2+-v} $2 "%.2f%s" ${_c:0:${#_c}-3}.${_c:${#_c}-3} ${units[_i]} } export device=$(stat -c %d "${1:-.}") rdu() { local _dir="$1" _spc="$2" _crt _siz _str while read _siz _crt;do if [ $_siz -gt $minsize ];then humansize $_siz _str printf "%s%12s%14s_%s\n" "$_spc" "$_str" \\ "${_crt##*/}" [ -d "$_crt" ] && [ $(stat -c %d "$_crt") -eq $device ] && rdu "$_crt" " $_spc" fi done < <( find "$_dir" -mindepth 1 -maxdepth 1 -xdev \ \( -type f -o -type d \) -printf "%D;%p\n" | sed -ne "s/^${device};//p" | tr \\n \\0 | xargs -0 du $duargs | sort -nr ) } rdu "${1:-.}" 

要显示当前文件夹中最大的前20个目录,请使用以下单行命令:

 du -ah . | sort -rh | head -20 

要么:

 du -a . | sort -rn | head -20 

对于当前目录中的前20个最大文件(recursion):

 ls -1Rs | sed -e "s/^ *//" | grep "^[0-9]" | sort -nr | head -n20 

或与人类可读的大小:

 ls -1Rhs | sed -e "s/^ *//" | grep "^[0-9]" | sort -hr | head -n20 

第二个命令正确地工作在OSX / BSD(如sort没有-h ),你需要安装从coreutils sort 。 然后将bin文件夹添加到您的PATH

所以这些别名在你的rc文件中是有用的(每当你需要的时候):

 alias big='du -ah . | sort -rh | head -20' alias big-files='ls -1Rhs | sed -e "s/^ *//" | grep "^[0-9]" | sort -hr | head -n20'