10 df commands for viewing disk space in Linux or Ubuntu

Source: Internet
Author: User

10 df commands for viewing disk space in Linux or Ubuntu

In Linux, you can use the command line tool named df to check disk space. The df command represents the disk file system. Using the df command, you can find the disk space summary information on Linux, such as available disk space and used disk space.

In this tutorial, we will teach you ten different df commands and actual examples to manage disk space on Linux.

Let's explore df commands with all options so that you can have a complete understanding of Linux disk space.

The basic syntax of the df command is:

Df [options] [devices]

1. Check the disk space of the file system

The "df" command displays information such as the name of the file system device, disk block, total disk space used, available disk space, usage and decoration percentage on the file system.

You can see similar output on the screen.

Bkjia @ bkjia :~ $ Df
File System 1 K-block used available % mount point
Udev 1949940 0 1949940 0%/dev
Tmpfs 395396 12000 383396 4%/run
/Dev/sda2 55438112 12254984 40337304 24%/
Tmpfs 1976964 25356 1951608 2%/dev/shm
Tmpfs 5120 4 5116 1%/run/lock
Tmpfs 1976964 0 1976964 0%/sys/fs/cgroup
/Dev/loop0 5248 5248 0 100%/snap/network-manager/233
/Dev/loop3 128256 128256 0 100%/snap/vscode/22
/Dev/loop1 415232 415232 0 100%/snap/intellij-idea-community/27
/Dev/loop2 155776 155776 0 100%/snap/skype/9
/Dev/loop5 131072 131072 0 100%/snap/vscode/23
/Dev/loop7 83328 83328 0 100%/snap/core/3887
/Dev/loop8 85888 85888 0 100%/snap/core/3604
/Dev/loop9 85888 85888 0 100%/snap/core/3748
/Dev/loop10 405760 405760 0 100%/snap/libreoffice/46
/Dev/loop6 127488 127488 0 100%/snap/vscode/20
/Dev/loop4 112256 112256 0 100%/snap/pyradio/12
/Dev/sda3 28705700 374852 26849632 2%/boot
/Dev/sda4 25821988 15587260 8899996 64%/home
/Dev/sda1 523248 4688 518560 1%/boot/efi
Tmpfs 395392 16 395376 1%/run/user/121
/Dev/loop11 54784 54784 0 100%/snap/foobar2000/47
/Dev/sdb1 30873116 5054308 25818808 17%/media/bkjia/helper's house
Tmpfs 395392 3184 392208 1%/run/user/1000
/Dev/loop12 106496 106496 0 100%/snap/skype/13
Bkjia @ bkjia :~ $

2. Display disk space in an understandable format

As you can see in the first example, output is hard to read or understand. By default, the df command displays hard-to-understand disk space information in bytes. We can easily understand that the results are measured in megabytes and gigabytes.

Don't worry. Good df commands can display information in readable formats such as MB and GB. You only need to add the-h flag for viewing.

Bkjia @ bkjia :~ $ Df-h
File System capacity used available % mount point
Udev 1.9G 0 1.9G 0%/dev
Tmpfs 387 M 12 M 375 M 4%/run
/Dev/sda2 53G 12G 39G 24%/
Tmpfs 1.9G 20 M 1.9G 2%/dev/shm
Tmpfs 5.0 M 4.0 K 5.0 M 1%/run/lock
Tmpfs 1.9G 0 1.9G 0%/sys/fs/cgroup
/Dev/loop0 5.2 M 5.2 M 0 100%/snap/network-manager/233
/Dev/loop3 126 M 126 M 0 100%/snap/vscode/22
/Dev/loop1 406 M 406 M 0 100%/snap/intellij-idea-community/27
/Dev/loop2 153 M 153 M 0 100%/snap/skype/9
/Dev/loop5 128 M 128 M 0 100%/snap/vscode/23
/Dev/loop7 82 M 82 M 0 100%/snap/core/3887
/Dev/loop8 84 M 84 M 0 100%/snap/core/3604
/Dev/loop9 84 M 84 M 0 100%/snap/core/3748
/Dev/loop10 397 M 397 M 0 100%/snap/libreoffice/46
/Dev/loop6 125 M 125 M 0 100%/snap/vscode/20
/Dev/loop4 110 M 110 M 0 100%/snap/pyradio/12
/Dev/sda3 28G 367 M 26G 2%/boot
/Dev/sda4 25G 15G 8.5G 64%/home
/Dev/sda1 511 M 4.6 M 507 M 1%/boot/efi
Tmpfs 387 M 16 K 387 M 1%/run/user/121
/Dev/loop11 54 M 54 M 0 100%/snap/foobar2000/47
/Dev/sdb1 30G 4.9G 25G 17%/media/bkjia/helper house
Tmpfs 387 M 2.0 M 385 M 1%/run/user/1000
/Dev/loop12 104 M 104 M 0 100%/snap/skype/13
Bkjia @ bkjia :~ $

3. display information of all file systems

If you want to view all file systems with zero block size, pass the-a or-all parameter together with the df command. The output will be similar to this.

Bkjia @ bkjia :~ $ Df-
File System 1 K-block used available % mount point
Sysfs 0 0 0-/sys
Proc 0 0 0-/proc
Udev 1949940 0 1949940 0%/dev
Devpts 0 0 0-/dev/pts
Tmpfs 395396 12004 383392 4%/run
/Dev/sda2 55438112 12254988 40337300 24%/
Securityfs 0 0 0-/sys/kernel/security
Tmpfs 1976964 20324 1956640 2%/dev/shm
Tmpfs 5120 4 5116 1%/run/lock
Tmpfs 1976964 0 1976964 0%/sys/fs/cgroup
Cgroup 0 0 0-/sys/fs/cgroup/uniied
Cgroup 0 0 0-/sys/fs/cgroup/systemd
Pstore 0 0 0-/sys/fs/pstore

4. display file system details in bytes

To display information and usage of all file systems in 1 K blocks, pass the option '-k' as follows '.

Bkjia @ bkjia :~ $ Df-k
File System 1 K-block used available % mount point
Udev 1949940 0 1949940 0%/dev
Tmpfs 395396 12004 383392 4%/run
/Dev/sda2 55438112 12255004 40337284 24%/
Tmpfs 1976964 20324 1956640 2%/dev/shm
Tmpfs 5120 4 5116 1%/run/lock
Tmpfs 1976964 0 1976964 0%/sys/fs/cgroup
/Dev/loop0 5248 5248 0 100%/snap/network-manager/233
/Dev/loop3 128256 128256 0 100%/snap/vscode/22
/Dev/loop1 415232 415232 0 100%/snap/intellij-idea-community/27
/Dev/loop2 155776 155776 0 100%/snap/skype/9

5. display file system information in MB

To display all file system information and usage in MB or MB, pass the '-m' option '.

Bkjia @ bkjia :~ $ Df-m
File System 1 M-block used available % mount point
Udev 1905 0 1905 0%/dev
Tmpfs 387 12 375 4%/run
/Dev/sda2 54139 11968 39392 24%/
Tmpfs 1931 20 1911 2%/dev/shm
Tmpfs 5 1 5 1%/run/lock
Tmpfs 1931 0 1931 0%/sys/fs/cgroup
/Dev/loop0 6 6 0 100%/snap/network-manager/233
/Dev/loop3 126 126 0 100%/snap/vscode/22
/Dev/loop1 406 406 0 100%/snap/intellij-idea-community/27
/Dev/loop2 153 153 0 100%/snap/skype/9

6. display the file system information in GB

To display details and usage of all file systems in GB or bytes, pass the option '-H '.

Bkjia @ bkjia :~ $ Df-h
File System capacity used available % mount point
Udev 1.9G 0 1.9G 0%/dev
Tmpfs 387 M 12 M 375 M 4%/run
/Dev/sda2 53G 12G 39G 24%/
Tmpfs 1.9G 20 M 1.9G 2%/dev/shm
Tmpfs 5.0 M 4.0 K 5.0 M 1%/run/lock
Tmpfs 1.9G 0 1.9G 0%/sys/fs/cgroup
/Dev/loop0 5.2 M 5.2 M 0 100%/snap/network-manager/233
/Dev/loop3 126 M 126 M 0 100%/snap/vscode/22
/Dev/loop1 406 M 406 M 0 100%/snap/intellij-idea-community/27
/Dev/loop2 153 M 153 M 0 100%/snap/skype/9
/Dev/loop5 128 M 128 M 0 100%/snap/vscode/23

7. Display/main file system information

By executing the following df command, you can only view the/home file system device information.

Bkjia @ bkjia :~ $ Df-h/home
File System capacity used available % mount point
/Dev/sda4 25G 15G 8.5G 64%/home
Bkjia @ bkjia :~ $

8. display the file system type in Linux

To view the type of each file system, pass the-T option. It provides output for file system type columns. You can see the types of each listed file system, such as ext4, ext3, tempfs, and devtmpfs.

Bkjia @ bkjia :~ $ Df-T
File System Type 1 K-block used available % mount point
Udev devtmpfs 1949940 0 1949940 0%/dev
Tmpfs 395396 12004 383392 4%/run
/Dev/sda2 ext4 55438112 12261152 40331136 24%/
Tmpfs 1976964 20312 1956652 2%/dev/shm
Tmpfs 5120 4 5116 1%/run/lock
Tmpfs 1976964 0 1976964 0%/sys/fs/cgroup
/Dev/loop0 squashfs 5248 5248 0 100%/snap/network-manager/233
/Dev/loop3 squashfs 128256 128256 0 100%/snap/vscode/22
/Dev/loop1 squashfs 415232 415232 0 100%/snap/intellij-idea-community/27
/Dev/loop2 squashfs 155776 155776 100% 0/snap/skype/9
/Dev/loop5 squashfs 131072 131072 0 100%/snap/vscode/23

9. Only include or exclude certain file system types.

If you only want to view the ext4 file system, use the df command with the-t Option

Bkjia @ bkjia :~ $ Df-t ext4
File System 1 K-block used available % mount point
/Dev/sda2 55438112 12261156 40331132 24%/
/Dev/sda3 28705700 374852 26849632 2%/boot
/Dev/sda4 25821988 15587616 8899640 64%/home
Bkjia @ bkjia :~ $

If you want to view all file system types except ext4, pass the-x option and type (ext3, ext4) to exclude them from the output.

Bkjia @ bkjia :~ $ Df-x ext4
File System 1 K-block used available % mount point
Udev 1949940 0 1949940 0%/dev
Tmpfs 395396 12000 383396 4%/run
Tmpfs 1976964 13776 1963188 1%/dev/shm
Tmpfs 5120 4 5116 1%/run/lock
Tmpfs 1976964 0 1976964 0%/sys/fs/cgroup
/Dev/loop0 5248 5248 0 100%/snap/network-manager/233
/Dev/loop3 128256 128256 0 100%/snap/vscode/22
/Dev/loop1 415232 415232 0 100%/snap/intellij-idea-community/27
/Dev/loop2 155776 155776 0 100%/snap/skype/9
/Dev/loop5 131072 131072 0 100%/snap/vscode/23
/Dev/loop7 83328 83328 0 100%/snap/core/3887

10. Display df Command Options and help

Run the following command to view all available options.

Bkjia @ bkjia :~ $ Df -- help
Usage: df [Option]... [file]...
Displays information about the FILE system where each FILE is located,
Or all file systems by default.

The required parameter applies to both the length and length options.
-A, -- all include pseudo, duplicate, inaccessible file systems
-B, -- block-size = SIZE scale sizes by SIZE before printing them; e.g .,
'-BM' prints sizes in units of 1,048,576 bytes;
See SIZE format below
-H, -- human-readable print sizes in powers of 1024 (e.g., 1023 M)
-H, -- si print sizes in powers of 1000 (e.g., 1.1G)
-I, -- inodes: displays inode information instead of block usage.
-K is -- block-size = 1 K
-L, -- local only displays the local file system
-- No-sync: no synchronization action is performed before the data used is obtained (default)
-- Output [= FIELD_LIST] use the output format defined by FIELD_LIST,
Or print all fields if FIELD_LIST is omitted.
-P, -- portability use the POSIX output format
-- Sync invoke sync before getting usage info
-- Total elide all entries insignificant to available space,
And produce a grand total
-T, -- type = TYPE limit listing to file systems of type TYPE type
-T, -- print-type print file system type
-X, -- exclude-type = TYPE limit listing to file systems not of type TYPE type
-V (ignored)
-- Help: displays the help information and exits.
-- Version: displays the version information and exits.

The displayed values are from -- block-size, DF_BLOCK_SIZE, and BLOCK_SIZE.
And the first available SIZE unit in the BLOCKSIZE environment variable.
Otherwise, the default unit is 1024 bytes (or 512, if POSIXLY_CORRECT is set ).

This article permanently updates link: https://www.bkjia.com/Linux/2018-02/150995.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.