LinuxQuestions.org
Visit Jeremy's Blog.
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 03-27-2008, 02:50 PM   #1
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Rep: Reputation: 31
How to exclude a Directory with TAR


I need to tar up a directory, and exclude certain files, and certain sub-directories.

The command I'm using is:

tar -zcvpf /home/users.tar.gz --directory /home/users --exclude=*.iso* --exclude=*.rpm --exclude=*.mpg --exclude=/home/users/richard --exclude *.tgz .

The command excludes files according to defined patterns.
Unfortunately, it doesn't exclude the directory /home/users/richard.

What is the correct way to exclude a directory with tar?
 
Old 03-27-2008, 03:13 PM   #2
karelvdm
Member
 
Registered: Sep 2004
Location: Pietermaritzburg South Africa
Distribution: Home:OpenSuse 11, Office:FreeBSD 7 PBX:Trixbox 2 (CentOS 4.4) Home Automation : LinuxMCE
Posts: 123

Rep: Reputation: 15
Have u had a look at this?

http://www.linuxquestions.org/questi...ectory-455908/
 
Old 03-27-2008, 04:33 PM   #3
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Yes I did.
It did not work for me.

I managed to get it to work though.

From outside /home, the following did not work:

tar -zcvpf /home/users.tar.gz --directory /home/users --exclude '/home/users/richard/*' .

But if I first do:
cd /home
then do

tar -zcvpf /home/users.tar.gz --directory /home/users --exclude 'users/richard/*' .

it works.

Apparently, you have to first enter the immediate upper directory first.
 
Old 03-28-2008, 04:43 AM   #4
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 270

Rep: Reputation: 33
Thumbs up

please add one more thing

--exclude /home/users/richard/* --exclude /home/users/richard

you need to exclude both (the directory as well as the files in that directory)
 
  


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 --exclude=directory ampop Linux - Software 7 06-20-2006 01:12 AM
Tar won't exclude directories. yougene Slackware 9 12-01-2005 09:32 AM
tar --exclude --exclude-from cefn Linux - Software 4 10-11-2005 07:31 PM
tar exclude-from drisay Slackware 1 12-23-2004 01:10 PM
tar --exclude for subdirectories mrtwice Linux - Software 2 10-23-2003 12:50 PM

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

All times are GMT -5. The time now is 09:23 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