- 5 Best Command Line Archive Tools for Linux – Part 1
- What is Archived file?
- Features of Archiving
- Area of Application
- 1. tar Command
- tar options
- shar Command
- shar options
- 3. ar Command
- ar options
- 4. cpio
- cpio options
- 5. Gzip
- gzip options
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- Related Posts
- 7 thoughts on “5 Best Command Line Archive Tools for Linux – Part 1”
- Got something to say? Join the discussion. Cancel reply
- Difference between archiving and compression
- 2 Answers 2
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
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
- Data Compression
- Encryption
- File Concatenation
- Automatic Extraction
- Automatic Installation
- Source Volume and Media Information
- File Spanning
- Checksum
- Directory Structure Information
- Other Metadata (Data About Data)
- Error discovery
Area of Application
- Store Computer Files System along with Metadata.
- Useful in transferring file locally.
- Useful in transferring file over web.
- 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
- -A : Append tar files to existing archives.
- -c : Create a new archive file.
- -d : Compare archive with Specified filesystem.
- -j : bzip the archive
- -r : append files to existing archives.
- -t : list contents of existing archives.
- -u : Update archive
- -x : Extract file from existing archive.
- -z : gzip the archive
- –delete : Delete files from existing archive.
tar Examples
Create a tar archive file.
Decompress an tar archive file.
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
- -o : Save output to archive files as specified, in the option.
- -l : Limit the output size, as specified, in the option but do not split it.
- -L : Limit the output size, as specified, in the option and split it.
- -n : Name of Archive to be included in the header of the shar files.
- -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.
Extract an shar archive file.
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
- -d : Delete modules from the archive.
- -m : Move Members in the archive.
- -p : Print specified members of the archive.
- -q : Quick Append.
- -r : Insert file member to archive.
- -s : Add index to archive.
- -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.
To extract an ‘ar’ archive file.
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
- -0 : Read a list of filenames terminated by a null character instead of a newline.
- -a : Reset Access time.
- -A : Append.
- -b : swap.
- -d : Make Directories.
cpio Examples
Create an ‘cpio’ archive file.
To extract a cpio archive file.
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
- –stdout : Produce output on standard output.
- –to-stdout : Produce output on standard output.
- –decompress : Decompress File.
- –uncompress : Decompress File.
- -d : Decompress File.
- -f : Force Compression/Decompression.
gzip Examples
Create an ‘gzip’ archive file.
To extract a ‘gzip’ archive file.
The above command must be passed followed with below command.
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.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Related Posts
7 thoughts on “5 Best Command Line Archive Tools for Linux – Part 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.
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:
Read more about split command man pages..
#! /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 $
;;
*) exit 1
esac
$ 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.
Why are you using this – >
Can you not directly use this ->
# tar -zxvf file_name.tar.gz
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.
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.
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. Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Источник
Difference between archiving and compression
What is the difference between Archiving and compression in Linux?
We have different commands for both which we can combine too.. but what exactly are they?
2 Answers 2
Archiving means that you take 10 files and combine them into one file, with no difference in size. If you start with 10 100KB files and archive them, the resulting single file is 1000KB. On the other hand, if you compress those 10 files, you might find that the resulting files range from only a few kilobytes to close to the original size of 100KB, depending upon the original file type. (source)
Compression is a process of taking some input data, and by using some sophisticated algorithm, compressing it (transform the bits, effectively), in order to have the same entity that weighs less size.
This is useful if you want to keep more data in a less space (space is always limited resource), or if you just want to have a faster file-transfer throughout networks.
Popular compression utility programs, on Linux distributions, are:
gzip (frequently used);
bzip2 (less frequently used, yet produces smaller output file than gzip);
xz (most space-efficient tool, in Linux, so far)
zip (often used for decompressing data, that was compressed on other systems using zip , like Windows OS).
Note, that generally, more efficient compression method is, more time it takes.
Archiving, on the other hand, can be thought of like putting some different files into one box. If you have 5 files, each of a size of 10kb, archiving those will give you 5 x 10 = 50kb, and that is it.
Note, that on Linux, we have a very good program tar, which, when given an input, does both:
- archives the input (first step);
- and then compresses that archive.
Источник