[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Tarball specific file extensions in all directories (recursive)

Posted on 2006-05-07
Medium Priority
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
  • 3
LVL 38

Expert Comment

ID: 16627398
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

yuzh earned 2000 total points
ID: 16627620
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"`

Author Comment

ID: 16629937
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

ID: 16631090
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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Screencast - Getting to Know the Pipeline
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 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