Logo
Loading...
Published on

Searching for big files/directories on a server

Author

Since my server is quite small and has limited space available (only 50 gb), I've decided to look what eats space and maybe not needed.

So first of all we will scan our directories and find which one's are using the most. For this let's use command:

du -h --max-depth=1 -t 1G / | sort -rh | head -10

Where params are:

  • -h: human readable sizes
  • -t 1G: only list directories bigger than 1G
  • sort -h: compare human readable numbers (e.g., 2K 1G)
  • sort -r: reverse the output to list biggest folders first
  • head -10: only list the first (biggest) 10 items
  • / : directory to scan in

Interestigly I've found that snap directory was using around 2G, even tho I'm not using any snaps, so removing of snapd can get you some space on Ubuntu.

Also I've foud out that my /var/log directory is above 4G, and interestingly almost all of this were journalctl logs.

So here I would share commands to check/clear journalctl logs, so maybe you could save some space too.

Check current disk usage of journal files

sudo journalctl --disk-usage

Rotate journal files

Active journal files will be marked as archived, so that they are never written to in future.

sudo journalctl --rotate

Delete journal logs older than 5 days

sudo journalctl --vacuum-time=5days

Delete log files until the disk space taken falls below 200M

sudo journalctl --vacuum-size=200M