df command in Linux provides disk space usage information of your file systems. Even if you already know about this command, probably one of the examples mentioned below might be new to you.
A sample output from df command is as follows:
$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 132239776 6210884 119311504 5% / tmpfs 4021876 0 4021876 0% /dev/shm /dev/sdb2 30969600 117740 29278696 1% /home/oracle /dev/sdc1 576310180 71232 546964104 1% /home/data
So we see that df gives some valuable information on the file systems, their mount points, their memory usage etc.
1. Display Information of all the File Systems
If the disk usage of all the file systems is required then use ‘-a’ option:
$ df -a Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 132239776 6210892 119311496 5% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys devpts 0 0 0 - /dev/pts tmpfs 4021876 0 4021876 0% /dev/shm none 0 0 0 - /proc/sys/fs/binfmt_misc /dev/sdb2 30969600 117740 29278696 1% /home/oracle /dev/sdc1 576310180 71232 546964104 1% /home/data
So we see that in the output, details of all the file systems and their memory usage is there.
2. Specify the Memory Block Size
If you see the output in point 1 above, the second column gives the memory of file system in memory blocks of 1k. df command provides an option through which we can change the size of memory block in the output. Use option -B for this:
$ df -B 100 Filesystem 100B-blocks Used Available Use% Mounted on /dev/sda1 1354135307 63599535 1221749720 5% / tmpfs 41184011 0 41184011 0% /dev/shm /dev/sdb2 317128704 1205658 299813848 1% /home/oracle /dev/sdc1 5901416244 729416 5600912425 1% /home/data
So you see that we specified a block size of 100 and in the output (second column) block size of 100 is displayed.
3. Print Human Readable Sizes
We are used to reading the memory in terms of gigabytes, megabytes, etc as its easy to read and remember. df command also provides an option ‘-h’ to print the memory statistics in human readable format.
Option -h stands for “human” readable format. As shown in the output below, G is used for gigabytes and M is used for megabytes.
$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 127G 6.0G 114G 5% / tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/sdb2 30G 115M 28G 1% /home/oracle /dev/sdc1 550G 70M 522G 1% /home/data
4. Display Grand Total in the Output
Till now we have seen that only disk usage statistics of individual file systems is produced. If we want to display a grand total of every column then we can use the ‘–total’ flag. Here is an example:
$ df -h --total Filesystem Size Used Avail Use% Mounted on /dev/sda1 127G 6.0G 114G 5% / tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/sdb2 30G 115M 28G 1% /home/oracle /dev/sdc1 550G 70M 522G 1% /home/data total 710G 6.2G 668G 1%
So we see that a new row ‘total’ at the end of the output was produced.
5. List Inodes (Instead of Block Usage)
Till now we have seen that df prints the second column as total memory blocks. If information in terms of inode is desired then df provides an option ‘-i’ for this.
$ df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda1 8396800 65397 8331403 1% / tmpfs 1005469 1 1005468 1% /dev/shm /dev/sdb2 1966560 2517 1964043 1% /home/oracle /dev/sdc1 36593664 11 36593653 1% /home/data
So we see that information in terms of inodes is displayed.
6. Print File System Type
If you wish to print the type of file system in the output, use option ‘-T’.
$ df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda1 ext4 132239776 6210892 119311496 5% / tmpfs tmpfs 4021876 0 4021876 0% /dev/shm /dev/sdb2 ext2 30969600 117740 29278696 1% /home/oracle /dev/sdc1 ext2 576310180 71232 546964104 1% /home/data
In the above output, we can see all the file systems along with their type is displayed. Apart from using df -T to identify file system, there are 4 other methods to identify the file system types.
7. Include/Exclude Certain File System Type
You can also display file systems that belongs to certain type. For example, the following command displays only ext2 file systems. types.
$ df -t ext2 Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdb2 30969600 117740 29278696 1% /home/oracle /dev/sdc1 576310180 71232 546964104 1% /home/data
You can also display file systems that doesn’t belongs to certain type. For example, the following command displays all other file systems except ext2. This is exactly opposite to the above -t option.
$ df -x ext2 Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 132239776 6210896 119311492 5% / tmpfs 4021876 0 4021876 0% /dev/shm
Comments on this entry are closed.
Nice info..
Hi,
Thanks a lot
–total is not available on old “df” command
good job. thanks. I appreciate it when you expand out the meaning of the options. For example “df -h” and you explain that -h is for “human readable”. A lot of times we have difficulty remembering the option because we don’t remember what it stands for. Expanding the option helps us remember. This is something to keep in mind for your future columns.
df .
df followed by a dot reports which file system cwd is currently.
Thanks for pointing out a couple of new flags to add to my df use. I wanted to add one of my top flags as well (-P) which forces POSIX compliant output and makes reading df output when using LVM much easier to read:
df -hP
thanx a lot…. its so helpful
Always useful !!! π
Thanks,
It’s usefull.
Thank you all for your valuable comments!!
df – h –total is not displaying, what is version of df ?
@anonymous
I am using version 7.4
Anonymous, is there a space in your command? Also, can you tell me what distro and df version (df –version) you are using?
Thanx…. really useful to every one.
HI Anonymous, its :
you have left one hyphen(-).kindly check there will be 2 hyphen coming before total…
df -h –total
You can’t use –total switch in RHEL/CentOS 4xx and RHEL/CentOS 5.xx.
I just tried , but you can definitely use in RHEL/CentOS 6.2.
( Which means you can’t use df’s switch “–total” in older version of coreutils-5.97-xxx . The core util found on CentOS 6.2 is coreutils-8.4-16.el6.x86_64. ).
Thanks a lot… It is very helpfull
If you want the output of df shown in a neat table use: df | column -t
To have all partitions sorted by percentage of used disk space (in increasing order) type:
df -Ph | sort -nk5
Options:
-n: sort by entire number not only the first digit, so 5% comes after say 1% and not 12%
-k5: sort using column 5 (in our case percentage of disk space used)
Hope that helps
Thank you very much for your realy valuable articles .
superb jobs done by thegeekstuff
Can anyone clarify why the df command does not show any output on my VPS (Centos 5.7)
Thanks, helped a lot π
Hi,
I would like to know about df little bit internal.
when we execute command `df` on CLI, from where it will read the information.
Hi,
The df -i command is not working in solaris. Please help.
Hi Ramesh,
This is regarding tmpfs query.Kindly find the below details and help on this .
we have server with 7 Gb and Tmpfs is 4 Gb. No process/application is using more memory but we are facing memory issue. And it is not a Db server
Questions :
1) In free -g we have only 3 gb free (buffer+caches is 2 gb and cache is 1 gb). and what about the reaming memory ?
2) configuring tmpfs is good or not in linux server (without DB (oracle) installed on it)
3) If we configured tmpfs ,it will directly took it from physical ram or not ? if yes means, then it will be shown as used in free command or not ?
Kindly help on this and find the below details from that server .
1) cat /etc/fstab->tmpfs /dev/shm tmpfs defaults 0 0
2) df -h β> tmpfs 3.9G 0 3.9G 0% /dev/shm
3) free -m
total used free shared buffers cached
Mem: 7873 7240 632 0 119 1640
-/+ buffers/cache: 5480 2392
Swap: 4095 0 4095
##free -g
total used free shared buffers cached
Mem: 7 7 0 0 0 1
-/+ buffers/cache: 5 2
Swap: 3 0 3
4) from top β
top β 21:01:04 up 332 days, 19 min, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 249 total, 2 running, 247 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.2%us, 0.3%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 8062532k total, 7415264k used, 647268k free, 122792k buffers
Swap: 4194296k total, 4k used, 4194292k free, 1679428k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
32746 UH00006 30 10 144m 7216 2328 S 0.0 0.1 1:53.21 pandora_agent
1917 root 20 0 245m 5404 884 S 0.0 0.1 1:26.54 rsyslogd
23397 root 20 0 169m 4120 2236 S 0.0 0.1 4:45.63 httpd
2413 cimsrvr 20 0 382m 3804 2088 S 0.0 0.0 2:51.21 cimservermain
21780 root 20 0 95824 3788 2864 S 0.0 0.0 0:00.14 sshd
2351 postfix 20 0 78972 3400 2468 S 0.0 0.0 1:21.00 qmgr
22873 postfix 20 0 78800 3244 2416 S 0.0 0.0 0:00.02 pickup
2344 root 20 0 78720 3200 2348 S 0.0 0.0 5:34.63 master
18650 apache 20 0 169m 3104 1160 S 0.0 0.0 0:00.00 httpd
5) Top memory usage
ps -A βsort -rss -o comm,pmem | head -n 11
COMMAND %MEM
pandora_agent 0.0
rsyslogd 0.0
httpd 0.0
cimservermain 0.0
sshd 0.0
qmgr 0.0
pickup 0.0
master 0.0
httpd 0.0
httpd 0.0
This is the sample servers , we have lots of servers like this .
Regards,
Arun J