How to Compress Files in Linux | Tar Command

Configurare noua (How To)

Situatie

File compression is a fundamental task in managing and transferring data efficiently on a Linux system. The Tar command, short for Tape Archive, is a powerful tool that allows users to create compressed and archived files.

Solutie

Pasi de urmat

tar Command to Compress Files in Linux

The tar command is commonly used to compress files in Linux when combined with options like -z (gzip) or -j (bzip2).

The Linux ‘tar’ stands for tape archive, which is used to create Archive and extract the Archive files. tar command in Linux is one of the important commands that provides archiving functionality in Linux. We can use the Linux tar command to create compressed or uncompressed Archive files and also maintain and modify them.

Creating an uncompressed tar Archive using option -cvf

This command creates a tar file called file.tar which is the Archive of all .c files in the current directory.

tar cvf file.tar *.c
  • ‘-c’: Creates a new archive.
  • ‘-v’: Displays verbose output, showing the progress of the archiving process.
  • ‘-f’: Specifies the filename of the archive

Output :

os2.c
os3.c
os4.c

Extracting files from Archive using option -xvf

This command extracts files from Archives.

tar xvf file.tar
  • ‘-x’: Extracts files from an archive.
  • ‘-v’: Displays verbose output during the extraction process.
  • ‘-f’: Specifies the filename of the archive.

Output :

os2.c
os3.c
os4.c

gzip compression on the tar Archive, using option -z

This command creates a tar file called file.tar.gz which is the Archive of .c files.

tar cvzf file.tar.gz *.c
  • ‘-z’: Uses gzip compression.
  • ‘-j’: Uses bzip2 compression.
  • ‘-J’: Uses xz compression.

Tip solutie

Permanent

Voteaza

(1 din 2 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?