搜索关键字:
linux sort by file/directory size
参考解答:
ls/find 之类的通通不行,还是对需要 du 命令的输出进行处理才能达到想要的效果
第一选择是du命令(GNU coreutils >= 7.5):
$ du --version du (GNU coreutils) 8.4 du -sh * | sort -h du -sh --max-depth=1 * | sort -hr
其它的选择还是du命令:
$ du --version du (GNU coreutils) 8.4 $ du -sh * | sort -h $ du -sh --max-depth=1 * | sort -hr $ du --max-depth=1 | sort -nr | cut -f2- | xargs du -hs $ du -B1 | sort -nr |awk '{sum=$1;hum[1024**3]="G";hum[1024**2]="M";hum[1024]="K"; for(x=1024**3; x>=1024; x/=1024){ if (sum>=x) { printf "%.1f%s\t\t",sum/x,hum[x];print $2;break }}}' $ du --max-depth=1 -B1 | sort -nr |awk '{sum=$1;hum[1024**3]="G";hum[1024**2]="M";hum[1024]="K"; for(x=1024**3; x>=1024; x/=1024){ if (sum>=x) { printf "%.1f%s\t\t",sum/x,hum[x];print $2;break }}}' $ du --max-depth=1 -h | awk '{printf "%s %08.2f\t%s\n", index("KMG", substr($1, length($1))), substr($1, 0, length($1)-1), $0}' | sort -r | cut -f2,3 $ du --max-depth=1 -h | perl -e 'sub h{%h=(K=>10,M=>20,G=>30);($n,$u)=shift=~/([0-9.]+)(\D)/; return $n*2**$h{$u}}print sort{h($b)<=>h($a)}<>;' $ du --max-depth=1 -h | perl -e'%h=map{/.\s/;99**(ord$&&7)-$`,$_}`du -h`;die@h{sort%h}' $ sudo apt-get install libnumber-bytes-human-perl $ du --max-depth=1 -B1 | sort -nr | perl -MNumber::Bytes::Human=format_bytes -F'\t' -lane 'print format_bytes($F[0])."\t".$F[1]' $ du --max-depth=1 -h | perl -e '@l{ K, M, G } = ( 1 .. 3 ); print sort { ($aa) = $a =~ /(\w)\s+/; ($bb) = $b =~ /(\w)\s+/; $l{$aa} <=> $l{$bb} || $a <=> $b } <>'
参考链接:
- http://serverfault.com/questions/62411/how-can-i-sort-du-h-output-by-size #Nice
- http://www.cyberciti.biz/faq/how-do-i-sort-du-h-output-by-size-under-linux/
- http://www.cyberciti.biz/faq/how-do-i-find-the-largest-filesdirectories-on-a-linuxunixbsd-filesystem/ #Nice
- http://unix.stackexchange.com/questions/53737/how-to-list-all-files-in-the-size-order
- http://unix.stackexchange.com/questions/88065/sorting-files-according-to-size-recursively #Nice
- http://stackoverflow.com/questions/7463554/bash-how-can-i-list-out-the-size-of-each-file-and-directory-recursively-and-s #Nice
- =
- http://www.ducea.com/2006/05/14/tip-how-to-sort-folders-by-size-with-one-command-line-in-linux/ #评论
- http://www.cyberciti.biz/faq/linux-ls-command-sort-by-file-size/