Fri. Aug 14th, 2020

Create archives and extract archive files with tar and gzip command

1 min read

Create archives and extract archive files with tar and gzip command in Linux

tar

The tar command is used to create archives and extract archive files.

Use

Example

Archive files or directories

tar -cvf backup.tar /etc

This command creates an archive file named backup.tar, which is an archive of the /etc directory.

Extract the archive file:
tar -xvf backup.tar
List files in an archive
tar -tvf backup.tar

gzip

Gzip is a command often used in Linux systems to compress and decompress files. It is convenient and easy to use.

Use

Example

Compress each file in the /home directory into a .gz file

cd /home
gzip *

Extract each compressed file in /home directory and list detailed information

gzip -dv *
Display detailed information of each compressed file in the /home, without decompression
gzip -l *