tar utility - how to zip and unzip files in linux

tar utility - how to zip and unzip files in linux

Colleagues hello to all.

In today's article, we will talk about a utility called tar in Linux. The tar utility means a tape archive which is used to copy files and directories and compresses everything into a single archive file commonly referred to as tar, gzip and bzip. On Linux, the tar utility is most widely used for creating compressed archive files.

 

Sitaxis:

tar [options] [archive-file-name] [file or directory to archive]


 

Parameters:

  • -c : create archive
  • -x : Extract archive
  • -f : create archive with given filename
  • -t : show or list files in a zipped file
  • -u : archives and appends to an existing archive file
  • -v : display detailed information
  • -A : concatenate archive files
  • -z : create tar file using gzip compression
  • -W : check archive file

 

In the first example, we will create a tar archive named archive.tar.gz and put five sql files into this archive.

$. tar -czvf archive.tar.gz  file_1.sql file_2.sql file_3.sql file_4.sql file_5.sql

linux_command_tar

This should create a archive.tar.gz file.

 

In the following example, we will create an archive using the bzip2 compression algorithm, for this we need to use the -j parameter.

$. tar -cjvf archive.tar.bz2 file_1.sql file_2.sql file_3.sql file_4.sql file_5.sql

linux_command_tar

This should create a archive.tar.bz2 file.


 

In order for us to now unzip our archives, we need to use the same command, but with an additional -x parameter.

Unzipping a .tar.gz archive

$. tar -xvf archive_gz.tar.gz

linux_command_tar

 

Unzip archive .tar.bz2

$. tar -xvf archive_bz.tar.bz2

linux_command_tar


 

With the next two examples, we only want to see what we have in the archives without unpacking them, for this we need to use the -t parameter.

Show the contents of a .tar.gz archive

$. tar -tvf archive_gz.tar.gz

linux_command_tar

 

Show contents of .tar.bz2 archive

$. tar -tvf archive_bz.tar.bz2

linux_command_tar


 

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES

How to find out the size of a file and directory in Linux
How to find out the size of a file and directory in Linux
LINUX
Read more
bzip2 utility - how to compress and decompress files in Linux
bzip2 utility - how to compress and decompress files in Linux
LINUX
Read more
lsof utility - find out what ports are listening in Linux
lsof utility - find out what ports are listening in Linux
LINUX
Read more