Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 527  / 3 Years ago, mon, june 21, 2021, 2:04:10

It works fine when I copy all hidden files using regex:



cp -r source/.[^.]* destination/


and it just copies exactly files beggining with a dot . .



However, I found the following works also:



cp -r source/.[^.]* destination/


In regular expression, doesn't dot . mean "any singular character"? So why does not the second command copy regular files (those not hidden) ?

Why is the dot . interpreted literally in cp command?


More From » clipboard

 Answers
0

cp, as well as the rest of the built-in shell commands, accept and expand glob patters and not regular expressions. They are similar in some aspects, different in many. For example, the . is literal in globs, and any single character is matched with ?.



Your friend in this case is man 7 glob.


[#36455] Wednesday, June 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brellked

Total Points: 63
Total Questions: 107
Total Answers: 104

Location: Morocco
Member since Fri, May 22, 2020
4 Years ago
;