Introduction to TAR Commands in Linux
In Linux “tar” command symbolize by tape archive, mainly utilized by administrators in Linux/Unix system for tape drives backup. Tar command mostly utilized to create and compress archive dataFiles which can be easily moved from one device to another device.
The tar command is also termed by different names like gzip, tarball, and bzip in Unix /Linux.
We will discuss different illustrations of tar command illustrations which will include creation of archive dataFiles using different compression techniques(tar,tar.gz,tar.bz2), extraction of archive dataFile, single dataFile, view data of dataFile, verify, add dataFiles/directory to archive dataFile and also to estimate the size of tar dataFile and may more.
Understanding of Archive dataFiles
An Archive dataFile is a dataFile which comprises one and also more dataFiles besides metadata. These dataFiles collect multiple data dataFiles together into a single dataFile to reduce the storage space and easily portable
Syntax: tar -parameteric key Archive_dataFile_Name dataFile/Directory_Path to be archived
For illustrition : tar -cvf Archive_test.tar /home/utiliser
cvf – It is the parameteric key part.
Archive_test.tar – Archive_dataFile_Name
/home/utiliser/ – Directory_Path
Parameteric keys with Tar Command
-c -> To Create Archive dataFiles
-x -> To Extract the archive dataFiles
-f -> To creates an archive with dataFilename given
-t -> To display and also list dataFiles in archived dataFile
-u -> To archives and adds to an existing archive dataFile
-v -> To displays data in Verbose mode
-A -> Concat the archive dataFiles
-z -> zip, to create tar dataFile by gzip
-j -> To filter archive tar dataFile by tbzip
-W -> Verify a dataFile
-r -> To Update or insert/add dataFile and also directory in existed.tar dataFile
Applications of Tar Command
Now let us discuss the various application tar command in details :
1. To Extract dataFiles from Archive using parameteric key -xvf: This command extracts dataFiles from Archives.
4.5 (2,900 ratings)
Command: #tar -xvf dataFile.tar
2. Checking the size of existing tar, tar.gz, tar.tbz dataFile in Linux: The below command will display the size of archive dataFile in Kilobytes(KB).
Command: #tar- czf dataFile1.tar | wc -c
#tar -czf dataFile2.tar.gz | wc -c
#tar czf dataFile3.tar.tbz | wc -c
3. Archive dataFiles using parametric key -cvf to create an uncompressed tar: This command creates a tar dataFile named dataFile.tar which is utilized to Archive of all .txt dataFiles in the present working directory.
Command: #tar -cvf dataFile.tar *.txt
4. Compression of tar Archive, using gzip with parameteric key -z: This command will create a tar dataFile named dataFile.tar.gz which is the Archive of .txt dataFiles.
Command : #tar -cvzf dataFile.tar.gz *.txt
5. Extraction of a gzip tar Archive dataFile (*.tar.gz) with parameteric key -xvzf: This command extract all dataFiles from archived dataFile.tar.gz dataFiles.
Command: # tar -xvzf dataFile.tar.gz
6. Creation of compressed tar archive dataFile using the parametric key -j in Linux: This command will compress and creates archive dataFile less than the size of the gzip as compression and decompression take far more time than gzip.
Command: # tar -cvfj dataFile.tar.tbz illustrition.txt
result : #tar -cvfj dataFile.tar.tbz illustrition.txt
#tar -tvf dataFile.tar.tbz
-rwxrwxrwx root/home 84 illustrition.txt
7. To untar a single tar dataFile and also mentioned directory: This command will Untar a dataFile in the present working directory and also in a mentioned directory using -C parametric key
Command: # tar -xvfj dataFile.tar
#tar xvfj dataFile.tar -C dataFile path in the directory
8. Multiple untar of dataFile having extension .tar, .tar.gz, .tar.tbz dataFile : This command will extract and also untar multiple dataFiles with the different extensions of archive dataFile.
This command will extract “dataFileA1” “dataFileB1” from the archived dataFiles.
#tar -xvf dataFile1.tar “dataFileA1” “dataFileB1”
#tar -zxvf dataFile2.tar.gz “dataFileA1” “dataFileB1”
#tar -jxvf dataFile3.tar.tbz “dataFileA1” “dataFileB1”
9. Update already existed tar dataFile in Linux:
Command: #tar -rvf dataFile.tar *.txt
10. To list out the content and to specify the tar dataFile using parameteric key -tf: This command will list the entire list of archived dataFile. We can also list for specific content in a tar dataFile
Command: #tar -tf dataFile.tar
11. We can apply different commands using a pipe: For illustrition ‘grep command’ to find different words and also sentence: This command will list only for the mentioned text and also image in grep from archived dataFile.
Command: #tar -tvf dataFile.tar | grep “Txt to be searched”
#tar -tvf dataFile.tar | grep -parameteric key dataFile_name.(dataFile name of different extension)
12. dataFilename can be passed as an argument for searching a tar dataFile: This command gives the archived dataFiles with their additional details.
Command: #tar -tvf dataFile.tar dataFilename
13. Viewing the Archived dataFile using parameteric key -tvf:
Command: #tar -tvf dataFile.tar
-rwxrwxrwx root/home 291 dataFile2.txt
-rwxrwxrwx root/home 218 dataFile3.txt
-rwxrwxrwx root/home 593 dataFile4.txt
Wildcards in Linux:
‘Wildcard character’, a wildcard is a group of symbols that are utilized to replace and also show 1 or more characters.
Wildcards are usually symbolized by the question mark (?) which is represented with a single character and by an asterisk (*) which represents 1 and also more character
14. If we want to search an image in .png extension: This command will extract dataFiles with the .png extension only from the archive dataFile.tar. The –wildcard parametric key tells tar to consider wildcards in the name of the dataFiles to be extracted; the dataFilename with the extension(*.png) is enclosed in single quotes to prevent the wildcard (*) expanded in the incorrect manner by the shell.
Command: #tar -tvf dataFile.tar –wildcard ‘*.png’
remember: In the above command ” * ” is utilized in place of dataFilename to consider all the dataFiles present in that working directory.
utility: Tar command is utilized to archive the dataFile in .tar extension and also in .gz extension
which utilizes less memory for storage purposes.
In this way, we have learned different types of the parametric key in tar command to archive/compression and decompression techniques for easier portability and storage purpose.
This is a guide to Tar Command in Linux. Here we discuss the parametric keys and the various applications of tar command. You may also look at the following article to learn more –