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?
129
votes
Why do you need it to skip that file, as opposed to just deleting it after copying it? Does it exist in the target directory already?
– Lasse V. Karlsen
Yes a file with the same name is already living in the target dir.
– Joe Cannatti
@LasseV.Karlsen: Or you could want to save the time of copying it, if it's a large file. I'm interested in this but excluding a directory rather than a file.
– Nikana Reklawyks
7 Answers
170
votes
84
votes
61
votes
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/ {} +
2
votes