I am looking for a tar command that meets the following requirements:

I want to exclude all files ending with: backwpup & .zip (in between and before can be any e.g. uploads/123backwpup-123.zip) I want to exclude all folders in the area /media/backup/ & /application/cache/

I start at a level that looks like this:

  • example.com
  • example.de
  • example.org

With subdirectories for each:

  1. /etc/
  2. /httpdocs/
  3. /lib/
  4. ...

Only the content of /httpdocs/ needs to be saved.

I tried it with command:

tar --exclude={"*backwpup*.zip", "*/media/backup/*", "*/application/cache/*"} -czvf backup.tar.gz **/httpdocs

But unfortunately backups with path wp-content/uploads/backwpup-4578-backups/2022-10-31_12-22-31_IKXUCSLD01.zip are still included.

3 Answers 3


You can try using the following tar command:

tar --exclude='backwpup.zip' --exclude='/media/backup/' --exclude='/application/cache/' -czvf backup.tar.gz example.com/httpdocs example.de/httpdocs example.org/httpdocs

This command excludes all files ending with "backwpup" or ".zip", as well as folders in the specified locations. It also only includes the "httpdocs" sub-directories in each domain directory

  • 1
    Unfortunately there are too many domains to specify everything individually. Ideal would be a regex based rule or similar. Then there are also subdomains like sub.example.com below example.com again with a httpdocs folder. Not so easy. But not unimportant for a complete filedump of the webserver data excl. backup and caching files.
    – Mike
    Feb 25 at 4:34

Perhaps this way?

find * -type d \( -path '*/media/backup/*' -o -path '*/application/cache/*' \) -prune -o -path '*/httpdocs/*' -type f ! -name '*backwpup*.zip' -print0 | tar -czvf backup.tar.gz --null -T -

Assuming you are using GNU tar, please see the documentation on how to exclude files: https://www.gnu.org/software/tar/manual/html_node/exclude.html This details the pattern matching: https://man7.org/linux/man-pages/man7/glob.7.html

Assuming you use GNU BASH you could loop through the directories using a for loop: https://www.gnu.org/software/bash/manual/html_node/Looping-Constructs.html using filename expansion (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)

At the end of this page are good examples: https://linuxize.com/post/bash-for-loop/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .