Home·Terminal commands

ls

Files and directories

Usage

ls -la [path]

Lists what a directory holds; names that begin with a dot stay hidden until you add -a.

Common flags

FlagMeaning
-lOne line per entry with mode, owner, size and time
-aInclude names that begin with a dot
-hSizes as 4.0K instead of 4096, together with -l
-tSort by modification time, newest first
-rReverse whatever order is in effect
-SSort by size, largest first
-RWalk into subdirectories
-dShow the directory itself instead of its contents

Examples

ls -lh

Long listing with readable sizes.

ls -lat

Newest first, hidden files included.

ls -d */

Only the directories in this folder.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does ls do?

Lists what a directory holds; names that begin with a dot stay hidden until you add -a.

Q. How do I type it?

ls -la [path] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

8 are listed here; the full set is in man ls. This command sits under Files and directories.

Related commands

man page: man ls