Archive

File compression is a fundamental task in managing and transferring data efficiently on a Linux system.

An archive file is a compressed file that contains one or more files bundled together for more accessible storage and portability.

Archive

Archiving commands in Linux are tools used to package and compress one or multiple files or directories into a single archive file.

The most commonly used archiving commands in Linux include tar, gzip, zip, and rar.

Understanding Archiving Commands in Linux

Archiving commands in Linux are a set of tools used to create, manage, and extract archive files.

These tools allow users to package one or more files or directories into a single archive file, compress the data, and store it in an organized and efficient manner.

They help to reduce the overall size of files and directories, making them easier to transfer and store.

common archiving commands in Linux

  1. tar

Used to create, manage, and extract tar archives. Tar stands for “tape archive,” which refers to its origins as a tool for backing up data to tape drives.

  1. gzip

Used to compress and decompress files using the gzip compression algorithm. Gzip is commonly used in conjunction with tar to create tarballs, which are tar archives that have been compressed with gzip.

  1. zip

Used to create, manage, and extract zip archives. Zip is a popular archive format that is supported by many operating systems.

  1. rar

Used to create, manage, and extract rar archives. Rar is a proprietary archive format that supports compression, spanning, and error recovery.

Basic Archiving Commands

  1. tar command

tar -cvf file.tar /path/to/folder

This command creates a tar archive called file.tar from the contents of the directory located at /path/to/folder

tar -xvf file.tar

This command extracts the contents of the file.tar archive into the current directory.

  1. gzip commands

gzip file.txt

This command compresses a file called file.txt and replaces it with a compressed file called file.txt.gz.

gunzip file.txt.gz

This command decompresses a file called file.txt.gz and replaces it with a decompressed file called file.txt.

zcat file.txt.gz

This command displays the contents of a compressed file called file.txt.gz on the terminal without extracting it.

zless file.txt.gz

This command allows you to view the contents of a compressed file called file.txt.gz in a more user-friendly way.

  1. zip commands

zip archive.zip file1.txt file2.txt

This command creates a new zip archive called archive.zip and adds two files called file1.txt and file2.txt to it.

unzip archive.zip
  1. rar commands

rar a archive.rar file1.txt file2.txt

This command creates a new rar archive called archive.rar and adds two files called file1.txt and file2.txt to it.

unrar x archive.rar

This command extracts the contents of the archive.rar file into the current directory.

For more archive command options you can use man page to get all options for all compression methods.

Last updated