Skip to content

The ls command

List the files and folders in a directory. Lists the contents of each directory you name, or the current directory when you name none. Names that start with a dot are hidden unless you ask for them with -a or -A. In the terminal, folders are shown in blue and programs you can run in green.

Usage

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

Options

-a, --allshow every entry, including hidden ones and the . (this folder) and .. (parent folder) entries
-A, --almost-allshow hidden entries, but not . and ..
-llong format: permissions, links, owner, group, size, date and name, one per line
-h, --human-readablewith -l, show sizes as 1.5K or 2.0M instead of bytes
-tsort by modification time, newest first
-Ssort by size, largest first
-r, --reversereverse the sort order
-R, --recursivelist folders inside folders, all the way down
-d, --directorylist a folder itself, not what is inside it
-F, --classifyadd / after folders and * after programs
-1one name per line

Examples

  • lsWhat is in the current folder
  • ls -laEverything, hidden files too, with details
  • ls -lh /var/logThe log folder with readable sizes
  • ls *.txtOnly the names that end in .txt

Learn it step by step

learner@sandbox: ~bash (practice)
Note: Try ls here: your home directory has sample files. Press Try beside an example, or type your own.

A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.