Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
The df
command in Linux (short for "disk free") is a utility used to display the amount of disk space used and available on file systems. This tutorial will cover how to use the df
command effectively, along with various options and examples.
Basic usage of the df
command:
To display disk space usage for all mounted file systems, simply run the df
command without any options:
df
This will show output similar to the following:
Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 10238440 3716476 6014616 39% / tmpfs 515324 92 515232 1% /run /dev/sdb1 20479928 3340292 16185200 18% /mnt/data
The output includes the file system, size, used and available space, usage percentage, and mount point.
Displaying disk space usage in human-readable format:
To display disk space usage in a more human-readable format (using kilobytes, megabytes, or gigabytes), use the -h
or --human-readable
option:
df -h
This will show output similar to the following:
Filesystem Size Used Avail Use% Mounted on /dev/sda1 9.8G 3.6G 5.8G 39% / tmpfs 503M 92K 503M 1% /run /dev/sdb1 20G 3.2G 15G 18% /mnt/data
Displaying disk space usage for specific file systems:
To display disk space usage for specific file systems, pass the desired file system or mount point as an argument:
df /dev/sda1
This will show the disk space usage only for the specified file system.
Displaying disk space usage in a specific unit:
To display disk space usage in a specific unit (e.g., megabytes or gigabytes), use the --block-size
option:
df --block-size=M
This command will display disk space usage in megabytes. You can replace M
with K
for kilobytes or G
for gigabytes.
Displaying the file system type:
To display the file system type along with disk space usage, use the -T
or --print-type
option:
df -Th
This will show output similar to the following:
Filesystem Type Size Used Avail Use% Mounted on /dev/sda1 ext4 9.8G 3.6G 5.8G 39% / tmpfs tmpfs 503M 92K 503M 1% /run /dev/sdb1 ext4 20G 3.2G 15G 18% /mnt/data
By following this tutorial, you should now have a good understanding of how to use the df
command in Linux to display disk space usage for file systems. The df
command is a helpful tool for monitoring disk usage and managing storage resources effectively.
How to use df command in Linux:
The df
command in Linux is used to display disk space usage information. A basic usage example is:
df
This command shows information about mounted filesystems along with their sizes, used space, and available space.
Checking disk space usage with df: To check disk space usage, use:
df -h
The -h
option displays sizes in a human-readable format (e.g., KB, MB, GB).
Displaying disk space in human-readable format with df:
The -h
option is used to display disk space in a human-readable format:
df -h
This makes the output easier to read by using units like KB, MB, and GB.
Showing specific file system usage using df: To display information about a specific filesystem, specify the mount point:
df -h /path/to/mount/point
Replace /path/to/mount/point
with the actual mount point.
Monitoring disk space trends with df:
To monitor disk space trends over time, you can use tools like watch
to update the df
output periodically:
watch -n 5 df -h
This updates the disk space information every 5 seconds.
Excluding certain file systems from df output:
To exclude specific filesystems from the df
output, you can use the -x
option:
df -x tmpfs -h
This excludes tmpfs
filesystems from the output.
Checking available inodes with df in Linux: To check available inodes (index nodes) along with disk space:
df -i
This provides information on used and available inodes.
Automating disk space checks with df and cron: To automate disk space checks, you can create a cron job:
0 * * * * df -h > /path/to/logfile.log
This example runs the df
command every hour and appends the output to a log file.
Troubleshooting low disk space issues using df: If you encounter low disk space, identify large directories with:
du -h --max-depth=1 /
This helps troubleshoot and locate where disk space is being consumed.