Df command tutorial with examples for beginners. Df command does not show correct values


Linux: The complete guide Kolisnichenko Denis Nikolaevich

9.2.2. System resource information: free, df, du commands

Command free shows the total number of people employed and free memory: physical, swap and kernel buffers. By default, the amount of memory is displayed in kilobytes, and the keys -b and -m allow you to measure it in bytes and megabytes, respectively.

Key -s<число> requires polling the system continuously, every<число>seconds until you interrupt the command by pressing Ctrl + C.

Commands df (disk free) and du (disk usage) show how much space is available and used on the hard disk.

Utility df displays information about disk space on all mounted in this moment file systems - both local and network:

1K block file system Use Available Use% mounted on

/ dev / hda4 22200824 4630864 16442200 22% /

/ dev / hda2 101105 8383 87501 9% / boot

/ dev / hda6 10221420 1737440 8483980 17% / mnt / win_disk_e

// user5 / share 7543680 4623488 2920192 62% / mnt / win_user5

With key -i the df command measures the disk space not in blocks, but in inodes (section 2.2.1), and with the -T switch shows the type of the file system. Other options can be found, as usual, on the man page.

Command du shows how much space each subdirectory of the directories specified as an argument takes up (if no arguments are specified, this will be the current directory) and calculates the grand total. If you do not have enough rights to view some subdirectories, then the result will differ from the correct one by the size of the prohibited directories.

From the Iptables Tutorial 1.1.19 by Andreasson Oskar

Appendix G. GNU Free Documentation License Version 1.1, March 2000 Copyright (C) 2000 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not

From the book Protecting Your Computer the author Yaremchuk Sergey Akimovich

AVG Free Edition Let's move on to one of the developments of the Czech company Grisoft - free AVG antivirus Free Edition. This antivirus program has good functionality, however the user free version can only work with English interface. AVG Free Edition is devoid of

From book 200 best programs for the Internet. Popular tutorial author Krainsky I

AVG Free Edition Vendor: Grisoft (http://www.grisoft.com/). Status: free. Download page: http://www.grisoft.com/doc/Programs/lng/us/tpl/tpl01. Size : 16.6 MB. When evaluating a new, little-known antivirus, it is customary to compare it with such well-known programs as Kaspersky Anti-Virus. In such

From the book Computer 100. Starting with Windows Vista author Zozulya Yuri

A-squared Free Manufacturer: Emsi Software GmbH (http://www.emsisoft.com). Status: free. Download page: http://www.emsisoft.com/en/software/download/. Distribution size: 16 , 3 Mbyte. A-squared Free antivirus package specialization - protecting your computer from various mail infections: Trojans, worms,

From the book TCP / IP Architecture, Protocols, Implementation (including IP version 6 and IP Security) by Faith Sidney M

General information about web resources of the Internet The Internet is a big computer network, which covers the whole world and consists of many small networks interconnected with each other. So that any computers on the Internet can communicate with each other without problems, across the entire network

From the book Computer Science: Hardware personal computer the author Yashin Vladimir Nikolaevich

12.13.1 Resource records This data item part consists of: [class] RecordType RecordData is called a resource record (RR). There are several types of resource records, each identified by a symbol or short acronym. Record types about

From the book Web Samodelkin. How to create a website yourself quickly and professionally the author Smooth Alexey Anatolevich

Chapter 1 Information, Information Processes and Systems

From the book How to find and download any files on the Internet author Raitman M.A.

Automatic registration of a site in search engines, catalogs and other resources One of the main advantages Page programs Promoter is an opportunity automatic registration site on thousands of various resources ( search engines, catalogs, ratings, etc.). it

From the book Ubuntu 10. Quick Start Guide the author Kolisnichenko D.N.

Antivirus package AVG Free B recent times work of the majority malware aims to obtain Money... If earlier viruses that perform various destructive functions prevailed among malicious programs, now mass epidemics are mainly

From book Linux programming in examples the author Robbins Arnold

21.3.8. The uptime command - information about the system operation The uptime command (Fig. 21.1) displays statistical information about the system operation: how much time has passed since the last reboot (in fact, this is the "uptime" time), how many users are currently connected to

From the book Digital Photography. Tricks and effects the author Gursky Yuri Anatolievich

21.3.10. The w, who, and whoami commands - information about users These three related commands display the following information (Figure 21.3) :? command w - list of users connected to the system; the virtual terminal from which the user works; login time for each

From book Social networks... VKontakte, Facebook and others ... the author Leontiev Vitaly Petrovich

21.6.1. Free and df commands - information about system resources The free command displays information about the use of the operating and virtual memory and df is about disk space usage. Fig. 21.5 shows that the system has only 512 MB of RAM, of which almost everything is occupied. On

From the book Sacred Wars of the World FOSS the author Alexey Fedorchuk

3.2.1.3. Freeing memory: free () When you've finished using memory, "reclaim it" using the free () function. The only argument is a pointer previously obtained using another selection function. It is possible (although it is useless) to convey

From the author's book

12.3. Free Transform (Free transformation) If the previous resizing tools are intended for the entire image, then Free Transform (Free transformation) allows you to change not only the dimensions, but also the proportions, the angle of rotation for the selected object or

From the author's book

Fera Free For Facebook By design, this "alternative" is made by the official client, like a peacock, an infusoria-shoe. Everything is convenient, everything is divided into functional tabs ... And instead of a boring "sheet" of linear text, we see a competent layout. Almost the magazine turns out, although not before

In this tutorial, we will learn how to use the df command. Df command means D isk F ree, which means the use of disk space on the file system. It displays the amount of disk space available on the file system in Linux system... The DF command should not be confused with the df command. They serve a variety of purposes. DF team reports, how much disk space do we have(that is free place), while the df command reports, it is how much disk space is consumed to files and folders. Hope we have explained to you clearly. Let's go ahead and see some practical examples df command so that you can understand it better.

Df command tutorial with examples

1. Kind of using the entire file system on disk

Run the commands without any arguments to display the entire disk space of the file system.

Output example:

Filesystem 1K-blocks Used Available Use% Mounted on dev 4033216 0 4033216 0% / dev run 4038880 1120 4037760 1% / run / dev / sda2 478425016 428790352 25308980 95% / tmpfs 4038880 34396 4004484 1% / dev / shm tmpfs 4038880 0 40388 0% / sys / fs / cgroup tmpfs 4038880 11636 4027244 1% / tmp / dev / loop0 84096 84096 0 100% / var / lib / snapd / snap / core / 4327 / dev / sda1 95054 55724 32162 64% / boot tmpfs 807776 28 807748 1% / run / user / 1000

As you can see, the result is divided into six columns. Let's see what each column means.

  • Filesystem- file system in the system.
  • 1K-blocks- file system size, measured in 1K blocks.
  • Used- the amount of used space in 1K blocks.
  • Available- number free space in 1K blocks.
  • Use%- percentage of filesystem usage.
  • Mounted on Is the mount point where the filesystem is installed.

2. Using the file system of the disk. Display in human readable format

As you can see in the examples above, usage is shown in 1k blocks. If you want to display them in human readable format, use the flag -h.

$ df -h Filesystem Size Used Avail Use% Mounted on dev 3.9G 0 3.9G 0% / dev run 3.9G 1.1M 3.9G 1% / run / dev / sda2 457G 409G 25G 95% / tmpfs 3.9G 27M 3.9G 1 % / dev / shm tmpfs 3.9G 0 3.9G 0% / sys / fs / cgroup tmpfs 3.9G 12M 3.9G 1% / tmp / dev / loop0 83M 83M 0 100% / var / lib / snapd / snap / core / 4327 / dev / sda1 93M 55M 32M 64% / boot tmpfs 789M 28K 789M 1% / run / user / 1000

Now let's look at the columns Size and Avail, usage is shown in GB and MB.

3. Show disk space usage in MB only

To view the disk space usage in the file system only in megabytes, use the flag -m.

$ df -m Filesystem 1M-blocks Used Available Use% Mounted on dev 3939 0 3939 0% / dev run 3945 2 3944 1% / run / dev / sda2 467212 418742 24716 95% / tmpfs 3945 26 3920 1% / dev / shm tmpfs 3945 0 3945 0% / sys / fs / cgroup tmpfs 3945 12 3933 1% / tmp / dev / loop0 83 83 0 100% / var / lib / snapd / snap / core / 4327 / dev / sda1 93 55 32 64% / boot tmpfs 789 1 789 1% / run / user / 1000

4. Listing inode information instead of using a block

We can list information inode instead of using a block with a flag -i as shown below.

$ df -i Filesystem Inodes IUsed IFree IUse% Mounted on dev 1008304 439 1007865 1% / dev run 1009720 649 1009071 1% / run / dev / sda2 30392320 844035 29548285 3% / tmpfs 1009720 86 1009634 1% / dev / shm tmpfs 1009720 18 1009702 1% / sys / fs / cgroup tmpfs 1009720 3008 1006712 1% / tmp / dev / loop0 12829 12829 0 100% / var / lib / snapd / snap / core / 4327 / dev / sda1 25688 390 25298 2% / boot tmpfs 1009720 29 1009691 1% / run / user / 1000

5. Displaying the file system type

To display the type of filesystem, use the flag -T.

$ df -T Filesystem Type 1K-blocks Used Available Use% Mounted on dev devtmpfs 4033216 0 4033216 0% / dev run tmpfs 4038880 1120 4037760 1% / run / dev / sda2 ext4 478425016 428790896 25308436 95% / tmpfs tmpfs 4038880 31300 4007580 1 % / dev / shm tmpfs tmpfs 4038880 0 4038880 0% / sys / fs / cgroup tmpfs tmpfs 4038880 11984 4026896 1% / tmp / dev / loop0 squashfs 84096 84096 0 100% / var / lib / snapd / snap / core / 4327 / dev / sda1 ext4 95054 55724 32162 64% / boot tmpfs tmpfs 807776 28 807748 1% / run / user / 1000

As you can see, there is additional column(second from left), which shows the type of filesystem.

6. Display only a specific type of file system

We can limit the list to specific filesystems. for example, ext4... For this we use the flag -t.

$ df -t ext4 Filesystem 1K-blocks Used Available Use% Mounted on / dev / sda2 478425016 428790896 25308436 95% / / dev / sda1 95054 55724 32162 64% / boot

Did you see? This command only shows the disk space usage of the ext4 filesystem.

7. Exclude a specific type of filesystem

You can exclude a specific filesystem from the result. This can be achieved by using a flag -x.

$ df -x ext4 Filesystem 1K-blocks Used Available Use% Mounted on dev 4033216 0 4033216 0% / dev run 4038880 1120 4037760 1% / run tmpfs 4038880 26116 4012764 1% / dev / shm tmpfs 4038880 0 4038880 0% / sys / fs / cgroup tmpfs 4038880 11984 4026896 1% / tmp / dev / loop0 84096 84096 0 100% / var / lib / snapd / snap / core / 4327 tmpfs 807776 28 807748 1% / run / user / 1000

This command will show the use of all filesystems except ext4.

8. Show usage for folders

To display the available disk space and where it is connected to a folder, for example / home / sk /, use the following command:

$ df -hT / home / sk / Filesystem Type Size Used Avail Use% Mounted on / dev / sda2 ext4 457G 409G 25G 95% /

This command shows the file system type, used and available space in a readable form and where it is installed. If you don't want to display the filesystem type, just ignore with the flag -t.

This is a RHEL server, I am using on it MySQL server, the database and log files (however logging is disabled) are located in the / srv directory where a lot of space is available.

I recently had a broken table so I tried to fix it, but the next day I found that MySQL was unable to answer many queries with an error indicating no disk space:

ERROR 1030 (HY000): Got error 28 from storage engine

So I ran the following command to see what is taking up space

# -h Filesystem Size Used Avail Use% Mounted on / dev / mapper / server-slash 9.9G 9.5G 0 100% / tmpfs 7.8G 0 7.8G 0% / dev / shm / dev / sda1 485M 58M 402M 13% / boot / dev / mapper / server-var 739G 252G 450G 36% / srv

Surprisingly, this is /. But more surprisingly, the directories under / do not indicate the used space anymore. 2 GB while df shows the total space 9.9 GB for / .

# du -sh / * 7.5M / bin 48M / boot 200K / dev 24M / etc 4.0K / home 223M / lib 21M / lib64 16K / lost + found 4.0K / media 4.0K / mnt 183M / opt ... deleted some file-not-found errors for files under / proc 0 / proc 144K / root 14M / sbin 4.0K / selinux 252G / srv 0 / sys 44K / tmp 917M / usr 259M / var

So why is df showing wrong values? And how can I know what is actually taking up space?

2 Solutions collect form web for “df command does not show correct values”

A common programming technique is to create a temporary file and disconnect immediately (). This leaves the file (and its space) available while the program is running, but automatically causes it to be deleted when the program using it exits. One advantage is that no epilogue (cleanup) code is required to write.

To determine if you have a process containing open file, follow these steps:

Lsof -a + L1 / dev / server_slash

Lsof + D / dev / server_slash + L1

Find files with a null NLINK value (0). These will be files with zero link count, which will disappear when the last process finishes. The SIZE / OFFSET column will suggest the character size of the file in question.

1) df does not report space reserved for root (default 5%) on unix style filesystems. Therefore, df will always report less than it should.

2) However, I think you started your database without mounting srv-partition. Without the srv partition to be mounted, everything will be written to the mount point, i.e. to the srv directory in the / -section. (root partition), thus using up a lot of space on the / -section.

However, when you mount the srv partition in the srv directory, all files in the srv / -partition directory become the "hidden" partition that you "mounted on top", but still the space remains but you cannot see or access it. to remove it.

Try unmounting the srv-partition (go to singleuser-moder / runlevel 1 / maintenance mode so everything is stopped), make sure it is actually unmounted (with mount), and see if there are files hiding under the directories you normally use as mount points (usr, srv, home, var, tmp, ...) in the /-decomposition. I bet you find something big in some of them. When you're done and reboot, make sure srv-partition is actually installed as it should.

It is that you can have stuff in directories that are usually hidden by mountable partitions, which can sometimes be useful.

If you do not follow the remaining free space in root section- then unpleasant news may await you. If this section is full, services important for your project will stop working. Agree, non-working MySQL or web server will not affect the project in the best way.

One of better solutions This question will use some utilities that will help you determine what the problem is, what exactly is taking up disk space. The moment when it gradually fills up leads to difficulties in analyzing this problem. To do this, there are a number of commands that will help you monitor quickly. Most often, the culprit of this problem is a "daemon" that actively writes its actions to a log file (hello to people who do not configure the rotation of logs, or forget to turn off the mode debug in services after debugging).

Finding the largest files
At such moments the main task- quickly find the required free space. The easiest method is to use df together with du: #df -h- will show the location by section; #du -sh / directory occupied space by directory (key -s will remove the extra output).

The most likely culprit is / var / log second in place / home /, then go / backup & / var / www /... In the case when the log is to blame web-server "a, it is enough to delete or clear the log file. Please note that in cases where the file is held by a daemon (log apache) to recalculate free space it is worth pulling apache, you can reset the file following command # echo ‘’> /var/log/httpd/httpd.log.

If you have any questions about the total memory size, then you can use the command df -h and find out the amount of free space in the file system. So, let's begin:

# df -h Filesystem Size Used Avail Use% Mounted on / dev / mapper / vg0-root 53G 44G 6.2G 88% / tmpfs 939M 0 939M 0% / dev / shm / dev / vda1 485M 45M 415M 10% / boot / dev / mapper / vg0-temp 2.0G 75M 1.8G 4% / tmp
It is rare when df -h shows free 88% in the partition, but file creation is not possible. In this case, you should use df with key -i, command # df called with the given key will show the value of free inode for the file system.

# df -i Filesystem Inodes IUsed IFree IUse% Mounted on / dev / mapper / vg0-root 3506176 320241 3185935 10% / tmpfs 240295 1 240294 1% / dev / shm / dev / vda1 128016 44 127972 1% / boot / dev / mapper / vg0-temp 131072 275 130797 1% / tmp
By adding the key -l (local)- You will only see information about locally mounted file systems:

# df -hl Filesystem Size Used Avail Use% Mounted on / dev / mapper / vg0-root 53G 44G 6.2G 88% / tmpfs 939M 0 939M 0% / dev / shm / dev / vda1 485M 45M 415M 10% / boot / dev / mapper / vg0-temp 2.0G 75M 1.8G 4% / tmp
Using the command sort You are sorting the lines that go into all source files... If filenames are not specified, or if file is specified - , the initial information comes from the standard input. By adding the option -n(numeric comparison) with the help of which first the leading spaces are discarded, then the numeric character strings containing maybe a minus sign and a decimal point, you get the following result:

# df -hl | sort -n / dev / mapper / vg0-root 53G 45G 5.9G 89% / / dev / mapper / vg0-temp 2.0G 75M 1.8G 4% / tmp / dev / vda1 485M 45M 415M 10% / boot Filesystem Size Used Avail Use% Mounted on tmpfs 939M 0 939M 0% / dev / shm
Using the utility du (disk used) You get a report on disk space usage given files as well as each directory of the subdirectory hierarchy of each specified directory. If you run the command with no arguments, then the command du reports disk space for the current directory.

# du 8 ./.config/htop 12 ./.config 5056 ./.xmlcache/ispmgr/checked 15048 ./.xmlcache/ispmgr 752 ./.xmlcache/core/checked 4440 ./.xmlcache/core 1088 ./. xmlcache / ispmgrnode / checked 6780 ./.xmlcache/ispmgrnode 26284 ./.xmlcache 20 ./.ssh 168 ./.gem/specs/api.rubygems.org%443/quick/Marshal.4.8 172 ./.gem/specs /api.rubygems.org%443/quick 8376 ./.gem/specs/api.rubygems.org%443 8380 ./.gem/specs 8384 ./.gem 8 ./.spamassassin 4 ./.mc/cedit 32 ./.mc 12 ./mod
By adding the parameter - - time You will get data output with the specified time modifications.

# du --time. | sort -k2 | tail -5 5056 2015-07-29 17:11 ./.xmlcache/ispmgr/checked 20 2015-09-03 18:04 ./.ssh 4 2015-10-15 12:42 ./test 32 2015-10- 20 19:38 ./.mc 1245816 2015-11-06 13:50.
You can also search for large files using the command find:

# find. -size + 1M -ls | sort -n -k7 15089762 1264 -rw-r ----- 1 shs staff 1289365 Feb 24 2015 ./bin/235.log 12731834 1724 -rw-r ----- 1 shs staff 1761280 Oct 15 2015 ./ bin.tar 13320206 2192 -rw ------- 1 shs staff 2239058 Dec 8 2015 ./mail/lab7 13320203 6308 -rw ------- 1 shs staff 6443348 Oct 26 2015 ./mail/lab6 12731744 19736 -rw-r ----- 1 shs staff 20183040 Jul 29 2015 ./backup.tar
A handy utility for an overall assessment of the occupied space and cleaning up irrelevant data ncdu- provides a pseudographic interface and easy navigation. Of the minuses: not suitable for emergency situations described at the beginning of the article, because ncdu first, it calculates the entire volume of files on the specified disk (directories), and only after collecting the required information, it gives a result that you can work with.

P.S. We are holding an action specifically for Habr's readers.

Since disk storage is important issue There are many command or graphical tools that can tell you your current disk space usage. These tools output in detail disk use in a variety of human-readable formats such as easy-to-understand summaries, detailed statistics, or intuitive visualizations. If you just want to know how much free disk space is available for different filesystems, then perhaps the df command is all you need.

The df command can report disk usage across various "mounted" filesystems. There is different ways calling this command. Here are some helpful examples of using the df command.

Display in a human-readable format

By default, the df command reports disk space in 1K blocks, which are not easy to interpret. The "-h" option will make df's disk space output in a more readable format (eg 100K, 200M, 3G).

Show inode usage

When you monitor disk usage, you should look not only at disk space, but also inode usage. On Linux, an inode is a data structure used to store metadata. specific files, and when the filesystem is created, a predefined number of inodes are allocated. This means that the file system can grow out of size not only because of the use of large files all the available space, but also because all the available inodes are being used by small files. Use the "-i" option to display inode usage.

Show the total of all data

By default, the df command shows the use of individual filesystems. If you want to know general use disks of all existing file systems, add the "--total" option.

Df -h --total

Displaying file system types

By default, the df command does not display information about file system types. Use the "-T" option to add the file system type to the output.

Including or excluding a specific type of filesystem

If you want to know the free space on a particular filesystem type, use the "-t ". You can use this option many times to include more than one type of filesystem.

Df -t ext2 -t ext4

To exclude a specific type of filesystem, use the "-x ". You can also use this option many times.

Df -x tmpfs

Displaying the disk usage of a specific mount point

If you specify a mount point with df, it will display the disk usage of that filesystem mounted at that location. If you define instead of the mount point of this regular file(or directory), df will display the disk usage of the filesystem that includes this file (or directory).

Df / home /

Displaying information about bogus file systems

If you want to display disk space information for existing file systems, including bogus file systems, use the "-a" option. Here, bogus filesystems will refer to pseudo filesystems that do not have a corresponding physical device, such as tmpfs, virtual filesystem cgroup, or FUSE filesystems. These bogus filesystems are 0 in size and will not be reported by df without the "-a" option.







2021 gtavrl.ru.