We have moved to www.dataGenX.net, Keep Learning with us.

Saturday, January 07, 2012

du command & tips

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

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 ducommand 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 -s This 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

No comments :

Post a Comment