System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

How to exlude files/directoris with tar

SOLVED
Go to solution
Leo The Cat
Regular Advisor

How to exlude files/directoris with tar

Hi

Usually I'm using
tar -cvf - /logs/ -X lost+found| gzip -c > /su02/logs.gz # tar and compress

I'd like to exclude systematically the lost+found directory. How to do this small trick ? I know that tar and -X option could work but ....

Thanks in advance
Bests Regards
Den.
4 REPLIES
Dennis Handly
Acclaimed Contributor

Re: How to exlude files/directoris with tar

This is the wrong forum for linux? questions.

Have you tried:
tar -cvf - /logs/ -X /logs/lost+found | ...

(Or does that still do the files in that directory?)
Thierry D
Valued Contributor
Solution

Re: How to exlude files/directoris with tar

Hi Leo,

here another way to exclude some files from being compressed with tar:

tar -zcvf logs.tgz /logs --exclude="lost+found"

Also to exclude it all the time, you could use the environment variable TAR_OPTIONS

export TAR_OPTIONS="--exclude=lost+found"

In that case this option would be used each time you invoke the tar command.

for more details -> man tar

Regards,
Thierry
Steven Schweda
Honored Contributor

Re: How to exlude files/directoris with tar

http://www.gnu.org/software/tar/manual/
http://www.gnu.org/software/tar/manual/html_node/exclude.html#SEC103

"-X name" seems to be equivalent to
"--exclude-from=file", not to
"--exclude=pattern". So, unless "lost+found"
is a file containing "a list of patterns"
(which seems unlikely), you would seem to be
using the wrong option.

> [...] /logs/ [...]

Specifying an absolute source path
("/something") instead of a relative one
("something") may be asking for extra
trouble if you'd ever like to restore the
files to a different location. (GNU "tar"
has options to allow this, but some people
seem to have trouble with GNU "tar" options.)
Leo The Cat
Regular Advisor

Re: How to exlude files/directoris with tar

Soluted with answers