Reputation: 4160
I'm copying all subdirectories with its contents to my current directory as follows:
cp -r dirToCopy/* .
But in the folder dirToCopy
, there is one subfolder called dirNotToCopy
which should not be copied.
How can I filter that particular folder out of my expression?
Upvotes: 1
Views: 2756
Reputation: 1
find /path_to/dirToCopy -maxdepth 1 -type d ! -name dirNotToCopy -exec cp -r {} . \;
Instead of using mindepth suggested in the other answer, we should use maxdepth. (I can't comment or edit another answer since I do not have enough reputation yet)
Also note that this command only copies the subdirectories, not the files in the directory.
Upvotes: 0
Reputation: 2160
Well if you want to do it in single line:
find /path_to/dirToCopy -mindepth 1 -type d ! -name dirNotToCopy -exec cp -r {} . \;
One more way of doing the same.
Upvotes: 1
Reputation: 241848
Use extended globbing:
shopt -s extglob
cp -r dirToCopy/!(dirNotToCopy) .
Upvotes: 3