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 / Option | Description |
|---|---|
| stat file | Displays detailed information about a file: inode number, size, permissions, and timestamps (access / modify / change). |
| stat -c "%s" file | Outputs only the file size in bytes. Useful inside scripts. |
| file file | Analyzes the file contents and reports its type (text, ELF binary, image, etc.). |
| du directory | Shows the disk usage of each file and subdirectory under the given directory. |
| du -s path | Shows only the total size without expanding subdirectories. |
| du -sh path | Shows the total size in a human-readable unit (K, M, G). |
| du -h --max-depth=1 | Expands only one level deep and shows the size of each entry. |
| du -sh * | sort -h | Lists all entries in the current directory sorted by size. |
| df | Shows the mount status, used space, and available space for all file systems. |
| df -h | Displays sizes in human-readable units. |
| df -T | Also shows the file system type (ext4, xfs, tmpfs, etc.). |
Sample Code
The examples below use the following directory structure.
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 contact us.