Tuesday, April 30, 2024
 Popular · Latest · Hot · Upcoming
22
rated 0 times [  22] [ 0]  / answers: 1 / hits: 14736  / 1 Year ago, mon, december 19, 2022, 7:23:10

I'm currently trying to find (and copy) all files and folder structure matching a specific pattern, in a specified directory and I'm so nearly there!



Specifically, I want to recursively copy all folders not begining with a '_' character from a specified path.



find /source/path/with/directories -maxdepth 1 -type d ! -name _* -exec cp -R {} /destination/path ;


In the /source/path/with/directories/ path are machine-specific directories beginning with '_' and others, and I'm only interested in copying the others. For a reason beyond me, the find command returns the /source/path/with/directories/ directory, and therefore copies its content, directories begining with '_' included.



Anyone have a hint as to why that is?



Thanks,



Pascal


More From » find

 Answers
7

find returns the root path because it matches your criteria—i.e. it is a directory, and it doesn't start with _.



You're looking for -mindepth 1, I suspect:



$ cd /tmp
$ mkdir a
$ touch a/b
$ mkdir a/c
$ touch a/c/d
$ find a
a
a/b
a/c
a/c/d
$ find a -mindepth 1
a/b
a/c
a/c/d


Reference: find manpage


[#37426] Wednesday, December 21, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
poefor

Total Points: 379
Total Questions: 95
Total Answers: 115

Location: Serbia
Member since Tue, Jul 26, 2022
2 Years ago
;