linux beginner
Now Reading
du Command (Disk Management) in Linux with Examples
0

du Command (Disk Management) in Linux with Examples

Disk Usage du Command

Introduction:

The Disk Usage du command is the static commands for UNIX/LINUX based distributions. This command is used to check information of disk usage of the files and directories of the system. The du utility first appeared in version 1 of AT&T UNIX

The Disk usage (du)

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 different options as per need. Let we discuss du command with various options.

To find disk usage status

The following command will display full disk usage of the /home/linuxManual. The number shown 64, 68, 60 are size of the sub-directories and 1632 refers the total size of that folder.
Example:

[user1@linuxhelp Desktop]$ du 
64        ./linuxfilenotes/df
68        ./linuxfilenotes/rsync
60        ./linuxfilenotes/du
60        ./linuxfilenotes/scp
88        ./linuxfilenotes/linux fhs
344       ./linuxfilenotes
1368      ./LinuxManual
1368

To display in Human Readable Format

This command show the result in “Human Readable Format”, which means it display the result in KB ,MB ,GB size format Using option ‘-h ‘with ‘du‘ command.
Example:

[user1@linuxhelp Desktop]$ du -h 
64K     ./linuxfilenotes/df
68K     ./linuxfilenotes/rsync
60K     ./linuxfilenotes/du
60K     ./linuxfilenotes/scp
88K     ./linuxfilenotes/linux fhs
344K    ./linuxfilenotes
1.3M    ./LinuxManual
1.3M

To get grand total of directory

To get grand total of directory use ‘-s‘ in your disk usage where -h is human readable.
Example:

[user1@linuxhelp Desktop]$ du -sh 
1.3M

To find out the disk usage of a directory tree with its sub-tress

Using option ‘-m ‘with ‘du‘ command finds the disk usage of a directory tree with its sub-tress in Kilobyte , Megabyte , Gigabyte using following options.
To check size in MB size format and also it display KB
Example:

[user1@linuxhelp Desktop]$ du -mh 
104K FTPcpanelaccess/skins/overlay
108K FTPcpanelaccess/skins
63M  FTPcpanelaccess/ftp cpanel access_media

To display grand total of disk usage for individual files

Using option ‘-c ‘with ‘du‘ command” displays the grand total of disk usage for individual files present in directory
Example:

[user1@linuxhelp Desktop]$ du -ch 
64K                 ./linuxfilenotes/df
67K                 ./linuxfilenotes/rsync
60K                 ./linuxfilenotes/du
.
.
1.3M                ./linuxmanual
1.3M                 total

To Display the disk usage counts for all the files with grand total

The option -a is used to Display the disk usage counts for all the files with grand total.
Example:

[user1@linuxhelp Desktop]$ du -ah
16K   ./linuxfilenotes/df/links_df.odt
44K   ./linuxfilenotes/df/df command.odt
.
.
1.3M ./LinuxManual
1.3M

To calculate and display the disk usage of all files and directories

Using  option ‘–exclude ‘ with ‘du’ command is used to calculate and display the disk usage of all files and directories, but excludes the particular files that match given pattern.
Example:

[user1@linuxhelp Desktop]$ du -ah --exclude=”*.txt”
16K     ./linuxfilenotes/df/links_df.odt
44K     ./linuxfilenotes/df/df command.odt
.
.
16K     ./LinuxManual/ CHMOD command.odt
1.3M    ./LinuxManual
1.3M    .

To Display the disk usage based on modification of time

Using this option to Display the disk usage based on modification of time.
Example:

[user1@linuxhelp Desktop]$ du -ah --time 
16K   2016-2-15 16:18           ./linuxfilenotes/df/links_df.odt
44M  2016-2-15 16:30            ./linuxfilenotes/df/df command.odt
.
.
16K   2016-2-15 16:18.          ./LinuxManual/ CHMOD command.odt
1.3M 2016-2-15 16:18

To display the disk usage for all files and directories

This option can be used to display the disk usage for all files and directories including hidden files.

Example:

[user1@linuxhelp Desktop]$ du -sh .[!.]* * | sort -n 
16K   ./linuxfilenotes/df/links_df.odt
44K   ./linuxfilenotes/df/df command.odt
.
.
4.0K mydir/.text1.txt                         (hidden files)
4.0K mydir/.text1.txt                         (hidden files)
32K   mydir

Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.

For more help topics browse our website www.linuxhelp.com

Be the first to comment, we value your suggestions. For further queries please comment below.

Leave a Response