I would like to copy all files out of a dir except for one name Default.png. It seems that there are a number of ways to do this. What seems the most effective to you?
+8
A:
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
Jon
2009-08-21 18:40:16
This produces-bash: !: event not found
Joe Cannatti
2009-08-21 18:46:49
Are you copying the files to a folder nested within the folder your copying from?
Jon
2009-08-21 18:48:07
This requires `shopt -s extglob` to work, if it has been disabled.
Barry Kelly
2009-08-21 18:52:40
I don't see why that would be an issue ordinarily, but thanks for pointing it out...
Jon
2009-08-21 19:01:23
Works great now. I did not have glob enabled.
Joe Cannatti
2009-08-21 19:03:35
+2
A:
I'd just do cp srcdir/* destdir/ ; rm destdir/Default.png unless the files are big. Otherwise use e.g.
find srcdir -type f/ |grep -v Default.png$ |xargs -ILIST cp LIST destdir/
nos
2009-08-21 18:41:13
+4
A:
Simple, if src/
only contains files:
find src/ ! -name Default.png -exec cp {} 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 {} dest/ +
If src/
has sub-directories, this does not recurse into them:
find src/ -type f -maxdepth 1 ! -name Default.png -exec cp {} dest/ +
John Kugelman
2009-08-21 18:59:15
This turns out to be the best for me because it would appear that OS X ships without glob enabled.
Joe Cannatti
2009-08-21 20:54:31
+1
A:
rsync has been my cp/scp replacement for a long time :
rsync -av from/ to/ --exclude=Default.png
matja
2009-08-21 18:59:42
This is more likely to produce errors than do what you intend.
Dennis Williamson
2009-08-22 01:40:18