Pocket howtos: tar command

Tags: 

tar is command to combine many files or directories to one file plus with can be compress and extract files too.

Command to combine files or directories into one file is

tar -cfv filename.tar dirname1 dirname2

cf is create a new archive file
v is output process to terminal
filename.tar is archive file name
dirname1, dirname2 is all files or directories that you want to combine together

Use this command if we want to compress archive file

tar -cfvz filename.tar.gz dirname1 dirname2

z is gzip compress type
filename.tar.gz is gzip compress archive file name

Or if you want to change compress type to bzip2

tar -cfvj filename.tar.bz2 dirname1 dirname2

j is bzip2 compress type
filename.tar.bz2 is bzip2 compress archive file name

Use this command to extract file

tar -xfvz filename.tar.gz
tar -xfvj filename.tar.bz2

x is tell tar to extract file
filename.tar.gz, filename.tar.bz2 is file name that you want to extract

If you want to specify your extract directory. Use this command

tar -xfvz filename.tar.gz -C /opt

-C /opt is path destination to extract file

The end...