Exclude a Sub-directory in Tar Command

To backup the directory /home/ to file /backups/home.tgz, and exclude /home/apachelog/ :


# cd /home
# tar czvf /backups/home.tgz –exclude apachelog/ *


(double ‘-’)
It may take a while, make it background:

# tar czf /backups/home.tgz –exclude apachelog/ * &

 if you have to exclude more than one dir.........then create a file called file.txt

and enlist the dirs with the path.
for ex.


#mkdir test
#mkdir test/test1
#mkdir test/test2
#mkdir test/test3


Now Suppose you want to exclude  test1 & test2 dirs..then
#vi file
test/test1
test/test2


save & exit
Now use tar as ...


# tar cvf xyz.tar.gz -X file test


where -X file is the listed dir from file and test is the tar destination to be created after excluding dirs .


have a nice taring........

No comments:

Post a Comment