Listing hidden files: Which ls option displays hidden files (names starting with a dot) together with other files in the current directory?

Difficulty: Easy

Correct Answer: ls -a

Explanation:


Introduction / Context:
By convention, UNIX-like systems treat filenames beginning with a dot as hidden. Many configuration files and directories use this convention. To audit or troubleshoot effectively, you often need to include these hidden entries in directory listings.


Given Data / Assumptions:

  • You are using the ls utility to list directory contents.
  • Some entries begin with a leading dot.
  • You want to display both hidden and non-hidden files.


Concept / Approach:
The “-a” option tells ls to include all entries, including those starting with “.” (dot). Other useful options: “-A” includes almost all, excluding “.” and “..”. The “-l” option sets long format; “-F” appends indicators like “/” for directories; “-x” changes multi-column layout by rows. None of these, except -a or -A, affects hidden file visibility.


Step-by-Step Solution:

Run “ls -a” to include hidden files.Optionally combine with “-l” for detail: “ls -la”.Inspect dot-prefixed files such as .bashrc, .gitignore, or .config/.


Verification / Alternative check:
Compare outputs of “ls”, “ls -a”, and “ls -A” to see which entries are included. Note that “.” and “..” are shown with -a but suppressed with -A.


Why Other Options Are Wrong:
-l: long format only. -x: layout change, not visibility. -F: classifies entries but does not show hidden ones. None: incorrect because “ls -a” is correct.


Common Pitfalls:
Assuming “ls *” will show dotfiles (it will not without dotglob); confusing “-a” and “-A”.


Final Answer:
ls -a

More Questions from Unix

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion