The current directory contains normal files and dot-files.
List hidden files but omit the special entries . and .. .
Which command is correct?
ls -A lists almost all entries while excluding . and ... The difference from -a is the treatment of those two special entries.
Detailed explanation
lsIncorrect. Plain ls omits dot-files.
Incorrect. Plain ls omits dot-files.
ls -ACorrect. -A includes hidden entries except the two special directory entries.
Correct. -A includes hidden entries except the two special directory entries.
ls -aIncorrect. -a also displays . and .., which must be excluded here.
Incorrect. -a also displays . and .., which must be excluded here.
ls -dIncorrect. -d lists directory entries themselves rather than selecting hidden entries.
Incorrect. -d lists directory entries themselves rather than selecting hidden entries.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
touch "$LAB_DIR/normal" "$LAB_DIR/.hidden"
ls -A "$LAB_DIR" | sort
rm -r "$LAB_DIR"Expected result
.hidden
normalKey points
- -A excludes . and ..
- -a includes . and ..
- No option excludes hidden entries
Notes
- Environment: GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.