How to compress / extract tar.bz, tar.bz2, tar.gz files in Ubuntu

For some reason I always forget which parameters needs to be used in each one of those cases, so, I’m going to put this information in this post until it burns in my brain.

Extract a tar.bz2 file or a tar.bz

tar -xvjf your_file.tar.bz2

Extract a tar.gz

tar -xvzf your_file.tar.gz

Compress a directory or file in tar.gz

The exclude option it’s just for reference, obviously you just need to use it if you need it

tar -czvf compressed.tar.gz path/to/directory --exclude=*.mp4

Compress a folder or file in tar.bz2

You could use the exclude also, and you can chain exclude options to omit for example the .git and vendor folders, which is very useful

tar -cjvf compressed.tar.bz2 path/to/directory

Source:
https://www.howtogeek.com/248780/how-to-compress-and-extract-files-using-the-tar-command-on-linux/

Advertisements

2 thoughts on “How to compress / extract tar.bz, tar.bz2, tar.gz files in Ubuntu

    1. I think that that way is shorter, but I just want to remind that “j” is for bz2 and “z” is for gz, that way when I need to compress I have no problem.
      Thanks for your comment.

      Like

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s