tarAn archiving utility. tar stands for tape archive.
Syntax: tar [options] [archive] [file]
Example:
Using the -cvf option to archive a file. The -c option is used to create the archive, -v displays a verbose message about the process and -f is used when the user wants to specify the name of the archive file.
$ tar -cvf java.tar java-programming/
java-programming/
java-programming/BalancedParanthesis/
java-programming/BalancedParanthesis/BalancedParanthesis.java
java-programming/FindTheWinner/
java-programming/FindTheWinner/FindTheWinner.java
java-programming/GarbageCollection/
java-programming/GarbageCollection/GarbageCollection.java
java-programming/HomegrownStack/
java-programming/HomegrownStack/HomegrownStack.java
java-programming/UniqueID/
java-programming/UniqueID/UniqueID.java
Using the -xvf to extract a archive file. The -x option is used to specify that we want to extract the archive.
$ tar -xvf java.tar
java-programming/
java-programming/BalancedParanthesis/
java-programming/BalancedParanthesis/BalancedParanthesis.java
java-programming/FindTheWinner/
java-programming/FindTheWinner/FindTheWinner.java
java-programming/GarbageCollection/
java-programming/GarbageCollection/GarbageCollection.java
java-programming/HomegrownStack/
java-programming/HomegrownStack/HomegrownStack.java
java-programming/UniqueID/
java-programming/UniqueID/UniqueID.java
Compressing an archive into .gz format using -z command.
$ tar -czf java.tar.gz java-programming/
$ ls
java.tar.gz
gzip & gunzipUsed for compressing a file. You can use gzip for both compression and decompression and use gunzip for decompression.
Syntax for gzip: gzip [option] filename
Syntax for gunzip: gunzip [option] filename
Example:
Compressing using gzip
$ ls
file.txt
$ gzip file.txt
$ ls
file.txt.gz
Decompressing using gzip using -d option.
$ gzip -d file.txt.gz
$ ls
file.txt
Decompressing using gunzip
$ gunzip file.txt
$ ls
file.txt