ls Command

The ls command lists directory contents in Linux. It's one of the most frequently used commands for exploring the file system.

Syntax

ls [OPTION]... [FILE]...

Description

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

Key features:

  • Lists files and directories
  • Shows file permissions and ownership
  • Displays file sizes and timestamps
  • Can show hidden files
  • Supports various sorting options

Common Options

Option Description
-l Long format (detailed information)
-a Show all files (including hidden)
-h Human-readable file sizes
-r Reverse order
-t Sort by modification time
-S Sort by file size
-R Recursive (list subdirectories)

Examples

Basic listing

ls

Lists files and directories in current directory

Long format listing

ls -l

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

Show all files (including hidden)

ls -a

Displays all files including those starting with a dot

Long format with hidden files

ls -la

Combines long format with showing all files

Human-readable file sizes

ls -lh

Shows file sizes in KB, MB, GB format

Sort by modification time

ls -lt

Lists files sorted by modification time (newest first)

Sort by file size

ls -lS

Lists files sorted by size (largest first)

Reverse order

ls -lr

Lists files in reverse alphabetical order

List specific directory

ls /home/user/Documents

Lists contents of specified directory

Recursive listing

ls -R

Lists all files and subdirectories recursively

See also