×


Category: Linux Commands


DU Command in Linux - More about it ?

This article covers the usage of the DU command in Linux. In fact, the du command makes it convenient for Linux users to stay aware of their disk consumption and make an upgrade if required.


How to sort du -h command output by size ?

The sort command provides -h parameter allows to compare human-readable numbers (e.g., 10K 15M 1G etc). This helps up to compare the results of `du -h` and short them.

It takes the below form:

$ du -h * | sort -h

This will display the results in the ascending order by size. 

You can also reverse this using -r to show results in descending order with the below command:

$ du -h * | sort -rh


What is the du -sh * command ?

The du -sh * command  will display only a total for each argument as well as print sizes in human readable format (e.g., 1K 234M 2G).

The command takes the below form:

$ du -sh


What is df command ?

The df command displays the amount of disk space available on the filesystem with each file name's argument.

The df command can be run by any user. Like many Linux commands, df uses the following structure:

$ df [OPTION]... [FILE]...

The df command primarily checks disk usage on a mounted filesystem. If you don't include a file name, the output shows the space available on all currently mounted filesystems. 


What is the differences between the df and du command in Linux ?

While du reports files and directories  disk usage, df reports how much disk space your filesystem is using.


How to use the du Command in GB / MB / TB format ?

The du command is used to estimate file space usage. To print sizes in human readable format such as 5K, 400M, or 3G, type the following commands:

du -h
du -h /tmp
du -h /home/user


How to use du (Disk Usage) Commands to Find Disk Usage of Files and Directories in Linux ?

The du command displays the files and directory sizes in a recursive manner.

  • To find out the disk usage summary of a /home/user directory tree and each of its subdirectories. Run the command as: # du  /home/folderName
  • You can use the "-h" option with the "du" command to print results in "Human Readable Format". This means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes, etc: # du -h /home/folderName
  • You can get the summary of a grand total disk usage size of a directory using the option "-s": # du -sh /home/folderName
  • You can use the "-a" flag with the "du" command displays the disk usage of all the files and directories: # du -a /home/folderName
  • You can use the "-a" flag along with "-h" displays disk usage of all files and folders in a human-readable format: # du -ah /home/folderName
  • You can find out the disk usage of a directory tree with its subtree in Kilobyte blocks using the "-k" (displays size in 1024 bytes units): # du -k /home/folderName
  • You can get the summary of disk usage of directory tree along with its subtrees in Megabytes (MB) only using the "-mh" option : # du -mh /home/folderName
  • You can use the "-c" flag to get a grand total usage disk space at the last line of the output: # du -ch /home/folderName

Search by typing a one letter Word Term Here