How to exclude a folder by name recursively when making a tar archive?
5,970
To exclude the directory named node_modules
wherever it is located under /srv/www/
even if there are multiple copies of it under different sub-directories, just do not specify a path in the --exclude
part and use it like this:
tar -zcvf /backup/project.tar.gz --exclude "node_modules" /srv/www/
This will exclude all directories and files named exactly node_modules
and all sub-directories and files under them anywhere in /srv/www/
.
Related videos on Youtube
Author by
W.M.
Updated on September 18, 2022Comments
-
W.M. over 1 year
I know it is possible to exclude a particular folder by a command like this:
tar --exclude='/srv/www/project/node_modules' -zcvf /backup/project.tgz .
My question how to exclude any folder named
node_modules
anywhere within the entire/srv/www
directory, to exclude it and exclude all folders under it?-
Raffa over 4 yearsIf what you mean is you want to exclude all directories that start with
node_modules
in their names likenode_modules123
andnode_modules_new
etc. then append a*
to the excluded directory name and use the command like sotar -zcvf /backup/project.tar.gz --exclude "/srv/www/project/node_modules*" /srv/www/
and please edit your question and make it clear. Thank you -
W.M. over 4 years@Raffa, I have just re-edited my question and made it clearer.
-