Linux / Unix – Checking Free Disk Space
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | None |
Time | 1m |
(a) df command : Report file system disk space usage.
(b) du command : Estimate file space usage.
df command examples to check free disk space
Type df -h or df -k to list free disk space:
$ df -h
OR
$ df -k
Sample outputs that show disk space utilization:
The df utility displays statistics about the amount of free disk space on the specified file system or on the file system of which file is a part. Values are displayed in 512-byte per block counts. The -H option is called as “Human-readable” output. It use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to four or fewer using base 10 for sizes i.e. you see 30G (30 Gigabyte).
How to check free disk space in Linux
To see the file system’s complete disk usage pass the -a option:
df -a
Find out disk usage and filesystem type by passing the -T option:
df -T
Want to get used and free inodes information on Linux? Try:
df -i
du command examples for checking free and used disk space
The du command shows how much space one ore more files or directories is using, enter:
$ du -sh
Sample outputs:
Fig.01: Unix df and du command outputs from my FreeBSD server
Say hello to ncdu command
ncdu (NCurses Disk Usage) is a curses-based version of the well-known ‘du’, and provides a fast way to see what directories are using your disk space. One can install with the following apt command/apt-get command:
sudo apt install ncdu
For RHEL/CentOS, first enable EPEL repo (see CentOS 8 turn on EPEL repo and RHEL 8 enable epel repo) and type the following yum command:
sudo yum install ncdu
Now just type:
ncdu
ncdu [dir] ncdu /etc/
GUI program
Above programs are good if GUI is not installed or you are working with remote system over the ssh based session. Linux and UNIX-like oses comes with KDE and Gnome desktop system. You will find Free Disk Space Applet located under GUI menus. Here is a sample from Fedora Linux version 22 system:
Conclusion
You learned how to keep track of disk utilization, and disk space with various Linux and Unix commands.
Check free disk space for current partition in bash
I am writing an installer in bash. The user will go to the target directory and runs the install script, so the first action should be to check that there is enough space. I know that df will report all file systems, but I was wondering if there was a way to get the free space just for the partition that the target directory is on.
Edit — the answer I came up with
Slightly odd because df seems to format its output to fit the terminal, so with a long mount point name the output is shifted down a line
7 Answers 7
for the current directory.
if you want to check a specific directory.
You might also want to check out the stat(1) command if your system has it. You can specify output formats to make it easier for your script to parse. Here’s a little example:
- df command : Report file system disk space usage
- du command : Estimate file space usage
Type df -h or df -k to list free disk space:
du shows how much space one or more files or directories is using:
The -s option summarizes the space a directory is using and -h option provides Human-readable output.
I think this should be a comment or an edit to ThinkingMedia’s answer on this very question (Check free disk space for current partition in bash), but I am not allowed to comment (not enough rep) and my edit has been rejected (reason: «this should be a comment or an answer»). So please, powers of the SO universe, don’t damn me for repeating and fixing someone else’s «answer». But someone on the internet was wrong!™ and they wouldn’t let me fix it.
has a substantial flaw: Yes, it will output 50G free as 50 — but it will also output 5.0M free as 50 or 3.4G free as 34 or 15K free as 15.
To create a script with the purpose of checking for a certain amount of free disk space you have to know the unit you’re checking against. Remove it (as sed does in the example above) the numbers don’t make sense anymore.
If you actually want it to work, you will have to do something like:
Also for an installer to df -k $INSTALL_TARGET_DIRECTORY might make more sense than df -k «$PWD» . Finally, please note that the —output flag is not available in every version of df / linux.
12 Useful “df” Commands to Check Disk Space in Linux
On the internet you will find plenty of tools for checking disk space utilization in Linux. However, Linux has a strong built-in utility called ‘df‘. The ‘df‘ command stands for “disk filesystem“, it is used to get a full summary of available and used disk space usage of the file system on Linux system.
Using ‘ -h ‘ parameter with (df -h) will show the file system disk space statistics in “human readable” format, means it gives the details in bytes, megabytes, and gigabyte.
Useful df Command Examples
This article explains a way to get the full information of Linux disk space usage with the help of ‘df‘ command with their practical examples. So, you could better understand the usage of df command in Linux.
1. Check File System Disk Space Usage
The “df” command displays the information of device name, total blocks, total disk space, used disk space, available disk space and mount points on a file system.
2. Display Information of all File System Disk Space Usage
The same as above, but it also displays information of dummy file systems along with all the file system disk usage and their memory utilization.
3. Show Disk Space Usage in Human Readable Format
Have you noticed that above commands displays information in bytes, which is not readable at all, because we are in a habit of reading the sizes in megabytes, gigabytes etc. as it makes very easy to understand and remember.
The df command provides an option to display sizes in Human Readable formats by using ‘-h’ (prints the results in human readable format (e.g., 1K 2M 3G)).
4. Display Information of /home File System
To see the information of only device /home file system in human readable format use the following command.
5. Display Information of File System in Bytes
To display all file system information and usage in 1024-byte blocks, use the option ‘ -k ‘ (e.g. —block-size=1K ) as follows.
6. Display Information of File System in MB
To display information of all file system usage in MB (Mega Byte) use the option as ‘ -m ‘.
7. Display Information of File System in GB
To display information of all file system statistics in GB (Gigabyte) use the option as ‘df -h‘.
8. Display File System Inodes
Using ‘ -i ‘ switch will display the information of number of used inodes and their percentage for the file system.
9. Display File System Type
If you notice all the above commands output, you will see there is no Linux file system type mentioned in the results. To check the file system type of your system use the option ‘ T ‘. It will display file system type along with other information.
10. Include Certain File System Type
If you want to display certain file system type use the ‘ -t ‘ option. For example, the following command will only display ext3 file system.
11. Exclude Certain File System Type
If you want to display file system type that doesn’t belongs to ext3 type use the option as ‘ -x ‘. For example, the following command will only display other file systems types other than ext3.
12. Display Information of df Command.
Using ‘—help ‘ switch will display a list of available option that is used with df command.
Read Also :
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.