Useful du commands

The du command is very useful when you are looking at disk space usage. Here are some of the most commonly used parameters:

-h human-readable Displays sizes in human-readable format, using units such as KB, MB, GB, etc
-a, –all Lists all files with their sizes (combine with h to get the best result)
-d, –max-depth=N
–time Lists all files with their sizes and the timestamp of its last modification
-X, –exclude=<pattern> Lists all files except those that match <pattern>

To find the disk usage of all files in the directory except the tarred files:

du -ah --exclude=".tgz" --exclude=".tar.gz"

To find the 10 largest files in the current directory ordered by file size:
(This gets both directories and files by size)
for i in G M K; do du -ah | grep [0-9]$i | sort -nr -k 1; done | head -n 11
or
du -ah . | sort -n -r | head -n 10

(This gets only files ordered by size)
du -hsx * | sort -rh | head -10
or
du -ah --max-depth=1 | sort -h

About vicki

Welcome to the Sovereign Republic of Vickistan. I am the President here. Lucky me! No taxes or laws yet. Lucky you!
This entry was posted in Linux. Bookmark the permalink.