Troubleshooting Disk Space Usage

A couple years ago, my coworker wrote a great post on finding disk space issues in Linux and how to resolve them. Helped me out this weekend when a critical server was having issues, so wanted to post it here:

For future reference (after reading the post above)

Show filesystem usage:

~$ df -h

Show all files/directories consuming space:

~$ du -kx / | sort -nr | more

Show directories in current location:

~$ du -hc | sort -h
~$ du -hc --max=1 | sort -h #This limits your directory listing to one level

List files in directory:

~$ ls -larth

List files in directory sorted by size, ascending:

~$ ls -lSrh

List and then delete any .log file older than 7 days:

~$ find . -type f -name "*.log" -mtime +7 -print -exec rm -fr {} \;

Another easy way to reclaim space by removing unused dependencies:

~$ apt-get autoremove