du command & tips

Hi folks, Here I am again with some nice nix commands tips/tricks
For this session, I have “du” command.

The basic syntax for du is:
du [options] [directories and/or files]

The du command displays the number of blocks used for files. If the File parameter specified is actually a directory, all files within the directory are reported on. If no File parameter is provided, the du command uses the files in the current directory……

$ ls -ls
total 6
2 -rw-r--r--   1 mjb     group        3 Feb 04 23:31 minutes.txt
4 -rw-r--r--   1 mjb     group     1201 Feb 04 23:25 note.txt
52 -rwxrwxrwx   1 adm     mqm      50329 Dec 16 08:25 addGLC  

The first column contains the size of the file in 512-byte blocks, and the sixth column gives the size of the file in bytes.
Earlier Unix systems used an allocation unit of 512 bytes. These 512 bytes came to be known as a block. As disk sizes grew, the basic allocation unit was increased to 1024 bytes on most systems (larger on some), but many utilities, such as ls above, still report file sizes or disk use in 512 byte blocks. So, the 3-byte file uses 2 blocks.

$du -a
8       ./.profile
8       ./.vi_history
8       ./.kshrc
8       ./dir1/ccms
The -a flag reports the number of blocks in individual files.

$du -sThis displays a summary of the directory size. It is the simplest way to know the total size of the current directory.

Shows the size in default block size (512 byte)
$du ./AUTOTEST/library/init.tcl
56      ./AUTOTEST/library/init.tcl

Shows the size in 1KB block size
$du -k ./AUTOTEST/library/init.tcl
28      ./AUTOTEST/library/init.tcl

Shows the size in 1MB block size
$du -m ./AUTOTEST/library/init.tcl
0.03    ./AUTOTEST/library/init.tcl

Shows the size in 1GB block size
$du -g ./AUTOTEST/library/init.tcl
0.00    ./AUTOTEST/library/init.tcl


a) display the disk usage of all files in KB
$du -ak | sort +nr

b) display the disk usage of largest 10 files in KB
du -ak | sort +nr | head

c)display everything sorted by filesize:
$ du -sk .[A-z]* *| sort -n

d)find top 5 directories, enter :
$ cd /home/user1
$ du -sk * | sort -nr | head -5


About victimizeit
This is Atul.. working for IBM as a DataStage Developer. I may not be an expert on any particular DataStgae technology, but I'm sure I do know a few things about DB2, AIX, Unix, Windows, and DataBase. In this blog, I'll give out some tips on these subjects. If you find them useful, great, I'll be happy. Thanks for stopping by !!

What is your opinion ?

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: