How to tar.gz *.php, *.txt, *.inc, *.js, *.css, *.php3 files

gziptarunix

I want to backup my server, but not bother with images /videos etc.

how can i tar.gz all those types of files i want (basically text files)?

Best Answer

You can use the find command to create an input list for most versions of tar.

Depending on the flavor of Unix are you using the command syntax may differ. For example on IBM AIX it would be something like this:

$ cd /directory/you/want/to/archive
$ find . \( -name '*.php' -o \
            -name '*.txt' -o \
            -name '*.inc' -o \
            -name '*.js' -o \
            -name '*.css' -o \
            -name '*.php3' \) -print > /tmp/input.list
$ tar -c -L/tmp/input.list -f - | gzip -c > /path/to/backup.tar.gz

If you have the fancy GNU(/Linux) utils you can do:

$ cd /directory/you/want/to/archive
$ find . -regex '.*\.\(php\|txt\|inc\|js\|css\|php3\)' -print > /tmp/input.list
$ tar -c -z -T /tmp/input.list -f /path/to/backup.tar.gz