Monday, November 19, 2007

Get Linux Disk Space and Usage

Here's is a command that shows several usage and ways of retrieving disk space usage. This disk space usage command is another abused and bypassed linux command that has been repeated over and over again from samples and old linux blog entries among the blog entries around here.

Here's a quick run covering details and samples on how to determine and show disk space (available and free) from your current harddisk using the 'df' linux command.

As root, simply

# df
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 27925596 8167952 18316216 31% /
/dev/sda1 46362180 27650596 16356460 63% /data
/dev/sda2 101105 11644 84240 13% /boot
tmpfs 509348 0 509348 0% /dev/shm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Legend:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
First column - disk partition name
Second column - total partition allocation
Third column - total used disk space on the specified disk partition
Fourth column - total free or available disk space on the specified disk partition
Fifth column - equivalent disk space allocation in percentage
Sixth column - mount point name of the specified disk partition
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A human readable harddisk space report covering dummy file system would be
# df -ah
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/dev/sda5 27G 7.8G 18G 31% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 - /dev/pts
/dev/sda1 45G 27G 16G 63% /data
/dev/sda2 99M 12M 83M 13% /boot
tmpfs 498M 0 498M 0% /dev/shm
none 0 0 0 - /proc/sys/fs/binfmt_misc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To list down inode information instead of hard disk block usage

# df -ih
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda5 6.9M 210K 6.7M 3% /
/dev/sda1 5.7M 31K 5.6M 1% /data
/dev/sda2 26K 32 26K 1% /boot
tmpfs 125K 1 125K 1% /dev/shm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A sample disk space output of RAIDed SCSI disks over LVM partitions

# df -vh
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 22G 12G 9.1G 56% /
/dev/cciss/c0d0p3 43G 36G 4.5G 89% /backup
/dev/cciss/c0d0p1 99M 20M 75M 21% /boot
/dev/mapper/VolGroup00_home-LogVol00_home
67G 18G 46G 29% /home
/dev/mapper/VolGroup00_var-LogVol00_var
67G 42G 22G 66% /var
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By default, df does not do 'sync' before the disk usage is retrieved.

To invoke disk sync before showing disk usage information would be
# df -ah --sync

To customize the disk byte block size when checking disk space usage would be:
(assuming a 2K per disk block)
# df -avh -B2048

To retrieve disk usage and file system types using df would be
# df -avhT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda5 ext3 27G 7.8G 18G 31% /
/dev/sda1 ext3 45G 27G 16G 63% /data
/dev/sda2 ext3 99M 12M 83M 13% /boot
tmpfs tmpfs 498M 0 498M 0% /dev/shm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
***Note the second column that shows the file system types

To show disk space usage with exclusion to specific file system would be
# df -vhT -x tmpfs
Filesystem Type Size Used Avail Use% Mounted on
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/dev/sda5 ext3 27G 7.8G 18G 31% /
/dev/sda1 ext3 45G 27G 16G 63% /data
/dev/sda2 ext3 99M 12M 83M 13% /boot
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
***Note that the tmps file system has been excluded from being listed

To send these disk space reports to your email, simply follow the old link here.

HTH

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy