How do I select all hidden files in a directory? ls .* selects the current folder - ., as well as it's parent ... I just want the hidden files
Asked
Active
Viewed 1,557 times
2 Answers
5
ls .[^.]* will show you all entries that start with a dot and are followed by a non-dot character, thus skipping both current (since it has only the leading dot, nothing following that) and parent directories. It will also show the content of hidden directories, and if that is not wanted, ls -d .[^.]* will omit the contents of hidden folders.
If you only want the hidden files in the current directory, find . -maxdepth 1 -type f -name ".*" will do exactly that.
zagrimsan
- 756
- 6
- 20
-
and it will especially show the the entire contents of all hidden directories ... – Bananguin Jan 09 '14 at 07:59
-
@Bananguin, indeed, I've updated my answer to take that into account. – zagrimsan Jan 09 '14 at 08:07
-
whereas `ls -d .[^.]*` does what you intended it to do ... – Bananguin Jan 09 '14 at 08:34
-
Clarification: the `*` is not a quantifier applied to `[^.]` like in a regular expression, but the bash syntax for "anything" instead. – giorgiosironi Oct 06 '16 at 10:57