Domanda

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?

È stato utile?

Soluzione

Use extended globbing:

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

Altri suggerimenti

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.

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top