質問

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) .

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top