Reading File Metadata with `ls` and `stat`
Learn to read Unix-like long listings and use `ls` and `stat` to inspect file metadata, including ownership, size, and symbolic links.
Reading a Long Listing and Inspecting Metadata
Read the fields from left to right
Use ls -l for a quick overview of file metadata. In a regular file’s long listing, the first field gives the object type and permissions; the remaining fields show hard-link count, owner, group, size, modification time, and name.
For example:
-rw-r----- 1 maya staff 840 Apr 11 16:05 notes.txt
Read this as: - marks a regular file, followed by its permission characters; 1 is the hard-link count; maya is the owner; staff is the group; 840 is the size, normally in bytes; Apr 11 16:05 is the modification time; and notes.txt is the name. The date shown is the modification time, not a general label for every kind of timestamp.
A directory entry has d as its type marker. For example, drwxr-x--- ... reports describes the directory object. Its displayed size is not the combined size of everything inside it. To inspect the directory itself rather than list its contents, use ls -ld reports.
Inspect links, ownership, and size carefully
A symbolic link’s name is followed by -> and its target, as in latest -> notes.txt. On GNU/Linux, stat normally reports the link itself; stat -L latest follows the link and reports its target instead. Use stat notes.txt when you need a more detailed file-status report. Exact output and options can vary across Unix-like systems.
Owner and group fields usually display account names. If names cannot be resolved—or numeric output is requested—the listing may show user and group IDs instead. GNU ls -n requests numeric IDs.
The size from ls -l is normally the file’s logical size in bytes. GNU ls -lh displays a scaled, human-readable size. Neither display should automatically be read as the disk space allocated: sparse files or filesystem allocation behavior can make logical size and allocated space differ.