ls – List Files and Directories

The ls command (short for “list”) displays the contents of a directory. It is one of the most fundamental and frequently used commands in Unix-like operating systems such as Linux, BSD and macOS.


Syntax

ls [OPTION]... [DIRECTORY]...
  • If no directory is specified, ls lists the contents of the current directory.

Common Options

Option Description
-l Use a long listing format
-a Show all files, including hidden files (starting with .)
-h With -l, print sizes in human-readable format (e.g., 1K, 234M)
-S Sort by file size, largest first
-t Sort by modification time, newest first
-r Reverse the order of the sort
-d List directories themselves, not their contents
-R List directories recursively
-i Show the inode number of each file
--color=auto Display files in color depending on type and permissions (if supported)

Practical Examples

1. List all files including hidden ones in long format

ls -la

Sample Output:

drwxr-xr-x  5 owner group     4096 Mar 19 21:30 .
drwxr-xr-x  4 owner group     4096 Mar 17 00:05 ..
drwxr-xr--  5 owner group     4096 Mar 17 2010 Artwork-Themes
-rw-r--r--  1 owner group      337 Mar 17 10:36 .bash_aliases
-rw-------  1 owner group      284 Mar 17 22:39 .bash_history
-rw-r--r--  1 owner group      414 Mar 17 00:05 .bash_profile
-rw-r--r--  1 owner group      261 Mar 19 10:37 .bashrc
-rw-rw-r--  1 owner group   164926 May 18 2010 documentation.pdf
Column Meaning
drwxr-xr-x File type and permissions
5 Number of hard links
owner File owner
group File group
4096 File size in bytes
Mar 19 21:30 Last modification time
. File or directory name

2. Display only directories in the current folder

ls -ld */

Sample Output:

drwxr-xr-x 6 user group 4096 Sep 23  2020 Pictures/
drwxr-xr-x 6 user group 4096 Apr  4 09:19 Documents/
drwxr-xr-x 2 user group 4096 Aug 22 08:09 Downloads/
...

3. Show file sizes in a human-readable format

ls -lh

4. Sort files by size

ls -lS

5. Sort files by modification date (newest first)

ls -lt

6. List all files in all subdirectories recursively

ls -R

7. Show inode numbers

ls -li

8. Colorized output (usually default in modern terminals)

ls --color=auto

Or with aliases:

alias ls='ls --color=auto'
alias ll='ls -lah --color=auto'

Tips

  • Combine options for more powerful listing, e.g.:
ls -lahS
  • To make colorized ls permanent, add the alias to your ~/.bashrc or ~/.zshrc.

See Also

  • man ls – for the full manual
  • tree – visual directory tree
  • find – advanced search in directories