Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. Bash Dictionary
  3. stat / file / du / df

stat / file / du / df

stat displays detailed metadata about a file, file identifies the file type, du reports disk usage, and df shows the available space on file systems.

Syntax

stat [option] file
file [option] file
du [option] [path...]
df [option] [filesystem...]

Commands and Options

Command / OptionDescription
stat fileDisplays detailed information about a file: inode number, size, permissions, and timestamps (access / modify / change).
stat -c "%s" fileOutputs only the file size in bytes. Useful inside scripts.
file fileAnalyzes the file contents and reports its type (text, ELF binary, image, etc.).
du directoryShows the disk usage of each file and subdirectory under the given directory.
du -s pathShows only the total size without expanding subdirectories.
du -sh pathShows the total size in a human-readable unit (K, M, G).
du -h --max-depth=1Expands only one level deep and shows the size of each entry.
du -sh * | sort -hLists all entries in the current directory sorted by size.
dfShows the mount status, used space, and available space for all file systems.
df -hDisplays sizes in human-readable units.
df -TAlso shows the file system type (ext4, xfs, tmpfs, etc.).

Sample Code

The examples below use the following directory structure.

📁 ~/project/ 📁 images/ 📄 photo.jpg (3.2MB) 📁 logs/ 📄 app.log (128KB) 📄 deploy.sh (1KB) 📄 data.bin (binary)

Display detailed metadata for a file.

stat deploy.sh
  File: deploy.sh
  Size: 1024         Blocks: 8    IO Block: 4096   regular file
Device: fd01h/64769d Inode: 123456     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/  user)   Gid: ( 1000/  user)
Access: 2026-03-05 10:00:00.000000000 +0900
Modify: 2026-03-05 09:30:00.000000000 +0900

Identify the file type. The result is based on the file contents, not the extension.

file deploy.sh
deploy.sh: Bourne-Again shell script, ASCII text executable
file data.bin
data.bin: ELF 64-bit LSB shared object, x86-64
file images/photo.jpg
images/photo.jpg: JPEG image data, JFIF standard 1.01

Show the total size of the current directory in a human-readable format.

du -sh .
3.4M    .

Check the size of each subdirectory one level deep. Useful for tracking down large directories.

du -sh */
3.2M    images/
128K    logs/

Sort all entries by size to see which ones are largest.

du -sh * | sort -h
1.0K    deploy.sh
4.0K    data.bin
128K    logs
3.2M    images

Check available space on all file systems.

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   18G   30G  38% /
tmpfs           2.0G  1.2M  2.0G   1% /run

Show only the file system that contains a specific path.

df -h /var
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   18G   30G  38% /

Notes

du -sh * | sort -h is extremely handy for finding directories that are consuming disk space. When a server is running low on disk, the standard approach is to first run df -h to get the big picture, then use du -sh */ to narrow down which directories are the largest.

See also ls -lh for listing files.

If you find any errors or copyright issues, please .