5 Best Command Line Archive Tools for Linux – Part 1

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

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.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

7 Responses

  1. Do not know how will the data center to backup data, but in my tests that have been mainly do backups of files on NTFS partitions I have come to the conclusion that whenever data is lost, there are files that are not copied by permission error I have not found how to solve this problem.

    My favorite tools are Rsync to back up files without compressing them. Ever I made a tar 50GB and then failed on some point after trying to unzip.

    And Tar uncompressed files to store long term and/or for divide them into DVDs.

    I definitely like to avoid compression to the maximum, or limit the size of compressed files according to my need is for now, the maximum size of a DVD.

    What are the most efficient ways to divide files into volumes ?, eg DVDs?

    These are my favorite uses of tar
    $ tar -cvf dvd-001.tar -ML 4480M –totals=SIGQUIT -C source

    I failed to understand understood the script indicated in the documentation for an automatic Tar multivolume.

    • Ravi Saive says:

      @Jesus,

      Thanks for sharing your real life backup scenarios with us, to be fact I never use tar command, when my data is larger than 15GB, because it takes lots of time in compressing the data or moving from one location to another. So, I always use rsync tool and recommend anyone who want to make a larger backups and it’s easier to make a mirrors of folders in local or remote. If you still want to split the files, better user split command as shown:

      # split -b 1024m file.tar.gz
      

      Read more about split command man pages..

    • Researching the multi volume tar, but I do not work for me
      http://www.gnu.org/software/tar/manual/html_node/Multi_002dVolume-Archives.html

      $ vim new-volume.sh

      #! /bin/bash
      # For this script it’s advisable to use a shell, such as Bash,
      # that supports a TAR_FD value greater than 9.

      echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.

      name=`expr $TAR_ARCHIVE : ‘\(.*\)-.*’`
      case $TAR_SUBCOMMAND in
      -c) ;;
      -d|-x|-t) test -r ${name:-$TAR_ARCHIVE}-$TAR_VOLUME || exit 1
      ;;
      *) exit 1
      esac

      echo ${name:-$TAR_ARCHIVE}-$TAR_VOLUME >&$TAR_FD

      $ chmod 755 new-volume.sh

      $ tar -c -L650M -f cd-disk.tar -F new-volume Videos
      tar: new-volume: Cannot exec: No such file or directory
      tar: Error is not recoverable: exiting now
      tar: ‘new-volume’ command failed
      tar: Error is not recoverable: exiting now

      This creates the first tar file named cd-disk.tar 650 MB correctly, but then throws an error and not continuous creaando the multivolume.

      Some clue?, Thanks.

  2. Sir999 says:

    Why are you using this – >

    # gunzip file_name.tar.gz

    Can you not directly use this ->

    # tar -zxvf file_name.tar.gz

    • Avishek Kumar says:

      sir999

      tar has a lot of option and is quite confusing too, at times. gunzip was a straight command. Moreover we mean to show the use of gunzip there.

      Hope you understand.

  3. Martin D says:

    Agreed – but that wasn’t the typo that I first saw.

    Take a look at the first sub heading – What is Archieved file? Exactly how that one got past the Spell Check I’m not sure.

  4. steve p. says:

    My pet peeve are typos:

    “shar has an advantage of being **plane** text ”

    I am sure you meant “plain text”, not “plane text”. I imagine “plane text” would be the magazines in the seat backs one jets.

    It was funny though, and very typical of the state of internet writing.

    Good article though.
    Steve

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.