Go Back   PC Tech Talk > PC Tech > Operating Systems and Software > Linux
User Name
Password
Home Register FAQ Members List Calendar Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 12-03-2004, 02:29 PM   #1
section31
Registered User
 
Join Date: Sep 2004
Posts: 35
section31 is on a distinguished road
recursive tarball

hey, does anyone know how to omit a few directories when making a tarball recursively.

Lets say
Code:
tar -cvzf backup.tar.gz foo_dir


Yet there are certain directories inside foo_dir I want the tarball to omit. How would I go about doing something like that.

Thanks for your time,
Dave
section31 is offline   Reply With Quote
Old 12-04-2004, 06:26 AM   #2
greffov
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
tar itself can't do it, but I would do it using find. Find can handle regexps.

see man find especially the OPERATORS section.

one example from the manual:
find / \! -name "*.c" -print
Print out a list of all the files whose names do not end in .c.

in complete the command would be something like
tar -cvzf myfile.tar.gz `find . -name "bla" | xargs`

for a backup it might be interesting to use the -j flag instead of the -z flag, since bzip2 compression is much better than gzip compression.



Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Old 12-04-2004, 01:55 PM   #3
section31
Registered User
 
Join Date: Sep 2004
Posts: 35
section31 is on a distinguished road
Thanks you so much, this is exactly what I needed.
section31 is offline   Reply With Quote
Old 12-04-2004, 02:16 PM   #4
section31
Registered User
 
Join Date: Sep 2004
Posts: 35
section31 is on a distinguished road
hey one more thing greffov. How can I put a regular expression inside the -name paramater. Or is that impossible. If not I can always pipe it into grep but I would like to do something like this but its not working.

find . -name "*\.(html|php)" -print
section31 is offline   Reply With Quote
Old 12-04-2004, 03:00 PM   #5
greffov
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
find . -(i)regex ".+\.(html|php.{0,1})" | xargs

I haven't tried the pattern, you might have to use -E to enable extended regular expression syntax.


b.t.w.: for those that feel very lost when reading this, don't worry -- it's just something you'll never be able to do with any GUI.



Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Old 12-04-2004, 04:29 PM   #6
berks
PCTT Administrator
 
berks's Avatar
 
Join Date: Mar 2003
Location: Las Vegas
Posts: 3,735
berks is on a distinguished road
Quote:
Originally Posted by greffov
b.t.w.: for those that feel very lost when reading this, don't worry -- it's just something you'll never be able to do with any GUI.



Good because i have no idea what any of that means! Usually when i see that many symbols together they mean someone is cussing!



Vote For Us!!!
berks is offline   Reply With Quote
Old 12-05-2004, 05:18 AM   #7
section31
Registered User
 
Join Date: Sep 2004
Posts: 35
section31 is on a distinguished road
Quote:
Originally Posted by greffov
find . -(i)regex ".+\.(html|php.{0,1})" | xargs

I haven't tried the pattern, you might have to use -E to enable extended regular expression syntax.


b.t.w.: for those that feel very lost when reading this, don't worry -- it's just something you'll never be able to do with any GUI.


Thanks for all the help... I had a few problems at first, but I found that I needed to escape all metacharacters except these [].*

this worked fine -> -iregex '.*\.\(html\|php\)'
section31 is offline   Reply With Quote
Old 12-05-2004, 08:51 AM   #8
greffov
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
great

can you post up the final complete command to make the tar here, just for reference? (and to make others possibly even more lost ;-) )

b.t.w.: why do you write ".*\.(html|php)" ? Do you have files named .html or .php that you want to be included?



Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Old 12-05-2004, 06:27 PM   #9
section31
Registered User
 
Join Date: Sep 2004
Posts: 35
section31 is on a distinguished road
About my files being .html or .php. I see where you're going. But since I can't figure out a way to enable "extended regular expression" I was unable to do a +*
I could always substitute a ..* for a +* but that still wouldn't achieve what you want because the results from the find return the relative or absolute paths. So I tried doing something like this [^/] .* but for some reason that doesn't match anything.

Oh well, in the meantime this works nearly perfect.
Code:
tar -cvjf backup.tar.bz2 `find . -iregex "..*\.\(html\|php\)"`


Reason i'm doing this is because the only linux box I have access to is my web host, and I'm going use this as a cron job to backup some stuff.

PS:
Cool Linux Reference Site/Book

Last edited by section31 : 12-05-2004 at 06:41 PM.
section31 is offline   Reply With Quote
Old 12-05-2004, 06:34 PM   #10
tiremonkey2000
Tire Master DJ
 
tiremonkey2000's Avatar
 
Join Date: Apr 2004
Location: florida
Posts: 131
tiremonkey2000 is on a distinguished road
Send a message via AIM to tiremonkey2000 Send a message via Yahoo to tiremonkey2000
thats what my head felt like after reading this made me cross eyed



Tiremonkey2000
tiremonkey2000 is offline   Reply With Quote
Old 12-05-2004, 06:38 PM   #11
section31
Registered User
 
Join Date: Sep 2004
Posts: 35
section31 is on a distinguished road
hey what does that thing below user's avatars do. "Add to reputation" I put something for greffov thinking it would go in his profile or something...but nothing. Where does it go.
section31 is offline   Reply With Quote
Old 12-06-2004, 01:25 PM   #12
greffov
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
I dunno, it adds on my balance or something. You can see it in your control panel.



Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT -4. The time now is 07:36 PM.
Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0


eInvesting - Lost Discussion - Club-tC - Xtreme Tuning

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59