In this tutorial, we will introduce how to use linux tar command to compress a directory then extract it. It is a very useful when you are processing linux files.
Linux tar command can help us to create some archive files with *.tar, *.tar.gz, *.gz, *.bz2.
Compress a folder using linux tar
We can use command below to compress a directory.
tar -czvf test.tar /home/test
Here we will compress /test directory to test.tar file.
Extract a .tar archive to a directory using linux tar
After we have compressed a directory, we can extract using command below:
tar -xzvf test.tar /home/temp
This command will extract test.tar archive file to the directory /home/temp