Getting Detailed Metadata
The stat command provides complete metadata including access, modify, change times, and inode.
Syntax:
stat [filename]Example
$ stat myfile.txtOutput:
File: myfile.txt
Size: 1024 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 131080 Links: 1
Access: 2025-07-22 10:12:05.000000000 +0530
Modify: 2025-07-22 10:10:01.000000000 +0530
Change: 2025-07-22 10:11:00.000000000 +0530
Birth: -Explanation:
| Field | Meaning |
|---|---|
| Size | File size in bytes |
| Blocks | Number of 512-byte blocks allocated |
| IO Block | Optimal block size for I/O |
| Device | Device ID of filesystem |
| Inode | Inode number |
| Links | Number of hard links |
| Access | Last time file was read |
| Modify | Last time file was content-modified |
| Change | Last time metadata (permissions, ownership) was changed |
Determining File Type Using file Command
The file command is used to identify the type of a file by examining its content, not its extension.
Syntax
file [filename]Example
$ file myfile.txtOutput:
myfile.txt: ASCII textExamples
$ file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, dynamically linked, ...
$ file image.png
image.png: PNG image data, 800 x 600, 8-bit/color RGB, non-interlacedExplanation:
- Text files show as
ASCII text,UTF-8 Unicode text, etc. - Executables show ELF format, architecture.
- Images display format (e.g., PNG, JPEG), dimensions, encoding.
Using ls -i to See Inode Number
Inodes store all metadata (except filename and content). To view the inode:
$ ls -i myfile.txt
131080 myfile.txt131080is the inode number — useful when tracking hard links.
Summary Table
| Command | Purpose | Example |
|---|---|---|
ls -l | List metadata like permissions, size | ls -l file.txt |
stat | Detailed metadata including timestamps | stat file.txt |
file | Determine file type | file file.txt |
ls -i | Show inode number | ls -i file.txt |
Last updated on