LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Thread Tools Search this Thread
Old 12-16-2005, 03:42 PM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora Core 8_x86 (latest git kernel)
Posts: 429
Thanked: 0
excluding hidden directories when using tar


[Log in to get rid of this advertisement]
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
djgerbavore is offline     Reply With Quote
Old 12-16-2005, 04:45 PM   #2
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192
Thanked: 0
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
sirclif is offline     Reply With Quote
Old 01-05-2006, 02:54 PM   #3
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora Core 8_x86 (latest git kernel)
Posts: 429
Thanked: 0

Original Poster
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
djgerbavore is offline     Reply With Quote
Old 01-05-2006, 04:49 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware 12.1, Slackware 13.0
Posts: 3,799
Thanked: 21
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.
gilead is offline     Reply With Quote

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


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


All times are GMT -5. The time now is 06:20 PM.

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.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration