Checking disk usage in linux

Posted under » Linux on 30 Sep 2020

To check disk usage

df command
Shows the amount of disk space used and available on Linux file systems.
du command
is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine. The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursively manner

Know which folders take a lot of space.

df -H

Read related command 'lsblk' and 'lshw -C disk'.

du  /home/ 

To get the summary of a grand total disk usage size of an directory use the option “-s”

Using “-a” flag with “du” command displays the disk usage of all the files and directories.

The output of the above command displays the number of disk blocks in the /home/ directory along with its sub-directories.

If there are many subdiretories, often you just want to see a bit.

-h stands for human readable format but if you want to know the file name in bytes, then

du -b file.jpg

To sort according to size and list only 10 rows

du -a /etc | sort -n -r | head -n 10

We often use the diff – to show you the difference between two computer files; compares files line by line but you can also use diff to compare file diretories.

diff -q directory-1/ directory-2/

You can alias the location of directory in case one of your main hardisk is full.

Read also Why df shows over 200G space used, while du only shows 50G used?.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS