Checking available space on 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 the 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 the ‘df‘ command with their practical examples. So, you could better understand the usage of the 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 the above commands display 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 it 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 systems 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 (MegaByte) use the option ‘ -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 a 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 a certain file system type use the ‘ -t ‘ option. For example, the following command will only display the ext3 file system.

11. Exclude Certain File System Type

If you want to display a file system type that doesn’t belongs to the ext3 type use the option ‘ -x ‘. For example, the following command will only display other file systems types other than ext3.

Читайте также:  Arm windows 10 планшет

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.

Источник

Linux: Find Out How Much Disk Space Left On Hard Drive

I am a desktop support professional with experience working in a corporate call center environment. Recently, I started to admin RHEL based IBM Linux server. How do I determine how much disk space left in my Linux server? How do I find out how much disk space I have in Linux for each partition?

You need to use the df command. It shows the amount of disk space available on the currently mounted file system. df is used to show or find out following information:

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements df
Est. reading time 2 minutes
  1. Used and available space.
  2. File system mount points.
  3. File system capacity.
  4. The number of inodes available.
  5. Find of whether there is sufficient space to upgrade or install new apps.

Syntax

The basic syntax is as follows:

df
df /path/to/dev
df [options] df [options] /path/to/dev

Examples

Type the following command:
# df
# df -H
Sample outputs:

Fig.01: df command in action

The following example will provide information only for the partition/device that contains the /home directory:
# df /home
# df -h /home
To see inode usage instead of block usage, type:
# df -i
# df -i /
# df -ih /
# df -i /dev/md0
Sample outputs:

Pass the -T to find out file system type:
# df -T -h
Sample outputs:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

df command options

From the df command man page:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

Again, thank you! 😀

Great! Thank you.

Df is great for finding the space available on a partition, but it doesn’t paint the entire picture of how much space is available on a hard drive. You would need to check the LVM displays as well as fdisk in order to best answer the question laid out in this article’s title.

Thnaks for providing the answer to this question in complete detail….

you can alse use “findmnt” which might not be provided in ALL UNIX-like variants.

Findmnt or df command

I use df to see how much available space there is on a mounted partition, but is there a good way to see how much space is used vs available on a whole disk, including unpartitioned space?
i suppose i could just look at df output and then compare that to fdisk’s output…
but i’m lazy and i’d love to find a better way or just a single utility/command that would do that for me.

use “cfdisk” command

Thanks for the tip. Cfdisk works pretty good. It makes my life a lot easier when I want to manage partitions from the CLI. Its a lot more visual than fdisk or parted and it’s dead simple. Seems like the next best thing if you don’t have access to gparted.
But even though cfdisk is great, I still wish there was a command like df that would simply return the available free space on the drive, like df does with partitions.

Источник

10 different methods to check disk space in Linux

Table of Contents

In this article I will share different commands and methods to check disk space in Linux. Most of these commands and methods should be available on most Linux distros. You can also utilise these commands to create a script to monitor disk size usage and create alarms or send mails (this would need a mail server).

1. Check partition size using df command

df is one of the most used command to check space of available partitions on the Linux setup. You can use df wih -Th to print the partition type and the partition size in human readable format. This command will show you the total available, used and free space per partition.

You can also use other arguments such as -i to print the available, used and free inode count per partition:

You can check the man page of df command for other supported arguments to check disk space in different formats.

2. Check disk space using fdisk utility

fdisk is another very handy utility for system administrators. fdisk is a user interactive program mostly used for creation and manipulation of partition tables such as creating, deleting, modifying partitions. But we can also use this utility to list the available disks connected to the Linux system along with the respective disk size.

Here is a snippet of output from command » fdisk -l »

As you can see from the output, I have a disk /dev/sda with a size of 15GB. The output also shows more details about this disks wherein it contains two partitions /dev/sda1 and /dev/sda2 .

The output of fdisk -l can be quiet long so if you just wish to check the disk space then you can use this command:

Here I have combined fdisk with awk to only print required sections. So I have two disks with 15GB and 8GB each, while I have two LVM partitions which are most likely part of these disks with a size of 14GB and 512MB.

3. Check disk space using parted utility

parted is another alternative to fdisk and is also used for manipulating disk partitions. It is useful for creating space for new operating systems, reorganising disk usage, and copying data to new hard disks.

Similar to fdisk , we can use parted -l to list all the available disks along with their respective size:

If you compare the output of parted with fdisk , here we only get the available disk and their size and the LVM details are missing which is a good thing as we only wanted to check the disk space.

We can also use awk with parted to further only print required output:

4. Check file size using du command

du is another wonderful utility to check the size of files recursively in Linux. It can also summarize disk usage of the set of files, recursively for directories. du is a very versatile tool and supports multiple arguments which you can use based on your requirement. Some of the most used arguments are:

Here are some example demonstrating different scenarios to check file system size using du command:

EG-1: Check size of all the files under a partition recursively

I have a separate partition for /boot :

So let’s check the size of all the files under /boot using du -h /boot/*

EG-2: Print total summary of size of files in a partition or directory

We can use du -c to print a total or summary of all the file size under provided directory or partition.

So the total file size under /etc/iscsi directory is 20K . You can also use this command under root i.e. du -sch /* to get a summary and total size of all the files under /

EG-3: Sort the output based on file size

By default the du command will print the size of the file based on the first available directory or sub-directory. So the output is not sorted and it can be a tedious task to go through the long list. We can combine du with sort command do sort the output based on the file size.

Here we have used du with sort -hr where -h is used to compare human readable numbers such as 2K, 1G, 4M etc while -r is used to reverse the order of search.

EG-4: Print file size larger than specified size

By default du will print the size of every file found under a partition or directory. We can add a threshold to print files higher than a certain size.

For example here we are printing the files with size higher than 1MB under /var/log

For more list of supported options check the man page of du command.

5. Check disk size using lsblk command

lsblk lists information about all available or the specified block devices. The lsblk command reads the sysfs filesystem and udev db to gather information. If the udev db is not available or lsblk is compiled without udev support than it tries to read LABELs, UUIDs and filesystem types from the block device.

We can use lsblk with -o LIST or —output LIST to get desired columns based on the value of LIST. Use lsblk —help to get a list of all supported columns.

We will use name, fstype, size, mountpoint LIST for our example. Although using only size and name was enough but to give more detailed output I am using additional list options.

6. Print disk size using blockdev

We can use blockdev command to print a report for the specified device. It is possible to give multiple devices. If none is given, all devices which appear in /proc/partitions are shown. Note that the partition StartSec is in 512-byte sectors.

You can also use following commands:

7. Check disk size and details using lshw command

lshw is a small tool to extract detailed information on the hardware configuration of the machine. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etc. on DMI-capable x86 or IA-64 systems and on some PowerPC machines.

By default lshw will give you a huge output, we can limit that by only printing the information for a specified class such as » disk «. To get the list of attached disks and their details such as size we will use lshw -c disk .

Here is an output snippet from my Linux node:

We can further improve the output using lshw with grep :

8. Checking disk size from the system logs

We can also use system logs such as boot logs using dmesg or journalctl -b and try to search for respective disk to get more information. The catch is that you should know the disk name unlike other methods which we discussed where we were able to check size of all the available disks without prior knowledge of disk name.

For example, here I am searching for all instance of sda disk in boot logs using dmesg :

Similarly we can search for any other disk, such as sdb :

You may also try grepping blocks in dmesg output which can list the available disk with their size:

9. Check disk size using lsscsi command

lsscsi uses information in sysfs (Linux kernel series 2.6 and later) to list SCSI devices (or hosts) currently attached to the system. Many non-SCSI storage devices (but not all) used the SCSI subsystem in Linux. In lsscsi version 0.30 support was added to list NVMe devices.

We can use lsscsi —size to list all the connected storage devices along with their size as shown below:

10. Print disk size using sfdisk

sfdisk is again an alternative to fdisk and parted utility. One of the major difference between fdisk and sfdisk is that sfdisk reads and writes partition tables, but is not interactive like fdisk or cfdisk (it reads input from a file or stdin). It’s generally used for partitioning drives from scripts or for partition table backup and recovery.

But it can also be used to check the disk size using sfdisk -l , sample output:

Summary

In this article we explored different commands and methods which can be used to check disk size (used/available/total) in Linux. You can easily utilize most of these commands and methods into a script to regularly monitor the available disk space and raise alarm when threshold is reached. There are some more commands such as udisks, hwinfo which can be used to collect similar information but they are distro dependent and may not be available with all the Linux distributions hence I have skipped them.

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Источник

Читайте также:  Linux как увеличить var каталог
Оцените статью