Drive Space Cheat Sheet for Linux/Ubuntu Machines

I find myself forgetting syntax when it comes to checking drive space and freeing space, here is a handy cheat sheet you hopefully will find handy for finding and cleaning up old data from your Ubuntu machine.

Note! Whenever cleaning up, take a backup first!

Checking Drive Space

  • df -h : Check disk space usage in human-readable format
  • df -i : Check inode usage (number of files)
  • du -sh / : Estimate disk space usage of the root directory
  • du -sh ~ : Estimate disk space usage of your home directory

Finding Large Files and Directories

  • find / -type f -size +100M -exec ls -lh {} \; : Find files larger than 100MB
  • find / -type d -size +100M -exec ls -lh {} \; : Find directories larger than 100MB
  • du -a / | sort -n -r | head -n 10 : Show top 10 largest directories and files

Freeing Up Space

  • sudo apt autoremove : Remove unnecessary packages
  • sudo apt clean : Remove package cache
  • sudo rm -rf /tmp/* : Remove temporary files
  • sudo rm -rf ~/.cache/* : Remove user cache files

Additional Tips

  • Regularly clean up your /var/log directory to prevent log file buildup
  • Consider setting up a cron job to automate disk cleanup tasks

Remember to always be cautious when deleting files and directories, and make sure to backup your data before making any changes!


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *