Operating System - HP-UX
1835453 Members
2545 Online
110078 Solutions
New Discussion

tar *.html in subdirectory

 
SOLVED
Go to solution
HPP
Regular Advisor

tar *.html in subdirectory

Hi,
I am trying to backup *.html from root directory of webserver, i tried using
find . -name "*.html" -exec tar cvf /tmp/web.tar {} \;
but it does not work. Can anybody help me on backing up only .html files to a file using tar.

Thanks
Be Teachable
5 REPLIES 5
Vincenzo Restuccia
Honored Contributor

Re: tar *.html in subdirectory

#find / -name *.html|xargs tar cvf /tmp/web.tar
CHRIS_ANORUO
Honored Contributor

Re: tar *.html in subdirectory

Do

find . -name *.html |xargs tar cvf /tmp/web.tar
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Klaus Crusius
Trusted Contributor
Solution

Re: tar *.html in subdirectory


does not work if many files are found.
to avoid:

# touch foo
# tar cvf /tmp/web.tar foo
#find / -name *.html|xargs tar rf /tmp/web.tar
There is a live before death!
Wieslaw Krajewski
Honored Contributor

Re: tar *.html in subdirectory

Hi,

The explanation is as follows:

1. When you run

find . -name "*.html" -exec any_command {} \;

then any_command is performed sequentialy for all files found. So in the case

find . -name "*.html" -exec tar cvf /tmp/web.tar {} \;

tar is sequentialy run for any file found, and as a result in your tar archive there is only the last file found by the find command.

If you want to archive what you want can run for example (just a proposal):

tar cvf /tmp/wk.tar $(find . -name "*.html")

Rgds.

Permanent training makes master
Shannon Petry
Honored Contributor

Re: tar *.html in subdirectory

I agree, but will give a few other arguments. First I would recommend you build a text file containing the names of the files to backup. You can run into an argument length problem otherwise.

>touch /tmp/backup.list
>find / -name "*.html" -print >> /tmp/backup.list
>tar cvf /tmp/backup.tar `cat /tmp/backup.list`

If you dont want to make a list first, instead of using the Korn shell syntax given above, the next command works on all systems.

>tar cvf /tmp/backup.tar `find / -name "*.html" -print`

Note that the quote before and after the find command is a grave mark, or back tick.

Regards,
Shannon
Microsoft. When do you want a virus today?