Explaining ls command options Explaining ls command options | Zhiwei Li

Explaining ls command options | Generated by AI

Home 2026.04

Question: Explain the ls command options like -l, -h, -c, -u, etc.


Answer:

These flags modify how the Unix/Linux ls command displays file information. Here’s a clear breakdown:

Core Format Option

  • -l (long listing format) Shows detailed information about files:

    • File permissions (e.g., -rw-r--r--)
    • Number of links
    • Owner name
    • Group name
    • File size
    • Timestamp (depends on other flags)
    • File name

    Example:

    ls -l file.txt
    

Size Formatting

  • -h (human-readable) Converts file sizes into easy-to-read formats:

    • Bytes → KB, MB, GB, etc.
    • Example: 10241.0K

    Usually combined with -l:

    ls -lh
    

Time Display Modifiers

By default, ls -l shows mtime (modification time) — when file content was last changed.

These options change which timestamp is shown:

  • -c (change time / ctime) Shows when file metadata last changed:

    • Permissions
    • Ownership
    • Links
    • Also updated when content changes

    Example:

    ls -lc file.txt
    

  • -u (access time / atime) Shows last time the file was accessed (read/opened)

    Example:

    ls -lu file.txt
    

Common Combinations You Saw

  • ls -lh → Long format + human-readable size + mtime

  • ls -lhc → Long format + human-readable + ctime

  • ls -lhu → Long format + human-readable + atime


Quick Summary Table

Option Meaning Effect
-l Long format Detailed file info
-h Human-readable Friendly file sizes
-c Change time Show ctime
-u Access time Show atime

Important Concept: mtime vs ctime vs atime

  • mtime → File content changed
  • ctime → File metadata changed (permissions, owner, etc.)
  • atime → File accessed/read

Small Insight (Practical Use)

  • Use mtime → tracking file updates (most common)
  • Use ctime → detecting permission/ownership changes
  • Use atime → rarely reliable (often disabled for performance)

If you want, I can explain how stat shows all three timestamps in one command (very useful for debugging file changes).