- The first command I’ll show you is ‘df‘ (disk free):
– `df -h` : Displays the sizes of the mounted file systems in human readable format. Here is the output on my machine:
Filesystem Size Used Avail Use% Mounted on /dev/sda5 7.6G 5.9G 1.3G 83% / udev 3.8G 12K 3.8G 1% /dev tmpfs 1.6G 1.1M 1.6G 1% /run none 5.0M 0 5.0M 0% /run/lock none 3.8G 13M 3.8G 1% /run/shm none 100M 16K 100M 1% /run/user /dev/sda6 54G 24G 28G 46% /home /dev/sda2 54G 48G 5.4G 90% /media/5CCAC272CAC247CA
Easy to understand. Try running only `df`, the result will be similar but the metrics will be different.
– `df –total -h` This command is the same as the above, but will show you the total size, used and available of all your storage media.
Filesystem Size Used Avail Use% Mounted on /dev/sda5 7.6G 5.9G 1.3G 83% / udev 3.8G 12K 3.8G 1% /dev tmpfs 1.6G 1.1M 1.6G 1% /run none 5.0M 0 5.0M 0% /run/lock none 3.8G 6.3M 3.8G 1% /run/shm none 100M 16K 100M 1% /run/user /dev/sda6 54G 24G 28G 46% /home /dev/sda2 54G 48G 5.4G 90% /media/5CCAC272CAC247CA total 124G 77G 44G 65%
– `df -a` This will show you the sizes of the dummy file systems like ‘/proc’.
Try executing `df –total -ah`
- The second command is ‘du’ (disk usage). Du shows the sizes of directories and their sub-trees. For example navigate to your home directory and type `du`. This will print something very long and hard to read. Try the ‘du’ command with a small directory tree.
– `du -h` Like the ‘df’ version – human readable. Here is an example:
du -h Music/smerch/ 530M Music/smerch/segment 3 282M Music/smerch/segment 1 269M Music/smerch/segment 5 alt 441M Music/smerch/segment 4 610M Music/smerch/segment 2 2.1G Music/smerch/
Try it yourself.
– `du -ah` This adds the sizes of each file in the folder passed and it sub-trees. The ‘-a’ option stands for all.
– `du -hs` This will list the sizes only of the current directory and its direct sub-directories.
– You can pass globs to ‘du’ to filter its output.
– `du -sk .[!.]* *| sort -n` Now this is something interesting. It shows the sizes of all the direct sub-folders of the current folder, including the hidden ones and the output is sorted by these sizes. The size metric is kilobyte. The ‘-s’ option tells ‘du’ to show the sizes only of the direct sub-folders and the current folder. The ‘-k’ option tells ‘du’ that it should display the sizes in kilobytes (you can use -h or -m instead). The globs .[!.]* * specify all the hidden folder names and all the folder names respectively. The result is then passed to ‘sort’. You can pass the ‘-r’ option to ‘sort’ to reverse the output.
– You can specify the maximum depth of the sub-directory trees – `du -h –max-depth=1`. The -d option is a synonym of –max-depth.
If you want to explore more use man or info with df and du.
- This is not included in the title, but I’m going to show you the ‘free’ command too.
– `free` Displays information for the memory (used/available/total) in kilobytes (-b will display the same information in bytes, -m in megabytes and -g in gigabytes).
– `free –total` Displays total summary for physical memory + swap space.
– `free -s 5` Now free will begin displaying memory information and it will be updated on every 5 seconds.