LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to exclude a Directory with TAR (https://www.linuxquestions.org/questions/linux-software-2/how-to-exclude-a-directory-with-tar-631093/)

fw12 03-27-2008 02:50 PM

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?

karelvdm 03-27-2008 03:13 PM

Have u had a look at this?

http://www.linuxquestions.org/questi...ectory-455908/

fw12 03-27-2008 04:33 PM

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.

chakka.lokesh 03-28-2008 04:43 AM

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)


All times are GMT -5. The time now is 08:51 PM.