Copy everything except specific files

Viewed 44

How can I copy everything (files and directories(even if they are empty)) from one directory to another, except files ".php", and files with name "config.yml". I need to do this with single command. I have tried this one

find ./ -type f ! ( -name "*.php" -o -name "config.yml" ) -exec cp --parents -r -t /my/directory/ "{}" +

It works but if the directory have only files ".php", command will skip the directory and do not copy the empty one, but I need the directory even if it will be empty.

1 Answers

Sorry, I haven't enough reputation to put a comment, because I would like to ask you if the use of "find" is a requisite.

If is not, you can do it easily with the rsync command:

rsync -av --exclude=config.yml --exclude="*php" ORIGINFOLDER/ DESTFOLDER

Just change ORIGINFOLDER and DESTFOLDER for your folders name, and take a look at the man to see the meaning of the options.

Related