LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-18-2006, 07:43 AM   #1
ampop
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Rep: Reputation: 0
tar --exclude=directory


I would like compact some files but exclude a entire directory, (backup issue)
I allready tried: tar --exclude=directory, but it doesn't work, I have to specify all the files.
Anyone knows a soluction for this issue?
Thanks.
 
Old 06-18-2006, 07:53 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Use a wild card in the --exclude option argument.

For example, suppose you have 3 directories a, b & c.
Each directory has 3 files.
a: d e f
b: g h i
c: j k l

To exclude all of the files in b, use --exclude 'b/*'
To also exclude the directory b, use --exclude 'b/*' --exclude 'b'

Side note: too bad that the spell checker isn't smart enouth to catch typo's like: "a entire"

Last edited by jschiwal; 06-18-2006 at 07:57 AM.
 
Old 06-18-2006, 08:02 AM   #3
ampop
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
jschiwal,

Thank you very much for your tip.
I'm sorry about my English, I didn'd used spel checker, I should use !
 
Old 06-18-2006, 08:45 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Since "a" is a word, a spell checker would not help. It doesnt' catch this mistake. I'll often have a problem key that I tend not to press hard enough, and not catch it until I check back the next day on my previous posts. A dropped 's' at the end of a word is my worst offender.

It would be nice if this site's spell checker was a little smarter, but that might put to much load on the server.

This reminds me on an early (1960's) AI experiment in language translation. An English-Russian translation program was written. They tested it by first translating from English to Russian, and then input the Russian, to compare the result with the original. When they tried "The spirit is willing, but the flesh is weak", they got back "The vodka is good, but the meat is rotten".

Last edited by jschiwal; 06-18-2006 at 08:46 AM.
 
Old 06-18-2006, 09:23 AM   #5
ampop
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
I can't exclude any file.

I have these files and directory's:

ampop@portatil:~/documentos/Pagamentos$ ls -l
total 588
drwxr-xr-- 3 ampop ampop 4096 2006-05-31 19:23 BES
drwxr-xr-- 2 ampop ampop 4096 2006-05-31 19:27 Clix
-rw-r--r-- 1 ampop ampop 5 2006-06-18 13:58 exclude.lst
-rw-r--r-- 1 ampop ampop 5 2006-06-18 13:52 exclude.lst~
-rw-r--r-- 1 ampop ampop 6 2006-06-18 14:11 file
-rw-r--r-- 1 ampop ampop 28 2006-06-18 13:46 lst~
-rw-r--r-- 1 ampop ampop 256000 2006-06-18 13:57 teste.tar
-rw-r--r-- 1 ampop ampop 303129 2006-06-18 14:11 teste.tar.gz
drwxr-xr-- 2 ampop ampop 4096 2006-06-12 10:53 TVcabo

I do:
$ tar -zcvpf ./teste.tar.gz * --exclude=file

And I get this:
BES/
BES/31-05-06
BES/Cartão de crédito/
BES/Cartão de crédito/31-05-06_1
BES/Cartão de crédito/31-05-06_2
Clix/
Clix/31-05-06
exclude.lst
exclude.lst~
file
lst~
teste.tar
teste.tar.gz
TVcabo/
TVcabo/12_06_06
tar: --exclude=file: Não é possível stat: Arquivo ou diretório não encontrado
tar: Saída por erro atrasada pelos erros anteriores

What's wrong?
 
Old 06-19-2006, 12:46 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I had tested out my example before posting. The 'b' directory was not backed up on my second example. In the first example, the b directory was backed up but not the contents.
This is the line I used in my test:
Code:
 tar cvzf tarex.tar.gz --exclude 'b/*' --exclude b *
There are two differences between our tests. I didn't use the -p option in my test, but this shouldn't matter.
The other difference is that I used "--exclude 'b/*' --exclude b" before the files to archive (the second wild card: '*'). I seem to remember the release notes for SuSE 10.0 containing some information about tar. The note was that tar was changed so that the order of arguments is important. I believe this was done for posix compliance.
Try changing your line to
Code:
tar -zcvpf ./teste.tar.gz --exclude=file *
and see if that works.

Also, note that I had the exclude wild card "--exclude 'b/*'" in single quotes so that it wouldn't be expanded by the shell. Your test didn't need a wild card at all, so I though I would point out this difference.

Tar and find are often used together. You might consider downloading the source packages for tar and findutils in order to produce a print worthy pdf or ps file from the texinfo source. The "Finding Files" manual is extensive. One other thing to consider when using tar is an option which causes tar to backup files before the containing directories. Since you use the -p option, this will allow you to restore files in directories you don't have 'x' or 'r' rights to.

Last edited by jschiwal; 06-19-2006 at 01:16 AM.
 
Old 06-19-2006, 12:01 PM   #7
ampop
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Thumbs up

It works!!!

Thank you very much, it was a very good help for my backup's.
 
Old 06-20-2006, 02:12 AM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I'm glad that it worked!
I thought I would point out a couple other archive programs. The first is "sar", which is a lot like tar but adds support for ACLs. If your kernel and filesystem support the getfacl and setfacl commands, and a user might use them, you might consider using sar instead. Another is dar and kdar. These are more convenient to use to backup to DVDs instead of tape. Also, dar will track when a file is deleted between incremental backups.
 
  


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
Tar won't exclude directories. yougene Slackware 9 12-01-2005 10:32 AM
tar --exclude --exclude-from cefn Linux - Software 4 10-11-2005 08:31 PM
tar --exclude-from=FILE GATTACA Programming 1 07-29-2005 01:25 PM
tar exclude-from drisay Slackware 1 12-23-2004 02:10 PM
tar --exclude for subdirectories mrtwice Linux - Software 2 10-23-2003 01:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:56 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration