Df (Unix)

Revision as of 21:00, 13 April 2025 by imported>Stevebroshar (Use block size instead of 512 since it varies)
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Template:Lowercase Template:Short description {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other df, short for disk free, is a shell command for reporting the amount of available storage space on file systems on which the user has read access. <syntaxhighlight lang="text" class="" style="" inline="1">df</syntaxhighlight> is typically implemented using the <syntaxhighlight lang="text" class="" style="" inline="1">statfs()</syntaxhighlight> or <syntaxhighlight lang="text" class="" style="" inline="1">statvfs()</syntaxhighlight> system calls.

The Single Unix Specification (SUS) specifies that space is reported in blocks of 512 bytes, and that at a minimum, it reports the file system names and the amount of free space.

Using 512-bytes as the unit of measure is a historical practice and maintains compatibility with ls and other commands. Notably, the file system need not be constrained to internally use 512-byte blocks. The <syntaxhighlight lang="text" class="" style="" inline="1">-k</syntaxhighlight> option was added as a compromise measure. It was agreed by the standard developers that 512 bytes was the best default unit because of its complete historical consistency on System V (versus the mixed 512/1024-byte usage on BSD systems), and that a <syntaxhighlight lang="text" class="" style="" inline="1">-k</syntaxhighlight> option to switch to 1024-byte units was a good compromise. Users who prefer the more logical 1024-byte quantity can use alias to map <syntaxhighlight lang="text" class="" style="" inline="1">df</syntaxhighlight> to <syntaxhighlight lang="text" class="" style="" inline="1">df -k</syntaxhighlight> without breaking many historical scripts relying on the 512-byte units.

The output with <syntaxhighlight lang="text" class="" style="" inline="1">-P</syntaxhighlight> consists of one line of information for each specified file system, like:

Template:Angbr Template:Angbr Template:Angbr Template:Angbr Template:Angbr Template:Angbr

where:

Template:Angbr
The name of the file system, in an implementation-defined format.
Template:Angbr
The total size of the file system in block size units. The exact meaning of this figure is implementation-defined, but should include Template:Angbr, Template:Angbr, plus any space reserved by the system not normally available to a user.
Template:Angbr
The total amount of space allocated to existing files in the file system, in block size units.
Template:Angbr
The total amount of space available within the file system for the creation of new files by unprivileged users, in block size units. When this figure is less than or equal to zero, it shall not be possible to create any new files on the file system without first deleting others, unless the process has appropriate privileges. The figure written may be less than zero.
Template:Angbr
The percentage of the normally available space that is currently allocated to all files on the file system. This shall be calculated using the fraction:
Template:Sfrac
expressed as a percentage. This percentage may be greater than 100 if Template:Angbr is less than zero. The percentage value shall be expressed as a positive integer, with any fractional result causing it to be rounded to the next highest integer.
Template:Angbr
The directory below which the file system hierarchy appears

HistoryEdit

The command first appeared in Version 1 AT&T Unix.<ref>Template:Man</ref> The command is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX and the Single Unix Specification (SUS).<ref>Template:Man</ref> The implementation of <syntaxhighlight lang="text" class="" style="" inline="1">df</syntaxhighlight> bundled in GNU coreutils was written by Torbjorn Granlund, David MacKenzie, and Paul Eggert.<ref>Template:Man</ref> The command is available for Windows via UnxUtils.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

UseEdit

SUS specifies syntax:

df [-k] [-P|-t] [-del] [file...]
<syntaxhighlight lang="text" class="" style="" inline="1">-k</syntaxhighlight>
Use 1024-byte units, instead of the default 512-byte units, when writing space figures
<syntaxhighlight lang="text" class="" style="" inline="1">-P</syntaxhighlight>
Use a standard, portable, output format
<syntaxhighlight lang="text" class="" style="" inline="1">file</syntaxhighlight>
Select the storage for the file system containing the specified file

Most implementations include extra options. The BSD and GNU coreutils versions include <syntaxhighlight lang="text" class="" style="" inline="1">-h</syntaxhighlight> (human-readable) which selects to format sizes in metric units (e.g. 10 MB), <syntaxhighlight lang="text" class="" style="" inline="1">-i</syntaxhighlight> which lists inode usage, and <syntaxhighlight lang="text" class="" style="" inline="1">-l</syntaxhighlight> which restricts reporting to local filesystems. The GNU implementation includes <syntaxhighlight lang="text" class="" style="" inline="1">-T</syntaxhighlight> which includes filesystem type information.

ExamplesEdit

Example output from the <syntaxhighlight lang="text" class="" style="" inline="1">df</syntaxhighlight> command:

<syntaxhighlight lang="console"> $ df Filesystem 1K-blocks Used Available Use% Mounted on udev 48764976 0 48764976 0% /dev tmpfs 9757068 173100 9583968 2% /run /dev/sda2 1824504008 723009800 1008791744 42% / tmpfs 48785328 0 48785328 0% /dev/shm tmpfs 5120 0 5120 0% /run/lock tmpfs 48785328 0 48785328 0% /sys/fs/cgroup /dev/sda1 523248 3672 519576 1% /boot/efi $ df -i Filesystem Inodes IUsed IFree IUse% Mounted on udev 12191244 500 12190744 1% /dev tmpfs 12196332 702 12195630 1% /run /dev/sda2 115859456 2583820 113275636 3% / tmpfs 12196332 1 12196331 1% /dev/shm tmpfs 12196332 5 12196327 1% /run/lock tmpfs 12196332 16 12196316 1% /sys/fs/cgroup /dev/sda1 0 0 0 - /boot/efi $ df -h Filesystem Size Used Avail Use% Mounted on udev 47G 0 47G 0% /dev tmpfs 9.4G 170M 9.2G 2% /run /dev/sda2 1.7T 690G 963G 42% / tmpfs 47G 0 47G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 47G 0 47G 0% /sys/fs/cgroup /dev/sda1 511M 3.6M 508M 1% /boot/efi </syntaxhighlight>

See alsoEdit

ReferencesEdit

Template:Reflist

External linksEdit

Template:Sister project

Manual pagesEdit

Template:Unix commands Template:Core Utilities commands