Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink
A file's name or extension alone does not establish its type in Linux. ls -l shows its file-system type and basic attributes, file examines content to infer a format, and stat displays metadata such as size, permissions, timestamps, and inode. This lesson explains what each result does—and does not—tell you.
What a Linux file type means
Linux file-system entries include ordinary files, directories, symbolic links, and devices. The first character of an ls -l output row identifies the entry's type. An extension such as .txt or .jpg is merely part of the name; it is not this file-system type indicator.
| First character | Type | Example |
|---|---|---|
- |
Regular file | Document or executable file |
d |
Directory | Path containing other entries |
l |
Symbolic link | Entry pointing to another path |
c, b |
Character or block device | Device entries under /dev |
p, s |
FIFO (named pipe) or socket | Entries used for interprocess communication |
Specify a target with ls -ld when you want to inspect that entry itself. Running ls -l on a directory can list its contents instead of showing a row for the directory.
ls -ld /etc /etc/passwd
The /etc row normally starts with d, and the /etc/passwd row with -. The remaining columns include permissions, link count, owner, group, size, modification time, and name. Actual values and display details vary by system.
Use file to infer a content format
file examines file-system information and characteristics of a file's content, then gives a human-readable description. Even without an extension, /etc/passwd may be recognized as text.
file /etc/passwd
Output might resemble the following; the wording varies with encoding and implementation.
/etc/passwd: ASCII text
This is a classification based on inspection, not an infallible certification of a file's contents. The detail reported for text encoding or other formats depends on detection rules. For a symbolic link, whether file inspects the link or its target also depends on options and environment; compare file -h link with file -L link.
Use stat to inspect metadata
stat reports information maintained by the file system, not the file's text or other content. It can show size, permissions, owner, inode number, link count, and several timestamps. An inode is a file-system structure used to manage an entry's metadata; it is distinct from the entry's name.
stat /etc/passwd
For a shorter output, GNU stat supports -c with a format string. Here %F is the file type, %s its size in bytes, and %n its name.
stat -c '%F | %s bytes | %n' /etc/passwd
The result is one line like the example below. 1234 is an illustrative size, not a measurement of your file; the actual size and display language can differ.
regular file | 1234 bytes | /etc/passwd
The first field identifies a regular file, the middle field gives its size in bytes, and the last field is the path examined. In the full stat output, Access, Modify, Change, and Birth timestamps have different meanings. In particular, do not read Change as the creation time: it concerns metadata changes. Birth may be unavailable on a particular file system or through a particular tool.
When you encounter a symbolic link
A symbolic link is a separate entry that refers to another path. ls -l commonly shows it as link -> target. readlink link prints the path string stored in the link. If that string is relative, interpret it from the directory containing the link, not your shell's current directory.
The link's metadata differs from the target file's metadata. GNU stat normally examines the link itself; use -L to follow it to the target. Following a broken link can fail. The links lesson covers creating links for practice.
Which command should you choose?
- Type and basic attributes in a listing:
ls -l, orls -ldto inspect the named entry itself. - Likely content format:
file. - Detailed size, timestamps, inode, and other attributes:
stat. - Path string stored in a symbolic link:
readlink.
For more examples, read the guides to file, stat, and readlink.
Official documentation
Check the file(1) manual, the GNU stat documentation, and the GNU readlink documentation for options and exceptions.









