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
| Flag | Meaning |
|---|---|
| -l | One line per entry with mode, owner, size and time |
| -a | Include names that begin with a dot |
| -h | Sizes as 4.0K instead of 4096, together with -l |
| -t | Sort by modification time, newest first |
| -r | Reverse whatever order is in effect |
| -S | Sort by size, largest first |
| -R | Walk into subdirectories |
| -d | Show the directory itself instead of its contents |
Examples
ls -lhLong listing with readable sizes.
ls -latNewest 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