Linux File Types and Metadata
How it works
A Linux filesystem stores different kinds of objects: regular files, directories, symbolic links, FIFOs (named pipes), sockets and block or character devices. A filename extension is a convention, not proof of content. file PATH attempts to classify an object using its type and, where appropriate, content patterns. stat PATH reports metadata such as size, inode number, ownership, permissions and timestamps. Modification time (mtime) records content changes, access time (atime) records access subject to filesystem and mount policies, and status-change time (ctime) records inode metadata changes, not creation. Birth time may be unavailable. A directory’s reported size is not the sum of its files.
Prepare a safe practice environment
Use GNU/Linux and Bash as a normal user. From the extracted package root run bash lab-fixtures/files/setup.sh. It prints a fresh private directory under /tmp. Copy that path and enter it with cd (quote the path if needed); check pwd. Each code example below starts in a new lab with the same fixture: notes/hello.txt, notes/daily report.txt, notes/-draft, notes/.hidden, and empty directories archive and empty. Set export LC_ALL=C for the shown ordering and English diagnostics. Never run the modifying examples on your own files.
Identify content and directory types
For this fixture the outputs are ASCII text and directory. Exact content descriptions depend on the file utility and its magic database.
Read selected metadata
GNU stat reports regular file 6: five letters plus the newline occupy six bytes. %F is the type and %s the size in bytes.
The newline is part of the stored data even though it is not shown as a letter. Here each of the five ASCII letters uses one byte, so adding the newline gives six. For multilingual text, a visible character may need more than one byte; file size and character count answer different questions.
Inspect inode and link count
The inode number is assigned by the filesystem and varies. This fresh regular file has one hard link.
Common mistakes and safe habits
Do not interpret ctime as creation time or assume that reading always updates atime immediately. file classifies content heuristically; it is not a security scanner. Avoid reading device files or unknown special files to identify them. GNU stat -c is not the same interface as BSD stat.
Try it yourself
Compare file -b and stat -c for notes/hello.txt and notes. Explain why size and file type are different kinds of information.
Use a fresh lab for the practice. When finished, return to the lab root if you are in a subdirectory, then leave it with cd ... Remove only the identified temporary lab folder using your file manager if desired. Never remove an unrelated path.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
File types and metadata — Knowledge Check
Apply filesystem concepts in a fresh disposable Linux lab.
What does GNU stat %s report for a regular file?
What does ctime represent?
What does file attempt to identify?
Does a .txt extension prove the data is text?
Why might atime not change after a read?