How to get the size of linux folders

September 18, 2021

How to get the size of linux folders

To get the size of a directory you can use the du command. To get the total size of the disrectory (without the subdirectories) use the s argument. The h argument will display the number in human readable form.


sudo du -sh

sudo du -sh /var

To list the subdirectories:

sudo du -sh /var/*


sudo du -h --max-depth=1 /var

How to clean up space

The command sudo apt-get autoclean will clean up the apt-get cache.

The command sudo apt-get autoremove will remove packages that were automatically installed to satisfy dependencies for some package and no longer needed by those packages.

rm -r /path/to/dir/* command removes all files and subdirectories from the path you choose.

journal logs

You can control the size of /var/log/journal using this parameter in  /etc/systemd/journald.conf:

sudo nano /etc/systemd/journald.conf


And then restart the service

sudo systemctl restart systemd-journald.service