CodeNewbie Community 🌱

Cover image for Managing Disk Space in Linux with the df Command
k1lgor
k1lgor

Posted on

Managing Disk Space in Linux with the df Command


Introduction

The df command is a useful tool for managing disk space on your Linux system. It displays information about the file system disk space usage, including the amount of free space, used space, and the percentage of space used. Here are some examples of using df command:

Show disk space usage in human-readable format

df -h
Enter fullscreen mode Exit fullscreen mode

Image 1

Show disk space usage for a specific file system

df -hT /dev/sda1
Enter fullscreen mode Exit fullscreen mode

Image 2

Show disk space usage for all file systems (including speudo file systems)

df -aTh
Enter fullscreen mode Exit fullscreen mode

Image 3

Show disk space usage for a specific file system and exclude file systems of a certain type

df -hT -x tmpfs /dev/sda1
Enter fullscreen mode Exit fullscreen mode

Image 4

Show disk space usage in bytes for all file systems (including empty file systems)

df -BT
Enter fullscreen mode Exit fullscreen mode

Image 5

Show disk space usage for a specific file system with inode information

df -i /dev/sda1
Enter fullscreen mode Exit fullscreen mode

Image 6

Show disk space usage with a specific output format

df --output=source,fstype,size,used,avail,pcent,target
Enter fullscreen mode Exit fullscreen mode

Image 7

Show disk space usage sorted by a specific column (ascending)

df -hT | sort -k 3
Enter fullscreen mode Exit fullscreen mode

Image 8

Show disk space usage sorted by a specific column (descending)

df -hT | sort -k 3 -r
Enter fullscreen mode Exit fullscreen mode

Image 9

Show disk space usage for all file systems and exclude the header line

df -hT | tail -n +2
Enter fullscreen mode Exit fullscreen mode

Image 10

Tips

  • Use the h option to display disk space usage in human-readable format (e.g., GB, MB)
  • Use the x option to exclude file systems of a certain type (e.g., tmpfs,devtmpfs)
  • Use the -output option to customize the output format of the command
  • Use the sort and tail commands to sort and filter the output as needed.

Conclusion

In summary, the df command is a powerful tool for managing disk space on your Linux system. With the various options available, you can easily view and analyze disk space usage for specific file systems and customize the output format.
Remember to use the available sorting and filtering commands to further manage and analyze the output.

Thank you for reading πŸ§‘β€πŸ’»

Stay tuned for more πŸš€

✌️ and logout


Buy Me A Coffee

Top comments (0)