Thursday, May 22, 2008

Check Disk Space in Linux

Linux / Unix df command

About df

Report how much free disk space is available for each mount you have.

Syntax

df [OPTION]... [FILE]...
-a, --all include dummy file systems
-B, --block-size=SIZE use SIZE-byte blocks
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si likewise, but use powers of 1000 not 1024
-i, --inodes list inode information instead of block usage
-k like --block-size=1K
-l, --local limit listing to local file systems
--no-sync do not invoke sync before getting usage info (default)
-P, --portability use the POSIX output format
--sync invoke sync before getting usage info
-t, --type=TYPE limit listing to file systems of type TYPE
-T, --print-type print file system type
-x, --exclude-type=TYPE limit listing to file systems not of type TYPE
--version output version information and exit

Examples

df

In the above example when performing just the df command with no additional switches or specification of the file or directory you would get a listing of all file systems and their used and available space.

df -h

The above command is one of the most commonly used commands as it displays the sizes in an easy to read format as shown in the below example.
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 28G 7.6G 19G 29% /
tmpfs 252M 0 252M 0% /lib/init/rw
tmpfs 252M 0 252M 0% /dev/shm
/dev/hda1 464M 37M 403M 9% /boot
/dev/hda3 8.3G 429M 7.5G 6% /var
nfs6:/home 520G 461G 60G 89% /home
mirrors:/mirrors 1.4T 1.1T 233G 83% /mirrors
/dev/mapper/big-phat 77G 36G 42G 46% /space
mailstore:/var/mail 9.9G 4.8G 4.7G 51% /var/mail

df -b public_html

In the above example this command would display the amount of free space in the public_html directory. Below is an example of the output may display when performing this command.

Filesystem avail
nfs.computerhope.com:/home 10068252

Related commands

du
find
ls

No comments: