BASH copy all files except one
I would like to copy all files out of a dir except for one named Default.png. It seems that there are a number of ways to do this. What seems the most effective to you?
Solution 1:
Should be as follows:
cp -r !(Default.png) /dest
If copying to a folder nested in the current folder (called example in the case below) you need to omit that directory also:
cp -r !(Default.png|example) /example
Solution 2:
rsync has been my cp/scp replacement for a long time:
rsync -av from/ to/ --exclude=Default.png
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
-v, --verbose increase verbosity
Solution 3:
Simple, if src/
only contains files:
find src/ ! -name Default.png -exec cp -t dest/ {} +
If src/
has sub-directories, this omits them, but does copy files inside of them:
find src/ -type f ! -name Default.png -exec cp -t dest/ {} +
If src/
has sub-directories, this does not recurse into them:
find src/ -type f -maxdepth 1 ! -name Default.png -exec cp -t dest/ {} +