The df command is used to find the amount of disk space used and available on different partitions and file systems. The simplest example of df command is just typing df on console with out any arguments and it will show you the space used and available on all currently mounted file systems of all types e.g NFS, ext3 and both local and remote. Alternatively you can ask df command to print the size and space available and used for a particular partition. Normally the disk space is printed in units of 1024 bytes, but this can be overridden. I commonly use df -h option to print the size and disk usage in human readable format e.g. G for giga bytes, M for mega bytes and so on.
In the past, I have shared example of many common Linux commands like find, grep, netstat, scp, curl, and lsof command and in this article, I will share 5 examples of how to use df command effectively in Linux command line.
5 df command usages every Programmer should learn
Without wasting anymore of your time, here are common df command options and examples which I believer not just programmers and developers but also every Linux user should learn. It's one of the essential Linux commands and knowing these usage will be quite useful in long run.
1. how to find how much space left in the partition
If you simply type df -h and give current directory like shown in following command then it
$ df -h .
will give you size of current partition and how much is filled and how much space is left as shown in below output. You can see that the /dev/root partition has 4.9G of space, out of those 2.3G is used and 2.6G is available.
This is also my go to command because most o the time you don't know the partition name and you are just interested in the current partition.
2. how to find size of all patriations
Let's say you don't want to know size of current partition but some other one which is shared between teams. Now, you don't remember the partition name but you know that it is mounted with your host. In this case, you can simply execute the following df command to get size of all partitions.
$ df -h
I hope you recognize the partition when you see in the output though. In previous command only usage of current partition was present but in this example you can see the disk usage detail of every single partition mounted on the host, including NFS
Once again, the -h option is to print size of partitions in human readable format e.g. G for gigabytes and M for Mega bytes. If you need size in 1K block, you can simply execute df command without -h option.
3. How to find size of a particular partition in Linux?
If you know the partition name and you are interested on either size of the partition or how much full or empty it is, you can simply execute the following df command to find the size or space left in a particular partition
$ df -h /opt/run
The above command will print file system, size, and usage details for partition /opt/run in the current host.
Here is an example of this command
You can see that when we passed /dev mount point then it print the size of devtmpfs file system. The key here is to pass the mount point, (see the mounted on column in above output) and not the name of partition.
4. Print size of local file systems only
When you print size of all partitions using df command it print sizes for both local and remote file systems. If you instead, just interested on size of location file systems then you can use the following df command:
$ df -l
The -l option is for printing usage detail of only local file systems.
5. How to print type of the file system
If you want to know which type of file system you are currently on, you can use the df -T to print the type of file systems. Some of the common types are "nfs", which is for NFS file system i.e. one mounted over a network from another machine.
Others are ufs, efs, ext3 which are mostly used for local file systems, a file system on a locally-mounted hard disk. Rarely you will see something like hsfs or cdfs which stands for a file system on a CD-ROM drive.
$ df -T
output
In this output you can see that one file system is 9p while other is local. If you are interested on the type of your current file system them just execute following command
$ df -hT .
This will print the type of your current file system or partition.
That's all about essential df command examples in Linux and UNIX. It is one of the essential command for any Linux user and very useful to check the disk usage. You often find yourself using "df" and "du" command in tendon to check how much space left in a file-system, partition or in a given directory.
Other Linux command articles you may like
Thanks for reading this article so far. If you find these df command examples useful, then please share it with your friends and colleagues. If you have any questions or feedback, then please drop a note.
P. S. - If you want to improve your Linux command skills, then I also suggest you look at these best online Linux courses from Udemy and Coursera. It's a great course for everyone, and you will definitely learn some useful tips to work better on Linux.
- 10 Example of lsof command in Linux
- 5 Courses to Learn Shell Scripting for Developers
- 10 Tips to improve your speed in Linux command lines
- 10 Linux command option every developer should learn
- 10 Courses to learn Linux command line for beginners
- 10 Examples of cURL command in Linux
- How to send email with attachment from Linux terminal?
- 10 Examples of chmod command in UNIX
- 6 Free Courses to learn Bash Scripting
- 5 Free Courses to learn Linux concepts for Beginners
- 10 Books to learn Linux command line in-depth
- 10 Basic Networking Command Every Linux User Should Know
- 10 Courses to learn DevOps for Experienced Developers
Thanks for reading this article so far. If you find these df command examples useful, then please share it with your friends and colleagues. If you have any questions or feedback, then please drop a note.
P. S. - If you want to improve your Linux command skills, then I also suggest you look at these best online Linux courses from Udemy and Coursera. It's a great course for everyone, and you will definitely learn some useful tips to work better on Linux.
No comments :
Post a Comment