|

$ in Linux: Check Free Disk Space with a Simple Command | Take Control of Your Storage

Share On

Introduction

Managing disk space is an essential task for any Linux user. Whether you are a system administrator or a regular user, it is crucial to keep track of your storage usage to prevent running out of space and ensure optimal performance. In this article, we will explore the ‘df’ command, a simple yet powerful tool that allows you to check the free disk space on your Linux system.

Why is it important to check free disk space in Linux?

Checking free disk space is important for several reasons. Firstly, it helps you monitor the overall health of your system. Running out of disk space can lead to system crashes, data corruption, and other issues. By regularly checking your disk space, you can identify potential problems and take appropriate actions before they escalate.

Secondly, checking free disk space allows you to plan for future storage needs. By knowing how much space is available, you can determine if you need to upgrade your storage or optimize your usage. This is particularly important for servers and systems that handle large amounts of data.

Lastly, checking free disk space helps you identify and remove unnecessary files and directories. Over time, your system can accumulate temporary files, log files, and other clutter that takes up valuable space. By identifying and removing these files, you can free up storage and improve system performance.

Using the ‘df’ command

The ‘df’ command is a versatile tool that provides detailed information about disk space usage on your Linux system. It displays the amount of used and available space on each mounted filesystem, along with other useful information such as the filesystem type and mount point.

1. Basic usage of the ‘df’ command

The basic usage of the ‘df’ command is simple. Open a terminal and type ‘df’ followed by the Enter key. This will display the disk space usage for all mounted filesystems on your system.

For example:

$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       10485760  524288   9961472   6% /
tmpfs             512000       0    512000   0% /dev/shm
/dev/sdb1       20971520 1048576  19922944   6% /mnt/data

In the output, the ‘1K-blocks’ column represents the total size of the filesystem in kilobytes, the ‘Used’ column represents the amount of space used, the ‘Available’ column represents the amount of space available, and the ‘Use%’ column represents the percentage of space used.

2. Using the ‘-h’ option for human-readable output

The ‘-h’ option can be used with the ‘df’ command to display the disk space usage in a more human-readable format. Instead of showing the size in kilobytes, it will display the size in a more understandable format, such as gigabytes or terabytes.

For example:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        10G  512M  9.5G   6% /
tmpfs           500M     0  500M   0% /dev/shm
/dev/sdb1        20G 1024M   19G   6% /mnt/data

The output now shows the size, used space, available space, and usage percentage in a more readable format.

3. Using the ‘-H’ option for decimal unit sizes

The ‘-H’ option is similar to the ‘-h’ option, but it uses decimal unit sizes instead of binary unit sizes. This means that instead of using powers of 1024 (e.g., kilobytes, megabytes, gigabytes), it uses powers of 1000 (e.g., kilobytes, megabytes, gigabytes).

For example:

$ df -H
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        11G  537M  9.9G   6% /
tmpfs           525M     0  525M   0% /dev/shm
/dev/sdb1        21G 1.1G   20G   6% /mnt/data

The output now shows the size, used space, available space, and usage percentage using decimal unit sizes.

4. Using the ‘-k’ option for output in kilobytes

The ‘-k’ option can be used to display the disk space usage in kilobytes. This is useful if you need to perform calculations or if you prefer to work with kilobytes instead of larger unit sizes.

For example:

$ df -k
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       10485760  524288   9961472   6% /
tmpfs             512000       0    512000   0% /dev/shm
/dev/sdb1       20971520 1048576  19922944   6% /mnt/data

The output now shows the size, used space, available space, and usage percentage in kilobytes.

5. Using the ‘-m’ option for output in megabytes

The ‘-m’ option can be used to display the disk space usage in megabytes. This is useful if you prefer to work with megabytes instead of larger unit sizes.

For example:

$ df -m
Filesystem     1M-blocks  Used Available Use% Mounted on
/dev/sda1           10240   512      9728   6% /
tmpfs                500      0       500   0% /dev/shm
/dev/sdb1           20480  1024     19456   6% /mnt/data

The output now shows the size, used space, available space, and usage percentage in megabytes.

6. Using the ‘-T’ option to display filesystem types

The ‘-T’ option can be used to display the filesystem type along with the disk space usage. This is useful if you want to know the type of each mounted filesystem.

For example:

$ df -T
Filesystem     Type     1K-blocks    Used Available Use% Mounted on
/dev/sda1      ext4      10485760  524288   9961472   6% /
tmpfs          tmpfs        512000       0    512000   0% /dev/shm
/dev/sdb1      ext4      20971520 1048576  19922944   6% /mnt/data

The output now includes an additional ‘Type’ column that shows the filesystem type for each mounted filesystem.

Checking free disk space for specific filesystem types

The ‘df’ command also allows you to check the free disk space for specific filesystem types. This can be useful if you want to focus on a particular type of filesystem or if you want to exclude certain filesystem types from the output.

7. Checking free disk space for ext4 filesystems

To check the free disk space for ext4 filesystems, you can use the ‘-t ext4’ option with the ‘df’ command.

For example:

$ df -t ext4
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       10485760  524288   9961472   6% /
/dev/sdb1       20971520 1048576  19922944   6% /mnt/data

The output now shows the disk space usage only for ext4 filesystems.

8. Checking free disk space for ext3 filesystems

To check the free disk space for ext3 filesystems, you can use the ‘-t ext3’ option with the ‘df’ command.

For example:

$ df -t ext3
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       10485760  524288   9961472   6% /

The output now shows the disk space usage only for ext3 filesystems.

9. Checking free disk space for ext2 filesystems

To check the free disk space for ext2 filesystems, you can use the ‘-t ext2’ option with the ‘df’ command.

For example:

$ df -t ext2
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       10485760  524288   9961472   6% /

The output now shows the disk space usage only for ext2 filesystems.

10. Checking free disk space for xfs filesystems

To check the free disk space for xfs filesystems, you can use the ‘-t xfs’ option with the ‘df’ command.

For example:

$ df -t xfs
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sdb1       20971520 1048576  19922944   6% /mnt/data

The output now shows the disk space usage only for xfs filesystems.

11. Checking free disk space for btrfs filesystems

To check the free disk space for btrfs filesystems, you can use the ‘-t btrfs’ option with the ‘df’ command.

For example:

$ df -t btrfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for btrfs filesystems.

12. Checking free disk space for vfat filesystems

To check the free disk space for vfat filesystems, you can use the ‘-t vfat’ option with the ‘df’ command.

For example:

$ df -t vfat
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for vfat filesystems.

13. Checking free disk space for ntfs filesystems

To check the free disk space for ntfs filesystems, you can use the ‘-t ntfs’ option with the ‘df’ command.

For example:

$ df -t ntfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for ntfs filesystems.

14. Checking free disk space for nfs filesystems

To check the free disk space for nfs filesystems, you can use the ‘-t nfs’ option with the ‘df’ command.

For example:

$ df -t nfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for nfs filesystems.

15. Checking free disk space for cifs filesystems

To check the free disk space for cifs filesystems, you can use the ‘-t cifs’ option with the ‘df’ command.

For example:

$ df -t cifs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for cifs filesystems.

16. Checking free disk space for tmpfs filesystems

To check the free disk space for tmpfs filesystems, you can use the ‘-t tmpfs’ option with the ‘df’ command.

For example:

$ df -t tmpfs
Filesystem     1K-blocks    Used Available Use% Mounted on
tmpfs             512000       0    512000   0% /dev/shm

The output now shows the disk space usage only for tmpfs filesystems.

17. Checking free disk space for ramfs filesystems

To check the free disk space for ramfs filesystems, you can use the ‘-t ramfs’ option with the ‘df’ command.

For example:

$ df -t ramfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for ramfs filesystems.

18. Checking free disk space for iso9660 filesystems

To check the free disk space for iso9660 filesystems, you can use the ‘-t iso9660’ option with the ‘df’ command.

For example:

$ df -t iso9660
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for iso9660 filesystems.

19. Checking free disk space for udf filesystems

To check the free disk space for udf filesystems, you can use the ‘-t udf’ option with the ‘df’ command.

For example:

$ df -t udf
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for udf filesystems.

20. Checking free disk space for squashfs filesystems

To check the free disk space for squashfs filesystems, you can use the ‘-t squashfs’ option with the ‘df’ command.

For example:

$ df -t squashfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for squashfs filesystems.

21. Checking free disk space for autofs filesystems

To check the free disk space for autofs filesystems, you can use the ‘-t autofs’ option with the ‘df’ command.

For example:

$ df -t autofs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for autofs filesystems.

22. Checking free disk space for devtmpfs filesystems

To check the free disk space for devtmpfs filesystems, you can use the ‘-t devtmpfs’ option with the ‘df’ command.

For example:

$ df -t devtmpfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for devtmpfs filesystems.

23. Checking free disk space for sysfs filesystems

To check the free disk space for sysfs filesystems, you can use the ‘-t sysfs’ option with the ‘df’ command.

For example:

$ df -t sysfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for sysfs filesystems.

24. Checking free disk space for proc filesystems

To check the free disk space for proc filesystems, you can use the ‘-t proc’ option with the ‘df’ command.

For example:

$ df -t proc
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for proc filesystems.

25. Checking free disk space for debugfs filesystems

To check the free disk space for debugfs filesystems, you can use the ‘-t debugfs’ option with the ‘df’ command.

For example:

$ df -t debugfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for debugfs filesystems.

26. Checking free disk space for securityfs filesystems

To check the free disk space for securityfs filesystems, you can use the ‘-t securityfs’ option with the ‘df’ command.

For example:

$ df -t securityfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for securityfs filesystems.

27. Checking free disk space for fuseblk filesystems

To check the free disk space for fuseblk filesystems, you can use the ‘-t fuseblk’ option with the ‘df’ command.

For example:

$ df -t fuseblk
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for fuseblk filesystems.

28. Checking free disk space for fuse filesystems

To check the free disk space for fuse filesystems, you can use the ‘-t fuse’ option with the ‘df’ command.

For example:

$ df -t fuse
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for fuse filesystems.

29. Checking free disk space for fuse.gvfsd-fuse filesystems

To check the free disk space for fuse.gvfsd-fuse filesystems, you can use the ‘-t fuse.gvfsd-fuse’ option with the ‘df’ command.

For example:

$ df -t fuse.gvfsd-fuse
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for fuse.gvfsd-fuse filesystems.

30. Checking free disk space for fusectl filesystems

To check the free disk space for fusectl filesystems, you can use the ‘-t fusectl’ option with the ‘df’ command.

For example:

$ df -t fusectl
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for fusectl filesystems.

31. Checking free disk space for pstore filesystems

To check the free disk space for pstore filesystems, you can use the ‘-t pstore’ option with the ‘df’ command.

For example:

$ df -t pstore
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for pstore filesystems.

32. Checking free disk space for mqueue filesystems

To check the free disk space for mqueue filesystems, you can use the ‘-t mqueue’ option with the ‘df’ command.

For example:

$ df -t mqueue
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for mqueue filesystems.

33. Checking free disk space for hugetlbfs filesystems

To check the free disk space for hugetlbfs filesystems, you can use the ‘-t hugetlbfs’ option with the ‘df’ command.

For example:

$ df -t hugetlbfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for hugetlbfs filesystems.

34. Checking free disk space for cgroup filesystems

To check the free disk space for cgroup filesystems, you can use the ‘-t cgroup’ option with the ‘df’ command.

For example:

$ df -t cgroup
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for cgroup filesystems.

35. Checking free disk space for cgroup2 filesystems

To check the free disk space for cgroup2 filesystems, you can use the ‘-t cgroup2’ option with the ‘df’ command.

For example:

$ df -t cgroup2
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for cgroup2 filesystems.

36. Checking free disk space for configfs filesystems

To check the free disk space for configfs filesystems, you can use the ‘-t configfs’ option with the ‘df’ command.

For example:

$ df -t configfs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for configfs filesystems.

37. Checking free disk space for binfmt_misc filesystems

To check the free disk space for binfmt_misc filesystems, you can use the ‘-t binfmt_misc’ option with the ‘df’ command.

For example:

$ df -t binfmt_misc
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for binfmt_misc filesystems.

38. Checking free disk space for autofs4 filesystems

To check the free disk space for autofs4 filesystems, you can use the ‘-t autofs4’ option with the ‘df’ command.

For example:

$ df -t autofs4
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for autofs4 filesystems.

39. Checking free disk space for rpc_pipefs filesystems

To check the free disk space for rpc_pipefs filesystems, you can use the ‘-t rpc_pipefs’ option with the ‘df’ command.

For example:

$ df -t rpc_pipefs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for rpc_pipefs filesystems.

40. Checking free disk space for nfsd filesystems

To check the free disk space for nfsd filesystems, you can use the ‘-t nfsd’ option with the ‘df’ command.

For example:

$ df -t nfsd
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for nfsd filesystems.

41. Checking free disk space for nfs4 filesystems

To check the free disk space for nfs4 filesystems, you can use the ‘-t nfs4’ option with the ‘df’ command.

For example:

$ df -t nfs4
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for nfs4 filesystems.

42. Checking free disk space for nfsd4 filesystems

To check the free disk space for nfsd4 filesystems, you can use the ‘-t nfsd4’ option with the ‘df’ command.

For example:

$ df -t nfsd4
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for nfsd4 filesystems.

43. Checking free disk space for rpc_pipefs filesystems

To check the free disk space for rpc_pipefs filesystems, you can use the ‘-t rpc_pipefs’ option with the ‘df’ command.

For example:

$ df -t rpc_pipefs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for rpc_pipefs filesystems.

44. Checking free disk space for rpc_pipefs filesystems

To check the free disk space for rpc_pipefs filesystems, you can use the ‘-t rpc_pipefs’ option with the ‘df’ command.

For example:

$ df -t rpc_pipefs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for rpc_pipefs filesystems.

45. Checking free disk space for rpc_pipefs filesystems

To check the free disk space for rpc_pipefs filesystems, you can use the ‘-t rpc_pipefs’ option with the ‘df’ command.

For example:

$ df -t rpc_pipefs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for rpc_pipefs filesystems.

46. Checking free disk space for rpc_pipefs filesystems

To check the free disk space for rpc_pipefs filesystems, you can use the ‘-t rpc_pipefs’ option with the ‘df’ command.

For example:

$ df -t rpc_pipefs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for rpc_pipefs filesystems.

47. Checking free disk space for rpc_pipefs filesystems

To check the free disk space for rpc_pipefs filesystems, you can use the ‘-t rpc_pipefs’ option with the ‘df’ command.

For example:

$ df -t rpc_pipefs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for rpc_pipefs filesystems.

48. Checking free disk space for rpc_pipefs filesystems

To check the free disk space for rpc_pipefs filesystems, you can use the ‘-t rpc_pipefs’ option with the ‘df’ command.

For example:

$ df -t rpc_pipefs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for rpc_pipefs filesystems.

49. Checking free disk space for rpc_pipefs filesystems

To check the free disk space for rpc_pipefs filesystems, you can use the ‘-t rpc_pipefs’ option with the ‘df’ command.

For example:

$ df -t rpc_pipefs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for rpc_pipefs filesystems.

50. Checking free disk space for rpc_pipefs filesystems

To check the free disk space for rpc_pipefs filesystems, you can use the ‘-t rpc_pipefs’ option with the ‘df’ command.

For example:

$ df -t rpc_pipefs
Filesystem     1K-blocks    Used Available Use% Mounted on

The output now shows the disk space usage only for rpc_pipefs filesystems.

In conclusion, the ‘df’ command is a powerful tool that allows you to check the free disk space on your Linux system. By using various options, you can customize the output to suit your needs, such as displaying the disk space usage in human-readable format, checking specific filesystem types, or using different unit sizes. Regularly checking your disk space is essential for maintaining the health and performance of your system, as well as planning for future storage needs. Take control of your storage and ensure you have enough space for your data.

FAQs

Q: Can I use the ‘df’ command to check the disk space on remote systems?

A: Yes, you can use the ‘df’ command with the ‘-h’ option to check the disk space on remote systems. Simply specify the hostname or IP address of the remote system as an argument to the ‘df’ command. For example, ‘df -h user@remotehost’.

Q: How can I sort the output of the ‘df’ command by disk usage?

A: You can use the ‘df’ command with the ‘–sort’ option to sort the output by disk usage. For example, ‘df –sort=used’ will display the filesystems with the highest disk usage at the top of the output.

Q: Is there a way to exclude certain filesystems from the output of the ‘df’ command?

A: Yes, you can use the ‘df’ command with the ‘-x’ option to exclude certain filesystem types from the output. For example, ‘df -x tmpfs’ will exclude tmpfs filesystems from the output.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *