Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

How do I exclude a file or folder while creating a tar.gz file with tar command?

share|improve this question

2 Answers 2

up vote 14 down vote accepted

Simple example, creating a gzipped tarball out of a directory, excluding a subdirectory and listing the contents:

$ ls fruit/
apple  banana  peach  tomato
$ tar czf onlyfruit.tar.gz --exclude=tomato fruit/
$ tar tf onlyfruit.tar.gz 
share|improve this answer
I hate to be a pedant, but a tomato is technically/botanically speaking a fruit as well :) –  Kev Jan 5 '12 at 0:41
This would be a nice discussion at ;D –  user13742 Jan 5 '12 at 16:35

use the --exclude=directory flag. Works like a charm.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.