$linuxjunkies
>

ls(1)

List directory contents and file information.

UbuntuDebianFedoraArch

Synopsis

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

Description

Lists files and directories in a directory. By default, output is sorted alphabetically and displayed in columns. When no FILE is specified, lists the current directory.

Most commonly used with flags to control output format, sorting, and what file metadata to display. Can operate recursively and show hidden files.

Common options

FlagWhat it does
-llong format; display permissions, owner, size, modification time, and filename
-ashow all files, including those starting with a dot (.hidden files)
-hprint file sizes in human-readable format (K, M, G) instead of bytes
-Rrecursively list subdirectories and their contents
-tsort by modification time (newest first)
-Ssort by file size (largest first)
-rreverse sort order
-dlist directories themselves, not their contents
-iprint inode number before each filename
-1list one file per line (useful for scripts)

Examples

Show all files in long format, including hidden files and their full details

ls -la

List all .txt files in long format with human-readable file sizes

ls -lh *.txt

List files sorted by size in ascending order (smallest first)

ls -lSr

Show 10 most recently modified files in long format

ls -lt | head -10

Recursively list all files and directories under /home/user/project

ls -R /home/user/project

List only subdirectories, not their contents

ls -d */

List files with directories shown first, human-readable sizes

ls -lh --group-directories-first

Count the number of .jpg files using one-per-line format

ls -1 *.jpg | wc -l

Related commands