BASH copy all files except one

Viewed 118274

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?

9 Answers

Jan, 2022 Update:

This is the easiest way(It's not complicated).

First, make "temp" folder:

mkdir temp

Second, copy all files from your original folder to "temp" folder:

"-R" flag can copy exactly all files including "Symbolic Links"

cp -R originalFolder/. temp/

Third, remove "Default.png" from "temp" folder:

rm temp/Default.png

Finally, copy all files from "temp" folder to your destination folder:

cp -R temp/. destinationFolder/

In addition, this is the shortest way without "temp" folder:

cp -R originalFolder/!(Default.png) destinationFolder/

Below script worked for me

cp -r `ls -A | grep -v 'skip folder/file name'` destination

use the shell's expansion parameter with regex

cp /<path>/[^not_to_copy_file]* .

Everything will be copied except for the not_to_copy_file

-- if something is wrong with this. please Specify !

Related