Friday, March 18, 2022

[SOLVED] BASH copy all files except one

Issue

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

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/ {} +


Answered By - John Kugelman
Answer Checked By - Robin (WPSolving Admin)