Under Linux, I'm looking for a command to list the largest file and/or the largest directories under a directory.
310 Answers
From any directory:
du -a | sort -n -r
A utility called ncdu will give you the information you are looking for.
sudo apt-get install ncduOn OS X, it can be installed using Homebrew:
brew install ncdu 5 Following command shows you one level of directories and their sizes
du --max-depth=1 /path | sort -r -k1,1nIf 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 5 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.
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.
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 0 Use
ls -A | xargs -I artifact du -ms artifact | sort -nrOptionally, you can add a pipe and use head -5
Use du. Try this to order the result:
du | sort -n 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 -n20or with human readable sizes:
ls -1Rhs | sed -e "s/^ *//" | grep "^[0-9]" | sort -hr | head -n20The 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' du -sh /path * | sort -nr | grep GG for GIG (to weed out smaller) files/directories
2