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.
ducommand is a powerful tool for managing disk usage on Linux systems
- You can use the
hflag to see sizes in “human-readable” format (e.g. 1.2G instead of 1234456)
dflag allows you to specify a depth level for the
du -d 2will only scan two levels deep in the directory tree)
cflag shows a grand total of the disk usage for all files and directories
headcommands can be used in combination with
duto sort and limit the output for easier analysis
- Find the top 10 largest files in your home directory:
du ~/* | sort -nr | head -n 10
- Find the top 10 largest directories in your home directory:
du -d 1 ~/* | sort -nr | head -n 10
- See a breakdown of disk usage by file type in your home directory:
du --exclude=/*/* ~/* | sort -nr
du -hcto see a grand total of disk usage for all files and directories in a specific directory (e.g.
du -hc /var/log)
- Use the
findcommand to search for and delete large files that you no longer need:
find / -size +100M -delete
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!