Home > File & Directory Management > ls-t

ls-t: (Non-standard) List files by time

ls-t is not a standard Linux command, but it is commonly used as an alias or custom script for the 'ls -t' command. 'ls -t' displays files and subdirectories in a directory, sorted by their last modification time.

Overview

ls-t is a shorthand for 'ls -t', which sorts and displays file system entries by modification time in descending order (most recently modified files first). This is useful for quickly finding recently worked-on files or tracking changes in a specific directory. ls-t itself is not a built-in command, so users must set up an alias for it.

Key Features

  • Sort by modification time (newest first)
  • Quickly identify recently changed files
  • Can be combined with various ls command options

Installation

Since ls-t is not a built-in command, users need to set up a shell alias or create a script. The most common method is using a shell alias.

Setting up an Alias

To use ls-t in bash or zsh shells, add the following line to your shell configuration file (e.g., ~/.bashrc, ~/.zshrc).

echo "alias ls-t='ls -t'" >> ~/.bashrc
source ~/.bashrc

Alias setup command

Explanation

The command above links the alias `ls-t` to the `ls -t` command. You can apply the changes immediately by running `source ~/.bashrc` or by opening a new terminal.

Usage Examples

ls-t behaves identically to 'ls -t' and can be used in combination with various ls options.

List files sorted by most recent modification

ls-t

Lists files in the current directory, sorted from the most recently modified to the oldest.

View in time order with detailed information

ls-t -l

Lists files in time order, including detailed information such as permissions, owner, and size.

View in time order with detailed information and human-readable sizes

ls-t -lh

Displays file sizes in KB, MB, etc., for better readability, along with detailed information and time order.

List files sorted by oldest first

ls-t -r

Reverses the default sorting order (newest first) to list files from oldest to newest.

List files including hidden files, sorted by time

ls-t -a

Lists hidden files and directories (starting with '.') along with other files, sorted by modification time.

Tips & Notes

Tips and notes for effectively using ls-t (i.e., ls -t).

Sorting Order

ls -t by default lists files from the most recently modified to the oldest. To view files from oldest to newest, use the `-r` (reverse) option.

  • Newest first (default): `ls-t`
  • Oldest first: `ls-t -r`

Directory Sorting

ls -t sorts both files and directories by their modification time. The modification time of a directory itself may differ from the modification times of its contents.

Other Time Criteria

Besides modification time, ls can also sort by access time (-u) or creation time (-U, on some systems). Utilize these options as needed.

  • Sort by access time: `ls -tu`
  • Sort by creation time (Linux): `ls -l --time=ctime`

Alias Management

Aliases are only applied to the current shell session. To use them permanently, you must add them to your shell configuration file (e.g., ~/.bashrc, ~/.zshrc). If you use multiple shells, you need to add the alias to each shell's configuration file.


Same category commands