Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Slackware This Forum is for the discussion of Slackware Linux.


  Search this Thread
Old 12-16-2005, 02:42 PM   #1
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

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:
tar -cvvf - ~root/ -X ~root/.*/ | gzip > backup.tar.gz
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?

Old 12-16-2005, 03:45 PM   #2
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
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Original Poster
Rep: Reputation: 30
thanks for you help, however it still doesn't exlude hidden directories:
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

Old 01-05-2006, 03:49 PM   #4
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

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

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:

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

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


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 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 > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:33 AM.

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