-1

I want to create a tarball of a directory structure. I know I can pack the entire directory by executing tar czvf testdir or all the files in it with tar czvf testdir/*. But what I want to do is exclude all files of a certain extension that occur anywhere in the directory. For example I want to pack up all files in the same directory structure, but leave out all .pyc files.

Is this possible?

1
  • 1
    Did you just try tar --exclude='*.pyc' czvf myFile.tgz testdir/*?
    – Hastur
    Oct 1, 2015 at 14:48

1 Answer 1

1

Yes, it is possible, and simple.

As Hastur mentioned, the command you want is:

tar --exclude='*.pyc' czvf testdir.tgz testdir

And I want to add that if you have a question about any terminal command you are using on Linux (or Mac OS X for that matter), the best place to start is with the official documentation. Type man tar and you will pull it up. You can search through the man page (manual page) by typing /searchterm (and n for next match) and you can scroll through the page using f and b, d and u, or j and k depending on how much you want to scroll in one step.

"But the documentation is decades old in some cases!" Yes, it is...and so are the tools you are using. They have stood the test of time. Really, the man page should always be the FIRST resort if you are having trouble.

Typing man tar followed by /exclude yielded:

--exclude=PATTERN
       exclude files, given as a PATTERN
1
  • Google search < man <command>
    – Wildcard
    Oct 2, 2015 at 8:14

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