Originally Posted by xavitxus
Can someone please explain this regular expression:
It's making me crazy
Alrighty. I'll split the regex in two parts to explain it:
A dot represents one character, any character. The asterisk is a multiplier that means the previous expression can occur zero or more times, and the slash is just a literal forward slash. So this part of the regex can be read as: "Match any amount of characters followed by a forward slash".
Since the dot has a special meaning in the regular expression, it's necessary to escape the first dot to instruct the program that we're looking for a literal dot, not the regex dot metacharacter. To use a metacharacter as a literal character write a backslash before it. The following .*
is the same as the first part. This can be read as: "Match a dot, followed by any amount of characters".
So the full regex can be read as: "Match any amount of characters followed by a forward slash, followed by a dot, followed by any amount of characters".
Originally Posted by osvaldomarques
find . \( ! -regex '.*/\..*' \) -type f -name "whatever"
The regular expression will match hidden files and directories of the form dir/.file
. But since it's negated in the find option (! -regex '.*/\..*'
), it will have the reverse effect, matching everything except hidden files and directories.
Hope that helps.