Exclude Directory from Tar

In order to exclude, skip, ignore a directory from a TAR archive do the following:

tar –exclude=”dir/excluded_dir_no_slash” -czvf tarball.tgz dir/

To exclude, skip, ignore multiple directories with TAR:

tar –exclude=”dir/excluded_dir_no_slash” –exclude=”dir/excluded_dir_no_slash_2″ -czvf tarball.tgz dir/

This answer in the question from Unix/Linux StackExchange does a good job of explaining it, “tar –exclude doesn’t exclude. Why?“.



Here’s a couple more tar commands for good measure:

tar -cvvf file.tar file.txt (tar file)
tar -cvvf file.tar home/ (tar dir)
tar -xvvf file.tar (untar)
tar -xvf file.tar (view)
tar -cvvf archives/20040918.tar *php *txt (example)

Post written by Ed Reckers

Founder and lead web development consultant at Red Bridge Internet : San Francisco WordPress Developers and Consultants.

Leave a Reply