Reputation: 311
I'm trying to copy a directories contents without one file. The problem i'm having is that the file is a few folders nested and the extglob operator fails to match.
Assume the following folder structure:
I would like to copy everything from source, including subfolders and files into dest except smu.txt.
I would have thought the following would do the trick:
#!/bin/bash
shopt -s extglob
cp -vr source/!(smu.txt) dest/
But it still copies smu.txt.
I also tried the following without success:
#!/bin/bash
shopt -s extglob
shopt -s globstar
cp -vr source/!(**/smu.txt) dest/
It if smu.txt is directly under ../source
it successfully ignores it, but how do I get it to ignore files within subdirectories?
Upvotes: -1
Views: 281
Reputation: 11
Have you tried using find? Maybe this works:
$ find -name "source/*!(smu.txt)" -exec cp -vr {} dest/\;
Upvotes: 1