πŸ‘ˆ More articles are this way my dudes πŸ„β€β™€οΈ

TIL: How to copy a directory ignoring specific files or directories

May 06, 2020 (1 min read)

Something I often want to do is copy the entire contents of a directory to another location but ignore specific files or sub directories. Usually I need to ignore node_modules or vendor.

A handy way to do this is with the command:

rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude

# For example lets copy everything in the current
# directory except node_modules to another folder
rsync -av --progress . ~/some-other-folder --exclude node_modules

As a bonus. You can also accomplish the same thing in a dockerfile using the COPY command. All you have to do is add a glob pattern for the files or directories you want to ignore to your .dockerignore file.

Like this if you have a node_modules directory in your root:

// .dockerignore
node_modules

I learned the rsync command from this post on stackoverflow. Go give the author an up vote if it was useful to you! https://stackoverflow.com/a/14789400/5056424

Also give this guy an up vote too if the Docker tip was helpful! https://stackoverflow.com/a/43747867/5056424

Cheers!

Dan


Buy Me a Coffee at ko-fi.com...
Β© 2023, Built with πŸ’–and Gatsby baby πŸ€™