How to calculate Use% of df command

If it is completely disk full, it will be a later festival, so I recognize that it is displayed with a little buffer, but how is it actually? When I calculate it, it doesn't fit.

$ df  /
Filesystem              1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root  30909700 14577164  16332536  48% /

The display of df is 48%, but (use * 100) / (Used + Available) This calculation gives 47%.

echo "(14577164 * 100) / (14577164 + 16332536)" | bc
47

Let's try core-utils.

df.c


        case PCENT_FIELD:
        case IPCENT_FIELD:
          {
            double pct = -1;
            if (! known_value (v->used) || ! known_value (v->available))
              ;
            else if (!v->negate_used
                     && v->used <= TYPE_MAXIMUM (uintmax_t) / 100
                     && v->used + v->available != 0
                     && (v->used + v->available < v->used)
                     == v->negate_available)
              {
                uintmax_t u100 = v->used * 100;
                uintmax_t nonroot_total = v->used + v->available;
                pct = u100 / nonroot_total + (u100 % nonroot_total != 0);
              }

Is it a feeling that it is generally +1? In the first place, this (u100% nonroot_total! = 0) returns 0 or 1.

$ cat x.c
#include <stdio.h>
int main(void)
{
  printf("%d\n", (0 != 0));
  printf("%d\n", (1 != 0));
}
$ gcc x.c
$ ./a.out
0
1

Recommended Posts

How to calculate Use% of df command
Summary of how to use pandas.DataFrame.loc
Summary of how to use pyenv-virtualenv
How to use MBDyn (command setting)
Summary of how to use csvkit
[Python] Summary of how to use pandas
[python] How to use __command__, function explanation
[Linux] How to use the echo command
How to use the Linux grep command
[Python2.7] Summary of how to use unittest
Jupyter Notebook Basics of how to use
How to use CUT command (with sample)
Basics of PyTorch (1) -How to use Tensor-
Summary of how to use Python list
[Python2.7] Summary of how to use subprocess
[Question] How to use plot_surface of python
How to use xml.etree.ElementTree
How to use virtualenv
How to use Seaboan
How to use image-match
How to use shogun
How to use Pandas 2
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use Bio.Phylo
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
How to use Pyenv
How to use list []
How to use python-kabusapi
How to use OptParse
How to use return
How to use dotenv
How to use pyenv-virtualenv
How to use Go.mod
How to use imutils
How to use import
How to calculate the volatility of a brand
How to use folium (visualization of location information)
A simple example of how to use ArgumentParser
[Python] How to use two types of type ()
Not much mention of how to use Pickle
Summary of how to use MNIST in Python
[For beginners] How to use say command in python!
How to use search sorted
[gensim] How to use Doc2Vec
A memo of how to use AIST supercomputer ABCI
I tried to summarize how to use matplotlib of python
Understand how to use django-filter
How to use the generator