Skip to content
Home » Mastering Disk Management on Linux with the Terminal

Mastering Disk Management on Linux with the Terminal

  • Linux
  • 2 min read

If you’re a Linux user, you know that the terminal is a powerful tool for managing and optimizing your system. One important aspect of system management is keeping track of disk usage, especially when you’re running low on storage. In this blog, we’ll explore some simple but effective terminal commands that can help you keep your disk usage in check.

Linux systems have a built-in utility called du (short for “disk usage”) that allows you to see how much space each file and directory is taking up on your system. This can be extremely useful for identifying and deleting large or unnecessary files that are taking up valuable storage space.

Key Takeaways

  • The du command is a powerful tool for managing disk usage on Linux systems
  • You can use the h flag to see sizes in “human-readable” format (e.g. 1.2G instead of 1234456)
  • The d flag allows you to specify a depth level for the du scan (e.g. du -d 2 will only scan two levels deep in the directory tree)
  • The c flag shows a grand total of the disk usage for all files and directories
  • The sort and head commands can be used in combination with du to sort and limit the output for easier analysis

5 Tips

  1. Find the top 10 largest files in your home directory: du ~/* | sort -nr | head -n 10
  2. Find the top 10 largest directories in your home directory: du -d 1 ~/* | sort -nr | head -n 10
  3. See a breakdown of disk usage by file type in your home directory: du --exclude=/*/* ~/* | sort -nr
  4. Use du -hc to see a grand total of disk usage for all files and directories in a specific directory (e.g. du -hc /var/log)
  5. Use the find command to search for and delete large files that you no longer need: find / -size +100M -delete

Challenge

Now that you’ve learned some useful tips for managing disk usage on Linux with the terminal, try putting them into practice on your own system. Can you identify and delete some unnecessary files or directories to free up some storage space? Share your results in the comments below!

Leave a Reply

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

five + twelve =