how to have 'find' not return the current directory

Posted by Pinpin on Ask Ubuntu See other posts from Ask Ubuntu or by Pinpin
Published on 2012-06-20T18:40:09Z Indexed on 2012/06/20 21:24 UTC
Read the original article Hit count: 240

Filed under:

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

© Ask Ubuntu or respective owner

Related posts about find