Never Ending Security

It starts all here

du Commands Cheatsheet

du Command Examples

du Command Examples – The Linux “du” (Disk Usage) is a standard Unix/Linux command used to check the information about hard disk usage, files and directories. The du command has many parameters and it produces report in many different formats.

Directory Summary

To find out the disk usage summary of a /home/cyberpunk directory tree and each of its sub directories:

[cyberpunk@n0where.net]# du  /home/cyberpunk

40      /home/cyberpunk/downloads
4       /home/cyberpunk/.mozilla/plugins
4       /home/cyberpunk/.mozilla/extensions
12      /home/cyberpunk/.mozilla
12      /home/cyberpunk/.ssh
689112  /home/cyberpunk/Debian
689360  /home/cyberpunk

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

Human Readable Format

By using “-h” option with “du” command you will get more “Human Readable Format“. All sizes will be shown inBytesKilobytes, MegabytesGigabytes etc.

[cyberpunk@n0where.net]# du -h /home/cyberpunk

40K     /home/cyberpunk/downloads
4.0K    /home/cyberpunk/.mozilla/plugins
4.0K    /home/cyberpunk/.mozilla/extensions
12K     /home/cyberpunk/.mozilla
12K     /home/cyberpunk/.ssh
673M    /home/cyberpunk/Debian
674M    /home/cyberpunk

Directory Total

To get the summary of a disk usage size for a specific directory use the “-s” switch

[cyberpunk@n0where.net]# du -sh /home/cyberpunk

674M    /home/cyberpunk

Files and Directory Usage

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

[cyberpunk@n0where.net]# du -a /home/cyberpunk

4       /home/cyberpunk/.bash_logout
12      /home/cyberpunk/downloads/upload.tgz
24      /home/cyberpunk/downloads/somefiles.tar.bz2
40      /home/cyberpunk/downloads
12      /home/cyberpunk/someotherfile.tgz
4       /home/cyberpunk/.mozilla/plugins
4       /home/cyberpunk/.mozilla/extensions
12      /home/cyberpunk/.mozilla
4       /home/cyberpunk/.bashrc
689108  /home/cyberpunk/Debian/Debian.iso
689112  /home/cyberpunk/Debian
689360  /home/cyberpunk

Files and Directory Usage – HRF

Using “-a” switch along with “-h” switch results in showing disk usage of all files and folders in human readable format.

[cyberpunk@n0where.net]# du -ah /home/cyberpunk

4.0K    /home/cyberpunk/.bash_logout
12K     /home/cyberpunk/downloads/upload.tgz
24K     /home/cyberpunk/downloads/somefiles.tar.bz2
40K     /home/cyberpunk/downloads
12K     /home/cyberpunk/someotherfile.tgz
4.0K    /home/cyberpunk/.mozilla/plugins
4.0K    /home/cyberpunk/.mozilla/extensions
12K     /home/cyberpunk/.mozilla
4.0K    /home/cyberpunk/.bashrc
673M    /home/cyberpunk/Debian/Debian.iso
673M    /home/cyberpunk/Debian
674M    /home/cyberpunk

Directory Tree in kb

For directory tree in Kilobyte blocks. Use the “-k” (displays size in 1024 bytes units).

[cyberpunk@n0where.net]# du -k /home/cyberpunk
40      /home/cyberpunk/downloads
4       /home/cyberpunk/.mozilla/plugins
4       /home/cyberpunk/.mozilla/extensions
12      /home/cyberpunk/.mozilla
12      /home/cyberpunk/.ssh
689112  /home/cyberpunk/Debian
689360  /home/cyberpunk

Directory Tree in MB

To get the summary of disk usage of directory in Megabytes (MB) use the switch “-mh” a:

[cyberpunk@n0where.net]# du -mh /home/cyberpunk

40K     /home/cyberpunk/downloads
4.0K    /home/cyberpunk/.mozilla/plugins
4.0K    /home/cyberpunk/.mozilla/extensions
12K     /home/cyberpunk/.mozilla
12K     /home/cyberpunk/.ssh
673M    /home/cyberpunk/Debian
674M    /home/cyberpunk

du -c

The “-c” flag provides a total disk space usage at the last line:

[cyberpunk@n0where.net]# du -ch /home/cyberpunk

40K     /home/cyberpunk/downloads
4.0K    /home/cyberpunk/.mozilla/plugins
4.0K    /home/cyberpunk/.mozilla/extensions
12K     /home/cyberpunk/.mozilla
12K     /home/cyberpunk/.ssh
673M    /home/cyberpunk/Debian
674M    /home/cyberpunk
674M    total

du –exclude

List disk usage of all the files and directories and exclude the files that matches given pattern.

[cyberpunk@n0where.net]# du -ah --exclude="*.txt" /home/cyberpunk

4.0K    /home/cyberpunk/.bash_logout
12K     /home/cyberpunk/downloads/upload.tgz
24K     /home/cyberpunk/downloads/somefiles.bz2
40K     /home/cyberpunk/downloads
12K     /home/cyberpunk/someotherfiles.tgz
4.0K    /home/cyberpunk/.bash_history
4.0K    /home/cyberpunk/.bash_profile
4.0K    /home/cyberpunk/.mozilla/plugins
4.0K    /home/cyberpunk/.mozilla/extensions
12K     /home/cyberpunk/.mozilla
4.0K    /home/cyberpunk/.bashrc
673M    /home/cyberpunk/Debian/Debian.iso
673M    /home/cyberpunk/Debian
674M    /home/cyberpunk

du –time

Display the disk usage based on modification of time, use the flag “–time” as shown below.

[cyberpunk@n0where.net]# du -ha --time /home/cyberpunk

4.0K    2014-09-10 22:32        /home/cyberpunk/.bash_logout
12K     2014-09-09 18:48        /home/cyberpunk/downloads/upload.tgz
24K     2014-09-09 18:48        /home/cyberpunk/downloads/somefiles.tar.bz2
40K     2014-09-09 18:48        /home/cyberpunk/downloads
12K     2014-09-09 18:32        /home/cyberpunk/someotherfiles.tgz
4.0K    2014-09-08 00:11        /home/cyberpunk/.bash_history
4.0K    2014-09-08 22:32        /home/cyberpunk/.bash_profile
4.0K    2014-09-08 22:32        /home/cyberpunk/.mozilla/plugins
4.0K    2014-09-08 22:32        /home/cyberpunk/.mozilla/extensions
12K     2014-09-08 22:32        /home/cyberpunk/.mozilla
4.0K    2014-09-08 22:32        /home/cyberpunk/.bashrc
673M    2014-09-07 18:51        /home/cyberpunk/Debian.iso
673M    2014-09-07 18:51        /home/cyberpunk/Debian
674M    2014-09-07 18:52        /home/cyberpunk
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s