{"id":1750,"date":"2022-02-13T00:10:31","date_gmt":"2022-02-12T18:40:31","guid":{"rendered":"https:\/\/smarttech101.com\/?p=1750"},"modified":"2023-09-11T08:06:53","modified_gmt":"2023-09-11T02:36:53","slug":"df-command-in-linux","status":"publish","type":"post","link":"https:\/\/smarttech101.com\/df-command-in-linux\/","title":{"rendered":"The df command in Linux with Examples"},"content":{"rendered":"\n
We use the df command to find the type of file systems, free and used space on them, where these file systems are mounted, among others. <\/p>\n\n\n\n
The df command stands for disk free. That means it is mainly used to know the free space. <\/p>\n\n\n\n
By default, if no argument is given, the df command shows the information about all the mounted file system. For example:<\/p>\n\n\n\n
~$ df\n\nOutput: \n \nFilesystem 1K-blocks Used Available Use% Mounted on\ndev 3452072 0 3452072 0% \/dev\nrun 3493196 1316 3491880 1% \/run\n\/dev\/nvme0n1p5 163181380 78961860 75857536 52% \/\ntmpfs 3493196 30600 3462596 1% \/dev\/shm\n\/dev\/nvme1n1p1 479596204 278631560 176528984 62% \/mnt\/crucial\ntmpfs 3493200 268 3492932 1% \/tmp\ntmpfs 698636 1644 696992 1% \/run\/user\/1000\n<\/code><\/pre>\n\n\n\nThe ‘1K-blocks’ column shows the total size in 1K blocks. The columns ‘Used’ and ‘Available’ show used and available space on the file system. ‘Use%’ shows the percentage of space that has been filled up. The Mounted on<\/code> column shows where the file system is mounted.<\/p>\n\n\n\nWhen you use the df command with a file(s) or folder(s) as its argument, it will give you the information only about those file systems on which the file(s)\/folder(s) are located. For example, the directory \/mnt\/crucial\/backup is located on the file system \/dev\/nvme1n1p1 and hence all other file systems are not outputted. <\/p>\n\n\n\n
~$ df \/mnt\/crucial\/backup\n\nOutput:\n\nFilesystem 1K-blocks Used Available Use% Mounted on\n\/dev\/nvme1n1p1 479596204 278631560 176528984 62% \/mnt\/crucial<\/code><\/pre>\n\n\n\nHow to get the file system space in 1m-blocks using df in Linux<\/h2>\n\n\n\n
To print the columns in multiples of 1024 (i.e. 1M-blocks) instead of the default 1K-blocks, use the flag -m.<\/p>\n\n\n\n
~$ df -m\n\nOutput:\n\nFilesystem 1M-blocks Used Available Use% Mounted on\ndev 3372 0 3372 0% \/dev\nrun 3412 2 3411 1% \/run\n\/dev\/nvme0n1p5 159357 77112 74080 52% \/\ntmpfs 3412 26 3386 1% \/dev\/shm\n\/dev\/nvme1n1p1 468356 272102 172392 62% \/mnt\/crucial\ntmpfs 3412 1 3412 1% \/tmp\ntmpfs 683 2 681 1% \/run\/user\/1000<\/code><\/pre>\n\n\n\nHow to get the file system space in human readable form using df in Linux<\/h2>\n\n\n\n
You need to use --human-readable<\/code> or -h<\/code>. This way, df will automatically choose the appropriate unit from the K, M, and G.<\/p>\n\n\n\nBy the way, I prefer the GNU syntax (i.e. --human-readable<\/code>) over the Unix syntax (i.e. -h) because it is easier to remember and stays in the mind for a longer time.<\/p>\n\n\n\n~$ df --human-readable\n\nOutput:\n \nFilesystem Size Used Avail Use% Mounted on\ndev 3.3G 0 3.3G 0% \/dev\nrun 3.4G 1.3M 3.4G 1% \/run\n\/dev\/nvme0n1p5 156G 76G 73G 52% \/\ntmpfs 3.4G 15M 3.4G 1% \/dev\/shm\n\/dev\/nvme1n1p1 458G 266G 169G 62% \/mnt\/crucial\ntmpfs 3.4G 268K 3.4G 1% \/tmp\ntmpfs 683M 908K 682M 1% \/run\/user\/1000<\/code><\/pre>\n\n\n\nThe above output is somewhat similar to that in gnome-system-monitor<\/strong>. So, if you prefer GUI apps, you can use that as well.<\/p>\n\n\n\n
Fig: using gnome-system-monitor to find the space available on your file systems<\/figcaption><\/figure>\n\n\n\nThe above units (K, M, and G) are multiples of 1024. To make them multiple of 1000 instead, use the flag --si<\/code> or -H<\/code>.<\/p>\n\n\n\n[ajay@lenovo ~]$ df --si\n\nOutput:\n\nFilesystem Size Used Avail Use% Mounted on\ndev 3.6G 0 3.6G 0% \/dev\nrun 3.6G 1.4M 3.6G 1% \/run\n\/dev\/nvme0n1p5 168G 84G 76G 53% \/\ntmpfs 3.6G 7.4M 3.6G 1% \/dev\/shm\n\/dev\/nvme1n1p1 492G 288G 179G 62% \/mnt\/crucial\ntmpfs 3.6G 25k 3.6G 1% \/tmp\ntmpfs 716M 107k 716M 1% \/run\/user\/1000<\/code><\/pre>\n\n\n\nHow to display all file systems<\/h2>\n\n\n\n
To display all file systems, you need to use --all<\/code> or -a<\/code> flag. Now, all the filesystems including pseudo, duplicate, inaccessible ones will be printed out. <\/p>\n\n\n\n~$ df --all\n\nOutput:\n\nFilesystem 1K-blocks Used Available Use% Mounted on\nproc 0 0 0 - \/proc\nsys 0 0 0 - \/sys\ndev 3452072 0 3452072 0% \/dev\nrun 3493196 1316 3491880 1% \/run\nefivarfs 0 0 0 - \/sys\/firmware\/efi\/efivars\n\/dev\/nvme0n1p5 163181380 78961808 75857588 52% \/\nsecurityfs 0 0 0 - \/sys\/kernel\/security\ntmpfs 3493196 26500 3466696 1% \/dev\/shm\ndevpts 0 0 0 - \/dev\/pts\ncgroup2 0 0 0 - \/sys\/fs\/cgroup\npstore 0 0 0 - \/sys\/fs\/pstore\nbpf 0 0 0 - \/sys\/fs\/bpf\nsystemd-1 0 0 0 - \/proc\/sys\/fs\/binfmt_misc\nmqueue 0 0 0 - \/dev\/mqueue\nhugetlbfs 0 0 0 - \/dev\/hugepages\ndebugfs 0 0 0 - \/sys\/kernel\/debug\ntracefs 0 0 0 - \/sys\/kernel\/tracing\nconfigfs 0 0 0 - \/sys\/kernel\/config\nfusectl 0 0 0 - \/sys\/fs\/fuse\/connections\n\/dev\/nvme1n1p1 479596204 278631560 176528984 62% \/mnt\/crucial\ntmpfs 3493200 268 3492932 1% \/tmp\ntmpfs 698636 1344 697292 1% \/run\/user\/1000\ngvfsd-fuse 0 0 0 - \/run\/user\/1000\/gvfs\n<\/code><\/pre>\n\n\n\nHow to know the file system type in Linux using df<\/h2>\n\n\n\n
To know whether the file system is mounted as ext4, NTFS, etc. you need to use --print-type<\/code> or -T<\/code>. Consequently, an extra column ‘Type’ will be printed out as well.<\/p>\n\n\n\n~$ df --print-type\n\nOutput:\n\nFilesystem Type 1K-blocks Used Available Use% Mounted on\ndev devtmpfs 3452072 0 3452072 0% \/dev\nrun tmpfs 3493196 1316 3491880 1% \/run\n\/dev\/nvme0n1p5 ext4 163181380 78961828 75857568 52% \/\ntmpfs tmpfs 3493196 26500 3466696 1% \/dev\/shm\n\/dev\/nvme1n1p1 ext4 479596204 278631560 176528984 62% \/mnt\/crucial\ntmpfs tmpfs 3493200 268 3492932 1% \/tmp\ntmpfs tmpfs 698636 1464 697172 1% \/run\/user\/1000<\/code><\/pre>\n\n\n\nHow to print only a certain type of file system in the df command<\/h2>\n\n\n\n
For this, you need to use --type<\/code> or -t<\/code> flag. <\/p>\n\n\n\nFor example, in order to print only the ext4 type of file system, we will use the following command:<\/p>\n\n\n\n
~$ df --type=ext4 \n\nOutput:\n\nFilesystem 1K-blocks Used Available Use% Mounted on\n\/dev\/nvme0n1p5 163181380 78961828 75857568 52% \/\n\/dev\/nvme1n1p1 479596204 278631560 176528984 62% \/mnt\/crucial\n<\/code><\/pre>\n\n\n\nHow to exclude a certain type of file system from the df command<\/h2>\n\n\n\n
Use --exclude-type<\/code> or -x <\/code> to exclude unwanted file systems.<\/p>\n\n\n\nFor example, to exclude, the ext4 file system, we use the following command:<\/p>\n\n\n\n
~$ df --exclude-type=ext4\n\nOutput:\n\nFilesystem 1K-blocks Used Available Use% Mounted on\ndev 3452072 0 3452072 0% \/dev\nrun 3493196 1316 3491880 1% \/run\ntmpfs 3493196 26500 3466696 1% \/dev\/shm\ntmpfs 3493200 268 3492932 1% \/tmp\ntmpfs 698636 1584 697052 1% \/run\/user\/1000<\/code><\/pre>\n\n\n\nHow to get only the desired columns in the df command<\/h2>\n\n\n\n
The above commands give a lot of columns which are not good if you are writing the scripts such as those for i3blocks, dwmblocks, etc. To get only the limited set of columns (called “fields”), use the flag --output<\/code>.<\/p>\n\n\n\n~$ df --output=field1,field2,...<\/code><\/pre>\n\n\n\nValid field names are:
‘source’ (source of the mount point, ex – \/dev\/sda1),
‘fstype’ (file system type, ex – ext4),
‘itotal’ (total number of inodes),
‘iused’ (number of used inodes),
‘iavail’ (number of available inodes),
‘ipcent’ (percentage of inodes which have been used),
‘size’ (total size),
‘used’ (used space),
‘avail’ (available space),
‘pcent’ (used percentage),
‘file’ (file name if specified on the command line, ex – for the example shown below, it is \/mnt\/crucial), and
‘target’ (mount location).<\/p>\n\n\n\n
For example, to get only the space available on the SSD, mounted at \/mnt\/crucial\/, I use the following command in my i3blocks:<\/p>\n\n\n\n
[ajay@lenovo ~]$ df --output=size \/mnt\/crucial\n\nOutput:\n\n1K-blocks\n479596204<\/code><\/pre>\n\n\n\nAnother Example:<\/p>\n\n\n\n
[ajay@lenovo ~]$ df --output=fstype,size,target\n\nOutput:\n\nType 1K-blocks Mounted on\ndevtmpfs 3452072 \/dev\ntmpfs 3493196 \/run\next4 163181380 \/\ntmpfs 3493196 \/dev\/shm\next4 479596204 \/mnt\/crucial\ntmpfs 3493200 \/tmp\ntmpfs 698636 \/run\/user\/1000<\/code><\/pre>\n\n\n\nHow to limit listing to local file systems<\/h2>\n\n\n\n
Syntax:<\/p>\n\n\n\n
~$ df --local<\/code><\/pre>\n\n\n\nWrapping up<\/h2>\n\n\n\n