Linux Disk Usage Commands

So as a sysadmin we should already be pretty familiar with the du command.  It’s a command that allows us to see file and directory sizes, as well as view both decreasing or increasing from the smallest or biggest file.

Here are a few basic du command arguments that have helped me over the years.

du -a

du -all shows all files and directories included in the directory you’re currently in

du -h

du -human-readable shows all files and directories in a format that’s better than just bytes.  So we’ll see listings in KB, MB, and GB.

du -s

du -summarize displays only a total of everything in a directory in bytes.  A better way to do this is (du -hs).

du -S

du -separate-directories does not include sub directory sizes.  Sometimes you just want to see files.

du –time

This shows the last modification time for each file, directory, and sub-directory.

Here are some more intermediate to advanced du commands that might be useful:

find -type f -exec du -sh {} +  | sort -r | head

Search the current directory you are in, as well as sub-directories in it for the biggest files.  Great for auditing.

du -skh .[!.]* *| sort -n

Shows file, directory, and sub-directory sizes including hidden with increase sorting.

du -skh .[!.]* *| sort -nr

Shows file, directory, and sub-directory sizes including hidden files with decrease sorting.

du –max-depth 1 -xh / or du -msh * | sort -n | tail -5

Shows file, directory, and sub-directory sizes including hidden at a max depth of a directory.  The second command is just another way to do that.  Sometimes you don’t need everything within everything.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s