Tarball specific file extensions in all directories (recursive)

Posted on 2006-05-07
Last Modified: 2008-01-09
I want to tarball into a gz file all files with the following extensions:
php, php3, html, shtml

I want it to recursively search through all subdirectories and place all of the files into a single tarball and maintain the directory structure (I essentially want to download an entire directory withOUT jpgs, gifs, etc).  When it creates the tarball I want it to leave the original files intact.
Question by:djs120
    LVL 38

    Expert Comment

    You can put all athe file name into a list, and then create the tarball, eg:

       find . -type f -name "*.php*" -o -name "*.*html" >/tmp/mylist

       tar cvf /path-to/tarball.tar `cat /tmp/mylist`
       gzip /path-to/tarball.tar

       if you have GNU tar, you can do:

       tar -zcvf /path-to/tarball.tar.gz `cat /tmp/mylist`

       PS: if you want to serach the whole system, replace . with /, or " cd / " then "find"

             if the list is too long, tar in some version of OS (eg SCO), might have
    trouble to handle it, in that case, you can use "cpio" instead of tar, eg:

            cat tmp/mylist | cpio -oacv >/path-to/mybackup.cpio
    man cpio
    to learn more details
    LVL 38

    Accepted Solution

    you don't need to use tmp file, you can also do:

        find . -type f -name "*.php*" -o -name "*.*html" | cpio -oacv >/path-to/mybackup.cpio

        GNU tar:
        tar -zcvf /path-to/tarball.tar.gz `find . -type f -name "*.php*" -o -name "*.*html"`
    LVL 1

    Author Comment

    I tried your last suggestion and I get this error:

    # tar -z cvf /root/full_backup.tar.gz `find . -type f -name "*.php*" -o -name "*.*html" -o -name "*.gz" -o -name "*.css" -o -name "*.js"`
    tar: You must specify one of the `-Acdtrux' options
    Try `tar --help' for more information.
    LVL 38

    Expert Comment

    As mentioned in my first coment, only GNU tar support -z option, Linux ship with GNU tar by default, Solaris, HP-UX, AIX and SCO does not.

    If the list in not too long, you can do:

    tar -cvf /path-to/tarball.tar  `find . -type f -name "*.php*" -o -name "*.*html"`
    and then do:

    gzip /path-to/tarball.tar  

    Thanks for the points and good night!

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
    Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now