ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Linux: Checking Filesystem Usage with df

    IT Discussion
    df linux centos rhel ubuntu suse opensuse sam linux administration system administration unix
    3
    13
    4.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      One of the most common tasks on any computer is looking at storage utilitzation and in the Linux world the tool we use for this is the df* utility. You can remember df as "display filesystem."

      We will start by looking at the output of a pretty basic system with df:

      $ df
      Filesystem     1K-blocks    Used Available Use% Mounted on
      /dev/vda1       20512592 3809548  15638084  20% /
      devtmpfs          245708       0    245708   0% /dev
      tmpfs             250952       0    250952   0% /dev/shm
      tmpfs             250952   28932    222020  12% /run
      tmpfs             250952       0    250952   0% /sys/fs/cgroup
      tmpfs              50192       0     50192   0% /run/user/1101
      

      The df utility creates a pretty simple table with simple headers. From left to right we have the filesystem device name, then the total size of the filesystem, the used amount of the filesystem, the unused amount of the filesystem, the same data but as a percentage of space consumed and finally the name of the mount point where the filesystem is currently mounted. Only mounted filesystems are shows in df, if other filesystems exist but are not mounted, they will be ignored. It is worth noting that swap is not considered to be mounted and is not shown here.

      In this example, tmpfs and devtmpfs denote a ramdisk like construct that is commonly used to allow the system to store some data in volatile memory as if it were on disk. Under most use cases, we can ignore these as they are volatile (reboot the system and they vanish, created fresh when the system boots up.) They are not on disk so we rarely need to manage them. There are generally many of these on a Linux server.

      If you want to clean up the results and not see the ramdisk usage along with the real usage (this makes it far easier for the human eye to scan or scripts to filter) you can use the -x or "excluse" flag to remove them from display like so:

      df -x tmpfs -x devtmpfs
      Filesystem     1K-blocks    Used Available Use% Mounted on
      /dev/vda1       20512592 3809976  15637656  20% /
      

      This takes far more to type so is often not done, instead we commonly learn to just ignore speciality file types. But if automating, scripting or creating an alias this is a very handy means of making the output more expected and useful.

      The other incredibly handy flag that I use with essentially every df command that I run is the -h flag which stands for "human readable." This flag changes the 1K block sizes into common size formats:

      df -h
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/vda1        20G  3.7G   15G  20% /
      devtmpfs        240M     0  240M   0% /dev
      tmpfs           246M     0  246M   0% /dev/shm
      tmpfs           246M   29M  217M  12% /run
      tmpfs           246M     0  246M   0% /sys/fs/cgroup
      tmpfs            50M     0   50M   0% /run/user/1101
      

      With the human readable option, as you can see, sizes are shown in a common, logical way. The / mount point is 20GB is size, the /dev is 240MB. This is, almost always, what a human would want to see.

      If using the df command in a script or if it is being processed in some way it is more common to want to see the sizes in a uniform way (all with a single scale) so that they can more easily be compared or sorted. Options would include -k for kilobytes, -m for megabytes and -g for gigabytes.

      $ df -m
      Filesystem     1M-blocks  Used Available Use% Mounted on
      /dev/vda1          20032  3725     15268  20% /
      devtmpfs             240     0       240   0% /dev
      tmpfs                246     0       246   0% /dev/shm
      tmpfs                246    29       217  12% /run
      tmpfs                246     0       246   0% /sys/fs/cgroup
      tmpfs                 50     0        50   0% /run/user/1101
      

      You can also use df to get the data from a single mount point:

      df /dev
      Filesystem     1K-blocks  Used Available Use% Mounted on
      devtmpfs          245708     0    245708   0% /dev
      

      All of these commands address the storage capacity of the filesystems. There is one other common usage of df and that is to look at inode utilization of our filesystems. We do this by using the -i flag.

      $ df -i
      Filesystem      Inodes IUsed   IFree IUse% Mounted on
      /dev/vda1      1305600 40358 1265242    4% /
      devtmpfs         61427   301   61126    1% /dev
      tmpfs            62738     1   62737    1% /dev/shm
      tmpfs            62738   327   62411    1% /run
      tmpfs            62738    13   62725    1% /sys/fs/cgroup
      tmpfs            62738     1   62737    1% /run/user/1101
      

      As you can see the Inode display option works just like the capacity one by showing the total number of inodes on each filesystem, the number of inodes used, the number free and then display the percentage of inodes that has been used.


      What is an inode?

      In UNIX-like filesystems (such as FFS, UFS, XFS, EXT4, EXT3, EXT2, JFS, ReiserFS, etc.) an inode is a datastructure on disk that contains metadata about files or directories (directories are just a special kind of file.) Each file has one associated inode. So the total number of inodes represents the total number of files and/or directories that can be created on the filesystem. The inode for a file contains information such as access times, owner and permission data.

      We will cover more about inodes and filesystems at a later time. But it is important to realize that inodes can become exhausted and a disk could be "full", meaning that no more files can be created, even if space still exists. But this situation is relatively rare and can easily be checked with df -i.

      Part of a series on Linux Systems Administration by Scott Alan Miller

      DustinB3403D 1 Reply Last reply Reply Quote 4
      • bbigfordB
        bbigford
        last edited by

        Very appealing colors. What theme are you using for that?

        scottalanmillerS 1 Reply Last reply Reply Quote 0
        • scottalanmillerS
          scottalanmiller @bbigford
          last edited by

          @BBigford said in Linux: Checking Filesystem Usage with df:

          Very appealing colors. What theme are you using for that?

          The colours are generated by NodeBB and the theme that ML has installed (or the one that you have chosen as you can change them.) Those aren't image captures but are just formatted text. There is no colouring denoted in what I input, anything that appears is coming from the Markdown processor in NodeBB,

          1 Reply Last reply Reply Quote 0
          • scottalanmillerS
            scottalanmiller
            last edited by

            This is what the original terminal looks like. I have it partially transparent so if you look very closely, you can see your own avatar through the console.

            0_1463164296881_Screenshot from 2016-05-13 21:31:07.png

            bbigfordB 1 Reply Last reply Reply Quote 0
            • bbigfordB
              bbigford @scottalanmiller
              last edited by

              @scottalanmiller said in Linux: Checking Filesystem Usage with df:

              This is what the original terminal looks like. I have it partially transparent so if you look very closely, you can see your own avatar through the console.

              0_1463164296881_Screenshot from 2016-05-13 21:31:07.png

              That makes sense. I obviously haven't dropped in any code to a ML thread. 🙂

              In either case, looks good formatted by ML then.

              1 Reply Last reply Reply Quote 0
              • bbigfordB
                bbigford
                last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • bbigfordB
                  bbigford
                  last edited by

                  Hmm, can't figure out how you format it that way. Are you doing 'incline code' for the format and then ML takes care of the rest? I've tried a few things but it just ends up looking like plain text.

                  scottalanmillerS 1 Reply Last reply Reply Quote 0
                  • scottalanmillerS
                    scottalanmiller @bbigford
                    last edited by

                    @BBigford said in Linux: Checking Filesystem Usage with df:

                    Hmm, can't figure out how you format it that way. Are you doing 'incline code' for the format and then ML takes care of the rest? I've tried a few things but it just ends up looking like plain text.

                    Oh... try indenting four spaces on a line.

                    1 Reply Last reply Reply Quote 0
                    • scottalanmillerS
                      scottalanmiller
                      last edited by

                      Or puting ``` on the line before and after a block.

                      1 Reply Last reply Reply Quote 0
                      • DustinB3403D
                        DustinB3403 @BRRABill
                        last edited by

                        @BRRABill At the moment I don't have parted installed. If you're unable to install it, you may need (if you really needed it) to enable to global repo's which are disabled by default.

                        1 Reply Last reply Reply Quote 0
                        • scottalanmillerS
                          scottalanmiller
                          last edited by

                          This will do it..

                          gdisk -l /dev/sda
                          
                          1 Reply Last reply Reply Quote 0
                          • DustinB3403D
                            DustinB3403 @scottalanmiller
                            last edited by

                            @scottalanmiller said in Linux: Checking Filesystem Usage with df:


                            What is an inode?

                            In UNIX-like filesystems (such as FFS, UFS, XFS, EXT4, EXT3, EXT2, JFS, ReiserFS, etc.) an inode is a datastructure on disk that contains metadata about files or directories (directories are just a special kind of file.) Each file has one associated inode. So the total number of inodes represents the total number of files and/or directories that can be created on the filesystem. The inode for a file contains information such as access times, owner and permission data.

                            We will cover more about inodes and filesystems at a later time. But it is important to realize that inodes can become exhausted and a disk could be "full", meaning that no more files can be created, even if space still exists. But this situation is relatively rare and can easily be checked with df -i.

                            Part of a series on Linux Systems Administration by Scott Alan Miller

                            Will there be a topic on "managing inode in linux"

                            scottalanmillerS 1 Reply Last reply Reply Quote 0
                            • scottalanmillerS
                              scottalanmiller @DustinB3403
                              last edited by

                              @DustinB3403 said in Linux: Checking Filesystem Usage with df:

                              Will there be a topic on "managing inode in linux"

                              Yes, but it is going to go into an "Advanced Topics" section. Just as LVM and MD will have high level "normal" admin sections and eventually delve much deeper in advanced sections. I want to cover everything in a "normal admin" capacity like you would learn from the RHCE up front. Then go back and cover the nitty gritty details that other admin books don't. So it will basically take two passes but the hope is that the first pass will take you from "starting point" to "competent Linux Admin" then the second part will go where normal admin guides don't tread.

                              1 Reply Last reply Reply Quote 1
                              • 1 / 1
                              • First post
                                Last post