Extracting Files from the Command Line
In the Linux command line, you can use various utilities to extract files from compressed archives. Here are some common commands for different archive formats:
To extract a Zip archive, use the unzip
command:
unzip archive.zip
This will extract all the files and directories contained within the Zip archive to the current working directory.
To extract a Gzip archive, use the gunzip
command:
gunzip archive.gz
This will extract the contents of the Gzip archive and remove the original .gz
file.
To extract a Bzip2 archive, use the bunzip2
command:
bunzip2 archive.bz2
This will extract the contents of the Bzip2 archive and remove the original .bz2
file.
To extract a Tar archive, use the tar
command with the x
(extract) option:
tar xf archive.tar
This will extract all the files and directories contained within the Tar archive to the current working directory.
If the Tar archive is also compressed, you can use the appropriate compression flag:
## Tar archive compressed with Gzip
tar xzf archive.tar.gz
## Tar archive compressed with Bzip2
tar xjf archive.tar.bz2
These commands will automatically decompress the archive while extracting the contents.
By mastering these command-line tools, you can efficiently extract files from various compressed archive formats in a Linux environment.