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 all folders named node_modules
within the entire /srv/www
?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityUse \( ! -name node_modules \)
to omit this directory name from find's output.
The -print0
option prints the full name of the file, followed by a null char. This should be used in case of filenames which contain newline chars.
The tar -null
option primes the following -T
option to read null-terminated files verbatim.
The tar -T -
option reads files from stdin (the output from the pipe).
find . -type d \( ! -name node_modules \) -print0 | tar --null -czf /backup/project.tgz -T -