LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 12-16-2005, 02:42 PM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora Core 8_x86 (latest git kernel)
Posts: 434

Rep: Reputation: 30
excluding hidden directories when using tar


i'm trying to write a script that backs up my home directory, however i'm having trouble trying to exclude the hidden directories from the tar command.
These are the commands i've tried with no success:
Code:
tar -cvvf - ~root/ -X ~root/.*/ | gzip > backup.tar.gz
and
Code:
tar -cvvf - ~root/ --exclude=.*/ | gzip > backup.tar.gz
however the tar command is still include the hidden directories, is there way to stop hidden directories from being including in the tar command?

thanks,
jerry
 
Old 12-16-2005, 03:45 PM   #2
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
are you sure tar includes hidden directories by default? i thought i remembered doing this once and forgetting about hidden files/directories and loosing a bunch of configure files.

anyhow, it looks like --exclude= accepts a pattern, which probably means you can give it a regular expression. if this is the case, then the '.' and '/' probably need to be excaped. i would try

tar -cvvf - ~root/ --exclude=\.*\/ | gzip > backup.tar.gz
 
Old 01-05-2006, 01:54 PM   #3
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora Core 8_x86 (latest git kernel)
Posts: 434

Original Poster
Rep: Reputation: 30
sirclif,
thanks for you help, however it still doesn't exlude hidden directories:
Code:
tar -cvvf - ~root/ --exclude=\.*\/ | gzip > backup.tar.gz
i'll search around and see if i can find a way to exlude hidden directories.

thanks again

djgerbavor3
 
Old 01-05-2006, 03:49 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 13.37
Posts: 4,021

Rep: Reputation: 125Reputation: 125
If you quote the string instead:

Code:
tar -cvvf - ~root/ --exclude '.*/' | gzip > backup.tar.gz
Then the string gets handed to tar instead of being handled by the shell. However, it still fails with an error of:

Code:
tar: .*: Cannot stat: No such file or directory
Try something like:

Code:
tar -c --exclude '.*' -f - ~root/ | gzip > /tmp/backup.tar.gz
That looks like it does what you're asking.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
excluding directories from commands David the H. Linux - General 5 04-06-2009 03:21 PM
Find excluding multiple directories with a wildcard pteigeler Linux - Software 1 09-02-2005 10:57 AM
tar, excluding directories recursively towlie Linux - Newbie 3 06-17-2004 12:32 PM
Excluding directories from zip files jonathanztaub Linux - General 1 05-17-2004 02:17 AM
tar and excluding files murshed Linux - Newbie 7 03-15-2003 02:32 PM


All times are GMT -5. The time now is 07:57 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration