Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a tar archive of a folder thisfolder but want to omit a sub-folder named notthisfolder. Can someone show me how to do this? I've tried to tar'ing the entire folder and removing the one I want to omit but that particular folder is 17gb.


I was using tar --exclude='notthisfolder' -zcvpf archive.tar /thisfolder/

share|improve this question
Can you post your tar script? – troylatroy Mar 5 '14 at 23:03
@troylatroy, I'm not sure exactly but the tar script I'm using is only omitting files in notthisfolder but everything else in its subfolder is being included... =( – sam yi Mar 5 '14 at 23:25

Your command is almost correct. Use

 tar cvfzp achive.tar.gz --exclude notthisfolder thisfolder/
  1. Note that the --exclude notthisfolder option goes after the archive name.

  2. Cosmetic comment: when using the z option, you are using gzip to compress your tarball, so name the archive archive.tar.gz and not archive.tar.

  3. Also, /thisfolder/ is an absolute path and points to the folder thisfolder inside the root directory /. For specifying a relative path (to the current working directory), use thisfolder/ without the leading slash /.

  4. As a little tidbit, you don't need to prefix the cvfzp options with a -. One less character to type!

Works for me ;)

$ tree
└── thisfolder
    ├── butincludethisfolder
    │   ├── includefile1
    │   └── includefile2
    ├── file1
    ├── file2
    └── notthisfolder
        └── notthisfile

3 directories, 6 files

$ tar cvfzp achive.tar.gz --exclude notthisfolder thisfolder/
share|improve this answer

From man tar:

       exclude files, given as a PATTERN

So, given a directory like this:

terdon@oregano foo $ tree
└── thisfolder
    ├── butincludethisfolder
    │   ├── includefile1
    │   └── includefile2
    └── notthisfolder
        ├── omitfile1
        └── omitfile2

You could run the following tar command to get what you want:

tar -cvzf foo.tar --exclude notthisfolder thisfolder/

That will create which contains:

$ tar xvzf foo.tar 
share|improve this answer

It looks like you syntax is wrong.

It should be more like this:

tar -zcvpf /where/you/store/backups/archive.tar /thisfolder --exclude "/notthisfolder" --exclude "/notthisfolder/omitfile1" --exclude "/notthisfolder/omitfile2"

or if the omit files are all in /notthisfolder

tar -zcvpf /where/you/store/backups/archive.tar /thisfolder --exclude "/notthisfolder"

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.