Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Linux command to find largely disk space utilized file. I need to list all files in the order of size

share|improve this question

migrated from stackoverflow.com Nov 27 '10 at 5:31

This question came from our site for professional and enthusiast programmers.

    
Belongs to superuser.com. –  EboMike Nov 27 '10 at 5:13
add comment

3 Answers

du -k | sort -rn | head -n 50

Where:

  • The du utility displays the file system block usage for each file argument and for each directory in the file hierarchy rooted in each directory argument. If no file is specified, the block usage of the hierarchy rooted in the current directory is displayed. -k will display block counts in 1024-byte (1-Kbyte) blocks.

  • sort is self-explanatory. -r reverses the result of comparisons, placing the highest value atop the list. -n compares according to string numerical value.

  • head only shows the top n rows. 50 in this case.

share|improve this answer
add comment

Always keep something like this tucked away in an alias somewhere:

find / -type f | xargs ls -s | sort -rn | awk '{size=$1/1024; printf("%dMb %s\n", size,$2);}' | head
share|improve this answer
    
expensive as ls is called on every individual file. -printf instead of xargs resolves that. –  pbr Nov 27 '10 at 5:40
add comment

Here you go.

For the / device, and only for that device, this prints the 500 largest files with their size in megabytes. Omit the "head -n 500" and it'll print all files with sizes, sorted largest first.

find / -xdev -type f -printf "%s %h/%f\n" | sort -rn -k1 | head -n 500 | awk '{ print $1/1048576 "MB" " " $2}'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.