I want to carry out some action (say chown
) on all the hidden files in a directory.
I know that this .*
is not a good idea because it will also find the current .
and parent ..
directories (I know that rm
will fail to operate on .
and ..
but other commands, including chown
and chmod
, will happily take effect)
But all my hidden files have different names!
How should I glob for all hidden files while excluding .
and ..
?
In Bash use:
to hide the
.
and..
directories. This also sets thedotglob
option:*
matches both hidden and non-hidden files.You can also do:
Gilles :)
You can use the following
extglob
pattern:.
matches a literal.
at first@()
is aextglob
pattern, will match one of the patterns inside, as we have only one pattern inside it, it will pick that!(.|)
is anotherextglob
pattern (nested), which matches any file with no or one.
; As we have matched.
at start already, this whole pattern will match all files starting with.
except.
and..
.extglob
is enabled on interactive sessions ofbash
by default in Ubuntu. If not, enable it first:Example:
You can use a
find
command here. For example something likeThis will find hidden files and change permissions
Edit to include the comment by @gerrit:
This will limit the search top the current directory instead of searching recursively.