10

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

2 Answers 2

13

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 
fruit/
fruit/peach/
fruit/apple/
fruit/banana/
2
  • 3
    I hate to be a pedant, but a tomato is technically/botanically speaking a fruit as well :)
    – Kev
    Jan 5, 2012 at 0:41
  • 4
    This would be a nice discussion at cooking.stackexchange.com ;D
    – user13742
    Jan 5, 2012 at 16:35
9

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .