Terminal GuideTerminal Guide

ls Command Guide

The ls command is one of the most frequently used commands in Linux. Learn how to list directory contents effectively with various options.

5 min readLast updated: January 19, 2025
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

lsList current directory
ls /pathList specific path
ls *.txtList files matching pattern

Display

-lLong format with details
-aShow hidden files
-hHuman-readable sizes

Sorting

-tSort by modification time
-SSort by file size
-rReverse sort order

Common Combos

ls -laAll files with details
ls -lhDetails with readable sizes
ls -ltDetails sorted by time

Downloadable Image Preview

Failed to generate preview

Basic Usage

The ls command lists information about files and directories. By default, it lists the contents of the current directory.

bash
ls

You can also specify a path to list:

bash
ls /home/user/documents

Common Options

ls has many options to customize its output. Here are the most commonly used ones.

Long listing format (-l)

bash
ls -l

Shows detailed information including permissions, owner, size, and modification date.

Show hidden files (-a)

bash
ls -a

Lists all files including hidden files (those starting with a dot).

Human-readable sizes (-h)

bash
ls -lh

Displays file sizes in human-readable format (K, M, G).

Sort by time (-t)

bash
ls -lt

Sorts files by modification time, newest first.

Common Options

-lLong listing format with details
-aShow all files including hidden
-hHuman-readable file sizes
-tSort by modification time
-rReverse order
-SSort by file size
-RList subdirectories recursively

Practical Examples

List all files with details

bash
ls -la

List only directories

bash
ls -d */

List files sorted by size

bash
ls -lhS

List recently modified files

bash
ls -lt | head -10

List files with specific extension

bash
ls *.txt
Tip
Combine options like ls -lahS to show all files with human-readable sizes, sorted by size.

Understanding the Output

When using ls -l, each line shows:

bash
-rw-r--r-- 1 user group 4096 Jan 15 10:30 file.txt
drwxr-xr-x 2 user group 4096 Jan 15 10:30 directory/
  • File type and permissions (-rw-r--r--)
  • Number of hard links
  • Owner name
  • Group name
  • File size in bytes
  • Last modification date and time
  • File or directory name
Info
The first character indicates the file type: - for regular files, d for directories, and l for symbolic links.

Summary

The ls command is essential for navigating and understanding your filesystem. Key takeaways:

  • Use ls -l for detailed file information
  • Use ls -a to see hidden files
  • Combine options like ls -lah for complete listings
  • Use ls -lt to find recently modified files

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles