010-150 · Question #7
Which of the following commands will display a list of all files in the current directory, including those that may be hidden?
The correct answer is A. ls -a. The ls -a option is the correct flag to display all files in a directory, including hidden files whose names begin with a dot.
Question
Which of the following commands will display a list of all files in the current directory, including those that may be hidden?
Options
- Als -a
- Bls --hidden
- Cls -h
- Dls --a
How the community answered
(63 responses)- A75% (47)
- B14% (9)
- C8% (5)
- D3% (2)
Why each option
The ls -a option is the correct flag to display all files in a directory, including hidden files whose names begin with a dot.
ls -a instructs ls to list all directory entries including those starting with '.', which are hidden by default, as well as the special entries '.' (current directory) and '..' (parent directory).
ls --hidden is not a valid option recognized by the GNU coreutils ls implementation and will produce an unrecognized option error.
ls -h enables human-readable output for file sizes (e.g., displaying '4.0K' instead of '4096') and has no effect on which files are displayed.
ls --a is not a valid long-form ls option and will result in an error; the correct short option is -a (single hyphen).
Concept tested: Listing hidden files using ls -a
Source: https://man7.org/linux/man-pages/man1/ls.1.html
Topics
Community Discussion
7A is correct. The -a flag tells ls to include entries whose names begin with a dot, which is how Linux hides files, so without it those files simply do not appear in the output.
Good point, and worth adding that -a actually shows . and .. too, so if you just want the hidden files without those two directory entries, -A is the cleaner flag to reach for.
ls -a is the one because the -a flag tells ls to include entries starting with a dot, which is how Linux hides files like .bashrc or .ssh. My senior had me run that on a fresh home directory and I was surprised how many hidden config files were already sitting there.
Yusuf nailed it, though worth being precise that -a shows ALL dot entries including the . and .. directory pointers themselves, so if you want just the hidden files without that noise, ls -A (capital A) is the cleaner habit to build.
ls -a is right, the -a flag includes dot files.
Right, and worth adding that -A skips the . and .. entries that -a includes, which is usually what you actually want when you care about hidden files.
ls -h is the trap here because "h" looks like it should mean hidden but it actually means human-readable sizes, which trips up a lot of people. The real answer is ls -a, where the "a" stands for all, and that is what shows you dotfiles and the . and .. entries.