tar

What is tar

tar is a tool that compresses and decompresses files, all with the same tool. tar has a lot of extra options. In order to see all of them, use the following command :

tar --help

How to use tar : compress/decompress

# syntax compressing (using the - is optional, for example : tar czvf is also accepted)
tar -czvf <TOBEMADEFILE.tar.gz> <file1> <file2>

##### compress recursively
tar -czvf <TOBEMADETARFILE.tar.gz> <directory> # from this point it will compress everything that is in the directory

##### syntax decompressing
tar -xvf <FILE.tar.gz>

tar example

# compress with tar 
root@Corrosie:~/test/test# ls
test2.txt  test3.jpeg  test.txt
root@Corrosie:~/test/test# tar -czvf test.tar.gz test2.txt test3.jpeg test.txt 
test2.txt
test3.jpeg
test.txt
root@Corrosie:~/test/test# ls
test2.txt  test3.jpeg  test.tar.gz  test.txt
root@Corrosie:~/test/test# 

# decompress with tar
root@Corrosie:~/test/test# ls
test2.txt  test3.jpeg  test.tar.gz  test.txt
root@Corrosie:~/test/test# rm -rf test2.txt test3.jpeg test.txt 
root@Corrosie:~/test/test# ls
test.tar.gz
root@Corrosie:~/test/test# tar -xvf test.tar.gz 
test2.txt
test3.jpeg
test.txt
root@Corrosie:~/test/test# ls
test2.txt  test3.jpeg  test.tar.gz  test.txt

Last updated