Command to check disk in linux

How to Check Disk Space in Linux

Managing disk space on a Linux server is an important task. For example, package manager applications notify you how much disk space will be required for an installation. For that information to be meaningful, you should know how much space your system has available.

In this tutorial, learn how to use the df command to check disk space in Linux and the du command to display file system disk space usage.

Tutorial on checking available disk space in Linux

  • A Linux-based system
  • A terminal window / command line
  • A user account with sudo or root privileges

Check Linux Disk Space Using df Command

You can check your disk space simply by opening a terminal window and entering the following:

Command to check disk space on Linux.

The df command stands for disk free, and it shows you the amount of space taken up by different drives. By default, df displays values in 1-kilobyte blocks.

Display Usage in Megabytes and Gigabytes

You can display disk usage in a more human-readable format by adding the -h option:

This displays the size in kilobytes (K), megabytes (M), and gigabytes (G).

Command to check disk space in human-readable format of kilobytes, megabytes,and gigabytes

Understanding the Output Format

The df command lists several columns:

Filesystem Size Used Avail Use% Mounted on udev 210M 0 210M 0% /dev tmpfs 49M 1004K 48M 3% /run /dev/sda2 7.9G 4.3G 3.2G 58% /

Your output may have more entries. The columns should be self-explanatory:

  • Filesystem – This is the name of each particular drive. This includes physical hard drives, logical (partitioned) drives, and virtual or temporary drives.
  • Size The size of the filesystem.
  • Used – Amount of space used on each filesystem.
  • Avail – The amount of unused (free) space on the filesystem.
  • Use% – Shows the percent of the disk used.
  • Mounted on – This is the directory where the file system is located. This is also sometimes called a mount point.

The list of filesystems includes your physical hard drive, as well as virtual hard drives:

  • /dev/sda2 – This is your physical hard drive. It may be listed as /sda1, /sda0, or you may even have more than one. /dev stands for device.
  • udev This is a virtual directory for the /dev directory. This is part of the Linux operating system.
  • tmpfs – You may have several of these. These are used by /run and other Linux processes as temporary filesystems for running the operating system. For example, the tmpfs /run/lock is used to create lockfiles. These are the files that prevent multiple users from changing the same file at the same time.
Читайте также:  At команды huawei linux

Display a Specific File System

The df command can be used to display a specific file system:

You can also use a backslash:

This displays the usage on your primary hard drive. Use the mount point (in the Mounted on column) to specify the drive you want to check.

Command to display the usage of a specific file system.

Note: The df command only targets a full filesystem. Even if you specify an individual directory, df will read the space of the whole drive.

Display File Systems by Type

To list all file systems by type, use the command:

This lists drives with the ext4 type, in human-readable format.

Command to list drives with the ext4 type with size and available space show

Display Size in 1000 Instead of 1024

You can display disk usage in units of 1000 instead of 1024:

This can address a point of confusion in storage technology. Hard drive manufacturers sell hard drives in sizes based on 1000 bytes = 1 kilobyte.

However, operating systems divide that space up so that 1024 bytes = 1 kilobyte. Because of this, a 1000-gigabyte hard drive ends up with roughly 930 gigabytes of usable storage.

Note: Check out our overview of the Linux free command used to check total, used, shared, free, and available memory and swap space.

Check Disk Space in Linux With du Command

The du command displays disk usage. This tool can display disk usage for individual directories in Linux, giving you a finer-grained view of your disk usage. Use it to display the amount of space used by your current directory:

Du command for displaying disk usage in Linux.

Like the df command, you can make du human-readable:

It displays a list of the contents of the current directory, and how much space they’re using. You can simplify the display with the -s option:

This shows how much space the current directory uses.

example of how much space is left in a linux directory

To specify the directory or file, check use the following options:

With the second command, you may have noticed a permission denied error message. This means the current user doesn’t have the privileges to access certain directories. Use the sudo command to elevate your privileges:

Note: If you’re working on CentOS Linux, you may need to use the su command to switch to the root user to access protected directories.

You should now understand how to use df and du commands to check disk space on your Linux system. Remember, to display a complete list of options, use either df —help or du —help .

Check out our article on how to use fsck command to run a filesystem check as preventive maintenance or when there is an issue with your system.

Источник

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.

How to Check Disk Space in Linux

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.

Читайте также:  Midnight commander горячие клавиши 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.

[[email protected] ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/cciss/c0d0p2 78361192 23185840 51130588 32% / /dev/cciss/c0d0p5 24797380 22273432 1243972 95% /home /dev/cciss/c0d0p3 29753588 25503792 2713984 91% /data /dev/cciss/c0d0p1 295561 21531 258770 8% /boot tmpfs 257476 0 257476 0% /dev/shm

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.

[[email protected] ~]# df -a Filesystem 1K-blocks Used Available Use% Mounted on /dev/cciss/c0d0p2 78361192 23186116 51130312 32% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys devpts 0 0 0 - /dev/pts /dev/cciss/c0d0p5 24797380 22273432 1243972 95% /home /dev/cciss/c0d0p3 29753588 25503792 2713984 91% /data /dev/cciss/c0d0p1 295561 21531 258770 8% /boot tmpfs 257476 0 257476 0% /dev/shm none 0 0 0 - /proc/sys/fs/binfmt_misc sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs

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)).

[[email protected] ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/cciss/c0d0p2 75G 23G 49G 32% / /dev/cciss/c0d0p5 24G 22G 1.2G 95% /home /dev/cciss/c0d0p3 29G 25G 2.6G 91% /data /dev/cciss/c0d0p1 289M 22M 253M 8% /boot tmpfs 252M 0 252M 0% /dev/shm

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.

[[email protected] ~]# df -hT /home Filesystem Type Size Used Avail Use% Mounted on /dev/cciss/c0d0p5 ext3 24G 22G 1.2G 95% /home

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.

[[email protected] ~]# df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/cciss/c0d0p2 78361192 23187212 51129216 32% / /dev/cciss/c0d0p5 24797380 22273432 1243972 95% /home /dev/cciss/c0d0p3 29753588 25503792 2713984 91% /data /dev/cciss/c0d0p1 295561 21531 258770 8% /boot tmpfs 257476 0 257476 0% /dev/shm

6. Display Information of File System in MB

To display information of all file system usage in MB (MegaByte) use the option ‘ -m ‘.

[[email protected] ~]# df -m Filesystem 1M-blocks Used Available Use% Mounted on /dev/cciss/c0d0p2 76525 22644 49931 32% / /dev/cciss/c0d0p5 24217 21752 1215 95% /home /dev/cciss/c0d0p3 29057 24907 2651 91% /data /dev/cciss/c0d0p1 289 22 253 8% /boot tmpfs 252 0 252 0% /dev/shm

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‘.

[[email protected] ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/cciss/c0d0p2 75G 23G 49G 32% / /dev/cciss/c0d0p5 24G 22G 1.2G 95% /home /dev/cciss/c0d0p3 29G 25G 2.6G 91% /data /dev/cciss/c0d0p1 289M 22M 253M 8% /boot tmpfs 252M 0 252M 0% /dev/shm

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.

[[email protected] ~]# df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/cciss/c0d0p2 20230848 133143 20097705 1% / /dev/cciss/c0d0p5 6403712 798613 5605099 13% /home /dev/cciss/c0d0p3 7685440 1388241 6297199 19% /data /dev/cciss/c0d0p1 76304 40 76264 1% /boot tmpfs 64369 1 64368 1% /dev/shm

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.

[[email protected] ~]# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/cciss/c0d0p2 ext3 78361192 23188812 51127616 32% / /dev/cciss/c0d0p5 ext3 24797380 22273432 1243972 95% /home /dev/cciss/c0d0p3 ext3 29753588 25503792 2713984 91% /data /dev/cciss/c0d0p1 ext3 295561 21531 258770 8% /boot tmpfs tmpfs 257476 0 257476 0% /dev/shm

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.

[[email protected] ~]# df -t ext3 Filesystem 1K-blocks Used Available Use% Mounted on /dev/cciss/c0d0p2 78361192 23190072 51126356 32% / /dev/cciss/c0d0p5 24797380 22273432 1243972 95% /home /dev/cciss/c0d0p3 29753588 25503792 2713984 91% /data /dev/cciss/c0d0p1 295561 21531 258770 8% /boot

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.

[[email protected] ~]# df -x ext3 Filesystem 1K-blocks Used Available Use% Mounted on tmpfs 257476 0 257476 0% /dev/shm

12. Display Information of df Command.

Using ‘—help ‘ switch will display a list of available option that is used with df command.

[[email protected] ~]# df --help Usage: df [OPTION]. [FILE]. Show information about the file system on which each FILE resides, or all file systems by default. Mandatory arguments to long options are mandatory for short options too. -a, --all include dummy file systems -B, --block-size=SIZE use SIZE-byte blocks -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) -H, --si likewise, but use powers of 1000 not 1024 -i, --inodes list inode information instead of block usage -k like --block-size=1K -l, --local limit listing to local file systems --no-sync do not invoke sync before getting usage info (default) -P, --portability use the POSIX output format --sync invoke sync before getting usage info -t, --type=TYPE limit listing to file systems of type TYPE -T, --print-type print file system type -x, --exclude-type=TYPE limit listing to file systems, not of type TYPE -v (ignored) --help display this help and exit --version output version information and exit SIZE may be (or maybe an integer optionally followed by) one of the following: kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y. Report bugs to [email protected]>.

Источник

Оцените статью
Adblock
detector