Importance of du command
du command is most popular Unix command using which you can get an overview of your file-directory space usage. It quickly estimate diskspace usage by certain directory. You can get full data about sizes of few specific directories, full directory tree or even size of each file.
If certain directory is eating up all your allotted diskspace which may cause overload on your server resulting server crash or preventing further logins. Thus du command is very useful for a system administrator to get all details on disk usage and can monitor it, so that they can avoid system crashes.
You can use du -sh * to get the biggest directory which is eating up your diskspace, again cd into it and once again fire above command, finally you will get required file which is consuming maximum diskspace so that you can think over it and take necessary action against it.
$ du –h will display output of diskusage in Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte (Human-readable output)
To use du command you should have read permission on that particular directories else you cant get diskspace consumption report for that particular directory, thus normal user with limited permissions can’t use this command for files/directories belonging to other users.
You can use different attributes with du commands :
du [-a] [-k] [-s] [-d] [-L] [-o] [-r] [-x] directories
|
-a |
Displays the space that each file is taking up. |
|
-k |
Write the files sizes in units of 1024 bytes, rather than the default 512-byte units. |
|
-s |
Instead of the default output, report only the total sum for each of the specified files. |
|
-d |
Do not cross filesystem boundaries. For example, du -d / reports usage only on the root partition. |
|
-L |
Process symbolic links by using the file or directory which the symbolic link references, rather than the link itself. |
|
-o |
Do not add child directories’ usage to a parent’s total. Without this option, the usage listed for a particular directory is the space taken by the files in that directory, as well as the files in all directories beneath it. This option does nothing if -s is used. |
|
-r |
Generate messages about directories that cannot be read, files that cannot be opened, and so forth, rather than being silent (the default). |
|
-x |
When evaluating file sizes, evaluate only those files that have the same device as the file specified by the file operand. |
|
directories |
Specifies the directory or directories. |












