Copy all directories except one


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?


Use extended globbing:

shopt -s extglob
cp -r dirToCopy/!(dirNotToCopy) .

Answered By – choroba

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published