Under Linux, I'm looking for a command to list the largest file and/or the largest directories under a directory.
10 Answers
A utility called ncdu will give you the information you are looking for.
sudo apt-get install ncdu
On OS X, it can be installed using Homebrew:
brew install ncdu
- 2,491
- 1,431
- 2
- 9
- 2
Following command shows you one level of directories and their sizes
du --max-depth=1 /path | sort -r -k1,1n
If one of them really sticks out (the last one on the list is the largest due to sort -r), then you re-run the command on that directory, and keep going until you find the offending directory / file.
If all you want is the ten biggest files just do
find /home -type f -exec du -s {} \; | sort -r -k1,1n | head
Following command will return top 10 biggest files from given /path
du -a -h /path | sort -h -r | head -n 10
I like to use -h options for readability. Both du and sort need to have -h.
- 163
- 201
du -sk * | sort -nr | head -1
This will show the biggest directory/file in a directory in KB. Changing the head value will result in the top x files/directories.
- 39
- 1
This post will help you well:
cd /path/to/some/where
du -a /var | sort -n -r | head -n 10
du -hsx * | sort -rh | head -10
- 163
- 311
Use
ls -A | xargs -I artifact du -ms artifact | sort -nr
Optionally, you can add a pipe and use head -5
- 11
Try the following one-liner (displays top-20 biggest files in the current directory):
ls -1Rs | sed -e "s/^ *//" | grep "^[0-9]" | sort -nr | head -n20
or with human readable sizes:
ls -1Rhs | sed -e "s/^ *//" | grep "^[0-9]" | sort -hr | head -n20
The second command to work on OSX/BSD properly (as
sortdoesn't have-h), you need to installsortfromcoreutils.
So these aliases are useful to have in your rc files (every time when you need it):
alias big='du -ah . | sort -rh | head -20'
alias big-files='ls -1Rhs | sed -e "s/^ *//" | grep "^[0-9]" | sort -hr | head -n20'
- 26,615
du -sh /path * | sort -nr | grep G
G for GIG (to weed out smaller) files/directories
- 7,466
- 1