Sometimes I need to perform following command
cp -rv demo demo_bkp
However I want to ignore all the files in directory .git . How do I achieve that? It takes a long time to copy .git files and I do not need those files.
You can use --exclude multiples times. Note that the dir thefoldertoexclude after --exclude option is relative to the sourcefolder , i.e., sourcefolder/thefoldertoexclude . Also you can add -n for dry run to see what will be copied before performing real operation, and if everything is ok, remove -n from command line.
cp does not delete files. Show activity on this post. -i Cause cp to write a prompt to the standard error output before copying a file that would overwrite an existing file.
To do so, create a text file with the name of the files and directories you want to exclude. Then, pass the name of the file to the --exlude-from option.
To ignore a git directory specifically, I'd try git export
first.
But in general, to copy a directory tree excluding certain files or folders, I'd recommend using rsync
instead of cp
. The syntax is mostly the same, but rsync
has way more options, including one to exclude selected files:
rsync -rv --exclude=.git demo demo_bkp
See e.g. the man page for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With