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
Usage examples
Show files in current directory
lsThe current directory is listed, normally excluding names beginning with a dot.
View hidden files and attributes
ls -lahLong output includes hidden entries, human-readable sizes, ownership and permission information.
Sort by time of change
ls -lt ./logsThe 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.