Skip to content

Creating a Directory Archive (.tar.gz/tar ball) in that Same Directory

It’s pretty simple:

cd ~/my_dir && tar --exclude=my_dir.tar.gz -czf my_dir.tar.gz ./*

The -c argument says to compress, z tells tar to create a gz type, f is to specify the file. The –exclude is the trick here so that tar doesn’t attempt to archive the file it is creating.

I’ve found it best to do this in the directory you are archiving, so yes cd into it first. If you don’t you will end up with problems such as longer paths in the tar archive, the exclusion specified won’t match, etc.



TheSoftwareProgrammer View All

I like science and writing software.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: