Thursday, September 2, 2010

A work of art: How to find, view and sort biggest files and/or directories in linux...

du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); 

printf ("%6.1f\t%s\t%25s  %s\n",($1/(2**(10*$m))),

(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}'
The above (in one line command) will find, view, sort and print in the screen stars in ascending order the biggest files and/or directories from the current directory.
Certainly is a very useful command. It's a work of programming art.
Thanks to Jonathan Jiang
[from  http://www.cyberciti.biz/faq/find-large-files-linux/ ]

0 comments: