Output:
Check whether the file is extracted by listing all files in the directory.
Unzip File using tar command
Another most common method to extract data from archived files using a terminal in Linux is by using the tar command which comes pre-installed in Ubuntu, it stands for “tape archiver“ used to compress, and extract the compressed files and also maintain and modify them. The files zipped with “.tar” extension are unzipped by tar command.
Syntax:
$ tar [options] filename.tar
Some options with tar command are:
Options:
-c : it create compressed files
-x : it extracts the compressed files
-f : creates compressed file with given filename
-t : displays or lists files in zip file
-u : compresses and adds to an existing zip file
-v : output verbose information
-A : concatenate the zip files
-z : zip, tells tar command that creates tar file using gzip
-j : filter archive tar file using tbzip
-W : verifies compressed file
-r : updates or add file/files or directory in already existed .tar file
The below-mentioned command will unzip “linux2.tar” by tar command:
$ tar xvf linux2.tar
Output:
Check whether the file is extracted by listing all files in the directory
Unzip File using gunzip command
Another common way to extract data from archived files using a terminal in Linux is by using gunzip command, which also comes pre-installed. In Linux, the gunzip command compresses or expands a file or files and, replaces the archived file/files with the original file/files. After extraction, the file/files will regain their original extension. The files zipped with “.gz, .z, _z, -gz, -z , .Z, .taz,.tgz” extension are unzipped by gunzip command.
Syntax:
$ gunzip filename.gz
Below mention command will unzip “linux3.txt.gz” by gunzip command
$ gunzip linux3.txt.gz
Output:
Check whether the file is extracted by listing all files in the directory:
Every operating system offers the possibility to compress files or directories with different methods to save disk space and to transfer files easily. The compressed files must be extracted. In this article, three methods of extracting compressed files are discussed in detail: Extracting files using “unzip”, “tar” and “gunzip” commands. You can choose one of the methods that you find easiest.