Navigation and files

Command ls

Show directory contents

Linux · Bash examples · commands run on the selected server

When to use ls

Use ls for a quick view of directory entries, then choose flags for hidden names, metadata or ordering. It is convenient for interactive inspection; scripts should not parse its presentation as a reliable filename protocol.

Syntax

ls [PARAMETERS] [PATH...]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-l
Detailed list with permissions, owner and size.
-a
Include hidden names starting with a dot.
-h
Human-readable sizes, used with -l or -s.

Usage examples

Show files in current directory

ls

The current directory is listed, normally excluding names beginning with a dot.

View hidden files and attributes

ls -lah

Long output includes hidden entries, human-readable sizes, ownership and permission information.

Sort by time of change

ls -lt ./logs

The log directory is ordered by modification time, with newer entries first by default.

Notes and limitations

  • For the exact path and attributes of a single file, use stat.
  • Names may contain spaces and newlines: do not parse the output of ls in scripts.

Common questions and troubleshooting

Why are my files missing from ls?

Check your working directory and include hidden entries. Also confirm that you are in the expected server session, not a different host.

Does the size column show total directory usage?

For a directory it normally describes the directory entry structure, not all contained files. Use du to measure a tree and df for filesystem capacity.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man ls.