In this brief Linux command line tutorial for robotics and machine learning engineers, we explain how to view and extract tar files. We only explain the basic usage. The YouTube tutorial is given below.
Explanation of the tar command
tar – is the program and command line tool used to create file archives and extract files from archives.
tar – is an abbreviation for Tape ARchive. Tar files are also known as tarballs. Essentially these files are compressed files containing other files and folders. When you see a file with an extension tar.xz – this means that this file is the tape archive and xz denotes the compression tool.
Basic usage for viewing and decompressing tar files:
To see the files in the tar file without extracting them, you need to type any of these two commands
tar tf <name of the file>
tar -tf <name of the file>
- t – means to list the archive
- f – means to specify the file name of the archive
For example, if the file name is file1.tar.xz, then you need to type
tar tf file1.tar.xz
If there are many files in the archive, you can type this to control how many files are displayed
tar -tf <name of the file> | less
To quit the less command, just type q. To extract the tar file we need to write
tar xvf <name of the file>
tar -xvf <name of the file>
This will extract the content of the tar file in the current folder. Here,
- x – means to extract
- v – means to display the verbose (detailed) output during the extraction process
- f – means to specify the file name of the archive
For example, to extract a tar archive called file1.tar.xz, you need to type this
tar xvf file1.tar.xz
This will extract the content of this archive in the current folder