Learn tar command with examples in linux or Unix

Tar command in UNIX:-

Tar command is abbreviated as tape archive.tar is one of the most popular zipped/achieve commands in Unix like zipping in windows to compress the files and store all the files into a single file tar.gz.

tar command examples in linux

tar and gzip are more popular zipped archive commands in Linux or Unix like zipping, WinRAR, etc in windows.

I have also blogged about Top 10 gzip examples in Linux,unix for gzip usage.

Most of the open-source frameworks like Maven, Tomcat, JBoss, etc..are shipped in tar.gz format to install in Unix environments. blogging all these for reference.

Tar example usage:-

*1. Creating archive tar.gz for a folder or tar the files:

tar –cvzf   newfilename.tar.gz existing-folder-name

This compress and create the tar version/zipped as new-file-name.tar.gz from the existing folder. The structure of files, directories, and subdirectories in existing-folder are the same way created for new-file-name.tar.gz

c- create a new gz file z - compressed the files v- print the list of the files shown in stdout f- with this option, the archive name is specified within the command

2.Extract/unzip the tar.gz file into a folder or untar:

tar –xvzf filename.tar.gz

X option means unzip the contents of this archive The remaining options are the same as in #1

This will extract and copy all the files to the current directory with the folder as the filename where this command is running.

3. Show all the files of the tar file

tar tvf  filename.tar.gz

This will show all the files in filename.tar.gz to the stdout console. Option t – list all the contents of the archive

Advantages with tar are it will take a backup of your files The disadvantage is a single file cannot be extracted from the zipped or archived file

Extract or unzip the archive with gunzip, tar command:-

With this both commands, we can be used to unzip the tar.gz or .gz files.’

To unzip the tar.gz file, there are two steps involved. First, unzip .tar.gz into the tar file in the following command and then use the tar command

gunzip filename.tar.gz
tar –xzf filename.tar

filename.tar is created with the first command, this is passed to the tar command to extract the files in the tar.

Hope you got the basic start for tar, and gunzip with examples.

Please feel free to comment and share your thoughts.

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.