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.

Advertisements

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s