ls -t Command

The ls -t command in Linux is used to list files and directories sorted by their last modification time, with the newest files appearing first. This is incredibly useful for quickly identifying recently changed files, especially in busy directories or when debugging.

Syntax

ls -t [OPTION]... [FILE]...

Description

By default, ls sorts entries alphabetically. The -t (or --sort=time) option changes this behavior to sort by modification time. The most recently modified files and directories will be listed at the top. This is often combined with other options for more specific sorting and display formats.

Key aspects of ls -t:

  • Sorts by modification time (mtime) by default.
  • Newest files/directories are listed first.
  • Useful for checking recent activity or changes.
  • Can be combined with -r to reverse the order (oldest first).

Common Options (with -t)

Option Description
-l Use a long listing format (e.g., ls -lt).
-r, --reverse Reverse order while sorting (oldest first when combined with -t).
-a, --all Do not ignore entries starting with . (hidden files).
-h, --human-readable With -l, print sizes in human readable format (e.g., 1K, 234M, 2G).
--time=atime Sort by access time instead of modification time.
--time=ctime Sort by change time (status information) instead of modification time.

Examples

List files by modification time (newest first)

ls -t
# Example Output: # new_report.txt latest_log.log old_document.txt

Displays files and directories, with the most recently modified at the top.

Long listing sorted by modification time

ls -lt

Provides detailed information in long format, sorted by modification time (newest first).

List files by modification time (oldest first)

ls -ltr

Combines -l, -t, and -r to show a detailed listing with the oldest files at the top.

List all files (including hidden) sorted by modification time

ls -at

Displays all files, including hidden ones, sorted by their last modification time (newest first).

Sort by access time (newest accessed first)

ls -ltu

Uses the -u option with -t to sort by access time instead of modification time.

See also