5 Best Command Line Archive Tools for Linux - Part 1

Channel: Linux Commands Linux
Abstract: Delete files from existing archive. tar Examples Create a tar archive file. # tar -zcvf name_of_tar.tar.gz /path/to/folder Decompress an tar archive f

In our day-to-day life we come across, archived files on the platforms of all kind be it Windows, Mac or Linux. There are several Application program available for all of the platforms to create archive files as well as uncompress them. When it comes to work on Linux Platform, we need to deal with archived files very frequently.

Linux Command Line Archive Tools

Here in this article we will be discussing archive tools available on standard Linux Distribution, their features, Examples, etc. The article divided into two parts, each part contains five command line archive tools (i.e. total of 10 Best Command Line Archive Tools).

What is Archived file?

An archive file is a compressed file which is composed of one or more than one computer files along with metadata.

Features of Archiving
  1. Data Compression
  2. Encryption
  3. File Concatenation
  4. Automatic Extraction
  5. Automatic Installation
  6. Source Volume and Media Information
  7. File Spanning
  8. Checksum
  9. Directory Structure Information
  10. Other Metadata (Data About Data)
  11. Error discovery
Area of Application
  1. Store Computer Files System along with Metadata.
  2. Useful in transferring file locally.
  3. Useful in transferring file over web.
  4. Software Packaging Application.

The useful archiving application on standard Linux distribution follows:

1. tar Command

tar is the standard UNIX/Linux archiving application tool. In its early stage it used to be a Tape Archiving Program which gradually is developed into General Purpose archiving package which is capable of handling archive files of every kind. tar accepts a lot of archiving filter with options.

tar options
  1. -A : Append tar files to existing archives.
  2. -c : Create a new archive file.
  3. -d : Compare archive with Specified filesystem.
  4. -j : bzip the archive
  5. -r : append files to existing archives.
  6. -t : list contents of existing archives.
  7. -u : Update archive
  8. -x : Extract file from existing archive.
  9. -z : gzip the archive
  10. –delete : Delete files from existing archive.
tar Examples

Create a tar archive file.

# tar -zcvf name_of_tar.tar.gz /path/to/folder

Decompress an tar archive file.

# tar -zxvf Name_of_tar_file.tar.gz

For more detailed examples, read 18 Tar Command Examples in Linux.

shar Command

shar which stands for Shell archive is a shell script, the execution of which will create the files. shar is a self-extracting archive file which is a legacy utility and needs Unix Bourne Shell to extract the files. shar has an advantage of being plain text however it is potentially dangerous, since it outputs an executable.

shar options
  1. -o : Save output to archive files as specified, in the option.
  2. -l : Limit the output size, as specified, in the option but do not split it.
  3. -L : Limit the output size, as specified, in the option and split it.
  4. -n : Name of Archive to be included in the header of the shar files.
  5. -a : Allow automatic generation of headers.

Note: The ‘-o‘ option is required if the ‘-l‘ or ‘-L‘ option is used and the ‘-n‘ option is required if the ‘-a‘ option is used.

shar Examples

Create a shar archive file.

# shar file_name.extension > filename.shar

Extract an shar archive file.

# unshar file_name.shar
3. ar Command

ar is the creation and manipulation utility for archives, mainly used for binary object file libraries. ar stands for archiver which can be used to create archive of any kind for any purpose but has largely been replaced by ‘tar’ and now-a-days it is used only to create and update static library files.

ar options
  1. -d : Delete modules from the archive.
  2. -m : Move Members in the archive.
  3. -p : Print specified members of the archive.
  4. -q : Quick Append.
  5. -r : Insert file member to archive.
  6. -s : Add index to archive.
  7. -a : Add a new file to the existing members of archive.
ar Examples

Create an archive using ‘ar‘ tool with a static library say ‘libmath.a‘ with the objective files ‘substraction’ and ‘division’ as.

# ar cr libmath.a substraction.o division.o

To extract an ‘ar’ archive file.

# ar x libmath.a
4. cpio

cpio stands for Copy in and out. Cpio is a general purpose file archiver for Linux. It is actively used by RedHat Package Manager (RPM) and in the initramfs of Linux Kernel as well as an important archiving tool in Apple Computer’s Installer (pax).

cpio options
  1. -0 : Read a list of filenames terminated by a null character instead of a newline.
  2. -a : Reset Access time.
  3. -A : Append.
  4. -b : swap.
  5. -d : Make Directories.
cpio Examples

Create an ‘cpio’ archive file.

# cd tecmint
# ls

file1.o file2.o file3.o

# ls | cpio  -ov > /path/to/output_folder/obj.cpio

To extract a cpio archive file.

# cpio -idv < /path/to folder/obj.cpio
5. Gzip

gzip is standard and widely used file compression and decompression utility. Gzip allows file concatenation. Compressing the file with gzip, outputs the tarball which is in the format of ‘*.tar.gz‘ or ‘*.tgz‘.

gzip options
  1. –stdout : Produce output on standard output.
  2. –to-stdout : Produce output on standard output.
  3. –decompress : Decompress File.
  4. –uncompress : Decompress File.
  5. -d : Decompress File.
  6. -f : Force Compression/Decompression.
gzip Examples

Create an ‘gzip’ archive file.

# tar -cvzf name_of_archive.tar.gz /path/to/folder

To extract a ‘gzip’ archive file.

# gunzip file_name.tar.gz

The above command must be passed followed with below command.

# tar -xvf file_name.tar

Note: The architecture and functionality of ‘gzip’ makes it difficult to recover corrupted ‘gzipped tar archive’ file. It is advised to make several backups of gzipped Important files, at different Locations.

That’s all for now. We will be discussing other compressing and decompressing applications, available for Linux, in our next article. Till then stay tuned and connected to Tecmint. Don’t forget to provide us with your valuable feedback in the comment section below.

Ref From: tecmint
Channels: archive tools

Related articles