09.10.2021

Creating and Extracting Archives Using the Tar Command in Linux. Linux backup - tar tar command description


The tar utility in Linux is designed to combine (pack) multiple files into one, that is, to create archives. It has good functionality for working with archives, can efficiently move files (archives or tar files) from one device to another (including tape devices), while maintaining file attributes and file system structure. All this allows you to use the utility as a full-fledged tool for organizing backups. Of course, there are other specialized utilities for these purposes. Like dump, but sysadmins can benefit from knowing how to deal with tar as well.

Specifics of using the tar utility

As already noted, the utility combines several directories and files into one tar file, which can then be compressed using, for example, gzip, compress, or bzip2. This is very convenient when you need to reserve both data and free up additional disk space. The utility is often used when you need to create short-term data backups.

Among the non-GNU tar versions, the vast majority of those that do not support file names longer than 100 characters, and also do not know how to work with multiple tapes, therefore, before using the specific version of the utility available, you should carefully read the official technical See the documentation (man tar command) for details like this. Also, not all versions of tar handle symbolic links by default - different keys are used for this from version to version, which can also be found in the documentation. The utility is very well suited for quickly copying a directory tree.

Tar Command Syntax and Options

The tar utility has the following syntax:

tar [options ] title_archive files_for_archive

For example, using the command:

$ tar -cf etc.tar / etc

you can make a copy of the / etc directory to the etc.tar archive. The above example demonstrates a common case for backing up using the tar command. Here the -c option means create an archive, -f - output the results to a file. In the second part of the command, which accepts the output stream from tar -cf, the -x (extract) option tells tar to extract the contents of the archive, -p to save information about the file access modes. There is also the -b option, which allows you to set the block merging factor, which is useful when writing to tape devices. This in some cases allows for better performance. The optimal value is 20, however, by experimenting, you can find the best option for specific conditions. The -v option allows you to display detailed information about the progress of the command.

Syntax for unpacking:

tar [options ] archive

For example the command

$ tar xfv archive.tar

Unpack archive.tar into the current directory, to specify the directory where you want to unpack the archive, use the -c switch. for instance

$ tar xfv archive.tar -c / var

Below is the main list of options for tar command

-A, —Catenate, —concatenate attaching tar files to an archive
-c, —Create create a new archive
-d, —Diff, —compare find differences between archive and filesystem
—Delete delete from archive (not on magnetic tapes!)
-r, —Append add files to the end of the archive
-t, --List list the contents of the archive
—Test-label check archive volume label and exit
-u, —Update add only newer files to the archive
-x, —Extract, —get extract files from archive

Please note that when you run a command, it is not necessary to put a hyphen in front of the keys

tar examples

As already mentioned, to create compressed archives, the archive itself is first created with the tar command, and then the archive is compressed using gzip. But you can do all this with one tar command:

$ tar -cvzf archive.tgz *

The result will be created compressed gzip archive.tgz, which will be compressed using gzip and the z option. The "*" symbol indicates that everything in the current directory will be included in the archive. The target archive archive.tgz will also be created here. Instead of the z option, you can specify others - Z, J, j, which specify the corresponding compression algorithms - LZV, xz and bzip2.

Just in case, before creating backups, it is better to go to the root directory "/" - the utility removes the initial "/" character from the file names / paths, which is why later information from the archives may not be restored quite correctly.

In the case of backup (to tape), you can use the following commands:

$ cd / $ tar -cpf / dev / st0 --label = "Backup at` date "+% d-% B-% Y" `." -C / home

As you can see, / dev / st0 is used as the archive name - the tape device. Therefore, to identify archives, it is useful to use the –label option, which specifies the description of a specific archive. Back quotes are used to substitute a mask for the date / time of the archive creation. The -C (or -directory) option specifies the directory to be backed up. To perform an incremental backup, i.e. when you need to back up only files that have changed since the previous backup, use the -N option:

$ cd / $ tar -cpNf / dev / st0 --label = "Backup at` date "+% d-% B-% Y" `." -C / home

After creating a backup, it will not be superfluous to check with the -d option that the archive is intact:

$ cd / $ tar -dvf / dev / st0

To back up the entire system, you can use the following command:

$ cd / $ tar -cpf / sysarchive / system-at-`date "+% d-% B-% Y" `.tar -C / --exclude = proc --exclude = mnt --exclude = archive - exclude = cache --exclude = * / lost + found.

Here, using the -exclude options, specify which directories should be excluded from the archiving procedure, and the dot symbol "." at the end of the command says that you need to process all directories and files located in the directory specified by the -C option. It should be noted that in this example, unlike the previous ones, the tar file itself is specified as the target archive, and not a tape device.

If you find an error, please select a piece of text and press Ctrl + Enter.

tar is a GNU archiver. tar takes multiple files and / or directories and concatenates them into one large file. This allows you to compress an entire directory tree, which cannot be done with or bzip2. Tar has many options, which are detailed on its man page.

$ man tar tar -xvvf foo.tar extract foo.tar tar -xvvzf foo.tar.gz extract gzipped foo.tar.gz tar -cvvf foo.tar foo / tar contents of folder foo in foo.tar

Commonly used tar command options

    C - create a new archive

    X - extract (extract) files from the archive

    –Delete - delete (delete) files from the archive

    R - append files to an existing archive

    A - append tar files to an existing archive

    T - list of files in the archive (contents of the archive)

    U - update (update) archive

    D - operation of comparing an archive with a given file system

    Z - processing an archive with gzip and gunzip examples. Compress or uncompress, depending on the combination of the accompanying -c or -x options.

    J - archive processing with bzip2. Compress or uncompress, depending on the combination of the accompanying -c or -x options.

tar is launched with the obligatory indication of one of the main actions, the most common of which is creating and unpacking archives, then other parameters are set depending on the specific operation.

The most common use of tar is to decompress and unzip a package downloaded from a website or ftp site. Most files have a .tar.gz extension. Quite often they are called "tarball" "s. This means multiple files that are archived with tar and then compressed with gzip. old Unix systems.

Alternatively, you may come across the .tar.bz2 files. This is how the kernel sources are distributed because it takes up less boot space. As you might have guessed, these are files zipped with tar and compressed with bzip.

You can extract all files from such an archive using tar with several command line options. Unzipping a tarball is done with the -z option, which means the file must be run through gunzip first and then unpacked. The most common method for unpacking tarballs :

% tar -xvzf .tar.gz file

There are quite a few options here. What do they mean? The -x option means extract. This is important because it tells tar "y exactly what to do with the input file. In this case, it will be split again into the files from which it was" stitched ". The -v option turns on verbose mode. the names of all the files to be extracted from the archive. It would be nice to use this option so that unpacking does not look too boring. You can also use -vv to make the output even more verbose and you get even more information about the files being extracted. The -z option tells tar " y stating that the .tar.gz file needs to be run through gunzip first. Finally, the -f option tells tar "y that the next line on the command line is the file to work with.

There are several ways to write this same command. On older systems that do not have a suitable copy of GNU tar, you may see the following entry for the same command:

% gunzip .tar.gz file | tar -xvf -

In this command, the file is first unpacked and the result is sent to tar. Because gzip writes output to stdout by default, this command will write the unpacked file to stdout. The pipeline then redirects this stream to tar for decompression. The “-” sign means that the data is taken from the standard input. Thus, the command will unzip the data stream received from gzip and write it to disk.

Another way to write the original command is to remove the “-” sign in front of the options:

% tar xvzf .tar.gz file

You may also come across a bzip "zipped archive. The version of tar provided in Slackware Linux can handle them in the same way as gzip" archives. Just instead of the -z option, you need to use -j:

% tar -xvjf .tar.bz2 file

Note that tar will save the extracted files from the archive to the current directory. Therefore, if you have an archive in / tmp that you want to unpack into your home directory, you have several options. First, the archive can be moved to your home directory and then expanded using tar. Second, you can specify the path to the archive on the command line. Third, you can use the -C option to unzip the tarball to the directory specified after this option.

% cd $ HOME% cp /tmp/.tar.gzfile. % tar -xvzf .tar.gz file% cd $ HOME% tar -xvzf /tmp/ .tar.gz file% cd /% tar -xvzf /tmp/.tar.gz file -C $ HOME

All of the above entries are equivalent. In each of them, the archive is expanded to your home directory, while the original compressed archive remains in place.

So, what's good about the fact that you can unpack archives if you can't create them? tar can do that too. In most cases, you can simply replace the -x option with -c.

% tar -cvzf .tar.gz file.

In this command, the -c option tells tar "y to create an archive, and the -z option passes the resulting archive through gzip to compress it. The .tar.gz file is the name of the file to create.

The -f option is not always required, but it is better to use it anyway. Without it, tar will write its data to standard output, which is usually used to pipe a stream to another program, like this:

% tar -cv .tar file. | gpg --encrypt

This command creates an uncompressed tarball with the contents of the current directory, and then runs the tarball through the gpg program, which encrypts and compresses the archive, making it impossible for anyone who does not have your private key to read it.

tar over ssh

If the source computer and the target computer are connected via LAN or WAN, you can combine the use of SSH (Secure Shell) and tar to archive, copy and extract files in one go to save time. Here's how to do it:

$ (cd ~ / stuff; tar --create --gzip --file - *) | \ ssh destination tar --extract --gunzip --file --verbose -C stuff

This command performs several actions at once. Let's break it down:

    The sequence of commands enclosed in parentheses is called a subshell. Changes made to the subshell - such as changing the directory - will not affect the command as a whole, but only the sub-shell environment. So the first escape sequence - (cd ~ / stuff; tar –create –gzip –file - *) changes the current working directory to ~ / stuff and then starts tar. Since the nested shell is followed by a redirection to the pipe, all the results of the subshell are sent to the next command in line.

    Like many other UNIX utilities, tar can write to stdout and read from stdin. Both stdout and stdin are usually denoted by a hyphen (-). Therefore, the –create –file command creates an archive on stdout.

    The pipe (|) transfers all the results of the subshell to the ssh utility, which, in turn, transfers all the necessary data from the source computer to the remote one.

    Finally, the remote computer runs its own instance of the tar utility to extract the data from the archive. Now –extract –file - reads the archive from standard input. The -C option forces tar on the target computer to change the current working directory to stuff before starting any unzip operations. The end result of this command as a whole will be to ssh the archive and unpack it into ~ / stuff.

So, with one command, the archive was created, transferred and unpacked. By the way, by slightly changing this command, you can copy the archive from the remote computer to the local one and unzip it. Here is the command to run on the local computer:

$ ssh destination cat archive.tgz | \ (cd ~ / stuff; tar --extract --gunzip --file -)

The archive on the remote machine will be opened, then a stream of bytes from cat will be sent to a nested shell, which will change the working directory and then extract the archive. (Adding -C ~ / stuff to the tar command will produce the same results; the example only shows that subshells can handle input as well.)

tar exclude

–Exclude pattern (-W exclude = pattern) Do not process files or directories that match the specified pattern. Note that exclusions take precedence over patterns or filenames specified on the command line.

    Example: Exclude the subdirectory from the test directory when archiving tar.svn tar -czf test1.tar.gz --exclude = ". Svn" test /

    Example: When zipping the current directory and compressing Examples of using gzip and gunzip, exclude the file with the extensions .tar.gz .iso .deb .py $ tar -czf test.tar.gz *. * --Exclude = "*. Tar.gz "--exclude =" *. iso "--exclude =" *. deb "--exclude =" *. zip "--exclude =" *. py "

tar preserving permissions

Create an archive with preservation of access rights. Switch -p, –preserve-permissions, –same-permissions extract information about file permissions (default for superuser)

Tar -cvpf archive.tar.gz dir1

Unpack the archive while maintaining access rights

Tar -xvpf archive.tar.gz

tar unpack to the desired directory

To unpack the archive into the desired directory, use the -C switch

# man tar ... -C directory In c and r mode, this changes the directory before adding the following files. In x mode, change directories after opening the archive but before extracting entries from the archive. ...

For example, example tested for FreeBSD:

# tar -xvf /usr/home/darkfire/backup.ns.server.254/usr/ports/distfiles.tar -C / usr / ports /

tar split split an archive into several parts

Split -b 1000m distfiles.tar distfiles.split.tar

As a result, you will get a lot of files like

Distfiles.split.taraa distfiles.split.tarab distfiles.split.tarai

100m means 100 megabytes. You can write 100k - it will be 100 kilobytes. You can put them back together like this:

Cat distfiles.split.tar * | tar zxvf -

The tar command line utility is used to work with archives on UNIX-based operating systems. With its help, you can archive data and optimize the use of disk space.

Creating and unpacking archives

Create

Creation is done with a key c... The syntax is as follows:

tar -c<опции> <новый архивный файл> <что сжимаем>

Example of creation:

tar -czvf archive.tar.gz / home / dmosk

* in this example, an archive will be created archive.tar.gz user's home directory ( / home / dmosk)
** where z- compress the archive in gzip (without this parameter, tar does not compress, but creates a so-called tarball); c- a key to create an archive; v- verbose mode, that is, with displaying the process (very convenient for monitoring the progress of work, but you can skip it in scripts); f- use a file (be sure to indicate, since we mostly work with files).

Unpack

Unpacking is performed with a key x with syntax:

tar -x<опции> <архивный файл>

Unpacking example:

tar -xvf archive.tar.gz

Examples of

gz

Unpacking the .gz file:

tar -xvf archive.tar.gz

* when an error occurs This does not look like a tar archive, you can use the command gzip -d archive.tar.gz.

bz2

tar -xvjf archive.tar.bz2

* the j key is responsible for working with bz2.

If the system swears at bzip2, then you need to install it:

yum install bzip2

apt-get install bzip2

pkg install bzip2

* respectively, for CentOS (RPM based), Ubuntu (deb based), FreeBSD (BSD based).

If we see an error tar: Unrecognized archive format, let's use the following command:

bzip2 -d archive.tar.bz2

gzip

tar -xvzf archive.tar.gzip

* the z key is responsible for working with gzip.

tgz

Unpacked as gzip:

tar -xvzf archive.tgz

Unpack to a specific folder

tar -C / home / user -xvf archive.tar.gz

* key -C used to specify the folder where you want to unpack files from the archive.

Unpacking without subfolder

This method can be used to unpack into a prepared directory. There will be some effect of renaming the directory or an analogue of "Unpack here":

tar -C / home / admin / mytar -xvf admin.tar.gz --strip-components 1

* catalog / home / admin / mytar must be created in advance; --strip-components 1 will skip one subfolder inside the archive.

Excluding files by mask

If you need to skip some files, enter the command with the --exclude key:

tar -czvf archive.tar.gz / wwwsite --exclude = "sess_ *"

* in this example we will create an archive archive.tar.gz, in which there will be no files starting with sess_.

Description of tar keys

Commands for action

* you cannot use several of the above keys in one command.

Additional options

Key Description
--atime-preserve Leave the same access time stamp for the file.
-b N Set the block size to N x 512.
-C Directory change. By default, the one we are in is used.
--checkpoint Show folder names when reading archive file.
-G Use the old incremental backup format when displaying or retrieving.
-g Use a new incremental backup format when displaying or retrieving.
-h Don't duplicate symbolic links. Only the files that these symlinks point to.
-i Ignore blocks of zeros.
-j Using bzip2.
--ignore-failed-read Ignore unreadable files.
-k When unpacking, the existing files are not replaced by the corresponding files from the archive.
-L N Change of magnetic tape after N * 1024 bytes.
-m When retrieving, ignore the modification time of the object.
-M Multivolume archives.
-N DATE Keep only newer files relative to DATE
-O The direction of what is fetched to standard output.
-p Extraction of protected information.
-P Does not strip leading slashes (/) from names.
-s Sorting files on checkout.
--preserve Similar to -ps
--remove-files Remove original files after adding to archive.
--same-owner Keep owner on checkout.
--totals Output of bytes when creating an archive.
-v Logging of actions - displaying a list of objects on which the action is taking place.
-V NAME Create an archive on a volume labeled NAME.
--version Show tar version.
-w Require confirmation for every action.
-W Checking the archive after recording.
--exclude FILE Exclude file FILE.
-X FILE Exclude files FILE.
-Z Filters the archive using compress.
-z Using gzip.

* the current list of options can be obtained by the command man tar.

The tar command in Linux is used to create an archive of files and directories. With the “tar” command you can create an archive file in the following formats: “ .tar“, “.tar.gz“, “.tar.bz2”. They are known as “ tarball“, “gizp“, “bzip" v . Tar is more flexible than ZIP, which is widely used in a cross-platform environment.

We will show tar command examples in this article.

First, see how many options are available to the command

Main operating mode:

  • -A, -catenate, -concatenate Add files to tar archive
  • -c, -create create a new archive
  • -d, -diff, -compare find differences between archive and filesystem
  • -delete delete from archive (not on magnetic tapes!)
  • -r, -append add files to the end of the archive
  • -t, -list list the contents of the archive
  • -test-label check archive and exit volume label
  • -u, -update only add newer files to archive
  • -x, –extract, –get extract files from archive

Compression options:

  • -a, -auto-compress suffix use archive to define program compression
  • -I, –use-compress-program = PROG filter over PROG (should accept -d)
  • -j, -bzip2 filter for archiving via bzip2
  • -J, -xz filter archives through XZ
  • -lzip filter archives via Lzip
  • -lzma filter archives through lzma
  • -lzop
  • -no-auto-compress do not use archive suffix to define compression program
  • -z, -gzip, -gunzip, -ungzip filter archive via GZIP
  • -Z, -compress, -uncompress filter archive using compression

I choose the installer for the demo. The total size of the installer is 26MB. We will check the zipped file size of each suggested compression method.

1. Create a file archive with tar

Archive Tar does compression of files and folders automatically. Archived can be stored on disk or can be transferred to another disk or it can be used for email attachments.

Tar -caf wordpress.tar wordpress /

The archive size is reduced to 23MB.

2. Create a tar.gz file archive

GZ stands for Gunzip. The .tar.gz archive can compress files and folders in an efficient way.

Tar -czf wordpress.tar.gz wordpress /

The archive size is reduced to 7.6Mb. Pretty impressive!

# ls -lh -rw-r - r-- 1 root root 23M Jan 5 22:09 wordpress.tar -rw-r - r-- 1 root root 7.6M Jan 5 22:15 wordpress.tar.gz

3. Create tar.bz2 archive

BZIP is more efficient to reduce the size of the archive file.

Tar -cjf wordpress.tar.bz2 wordpress /

The archive size is reduced to 6.9MB.

# ls -lh -rw-r - r-- 1 root root 23M Jan 5 22:09 wordpress.tar -rw-r - r-- 1 root root 6.9M Jan 5 22:27 wordpress.tar.bz2 - rw-r - r-- 1 root root 7.6M Jan 5 22:26 wordpress.tar.gz

4. Untar tar file archive

Convenience and ease of use of any archive, if useful, when it can be easily unpacked. Unzip the file .tar

Tar -xf wordpress.tar or tar -xf wordpress.tar / home / andreyex / extracted

The 'X' stands for unpacking.

5. Unpack the tar.gz archive file

tar -xzf wordpress.tar.gz

6. Unpacking tar.bz2 file archive

tar -xjf wordpress.tar.bz2 tar tf wordpress.tar wordpress / wordpress / wp-blog-header.php wordpress / wp-login.php wordpress / wp-config-sample.php wordpress / wp-admin / wordpress / wp- admin / link-parse-opml.php wordpress / wp-admin / ms-upgrade-network.php wordpress / wp-admin / themes.php

8.Untar specific file from tar archive file

tar -xf wordpress.tar wordpress / wp-config-sample.php

That's all for now. These are the main tar command examples on Unix / Linux.

These days we come across archive files very often and on all platforms: Windows, Mac or Linux. These can be programs, backups of systems or databases, or just an archive of files. We also often have to create our own archives in Linux in order to transfer several files to friends or upload to a file hosting service. In the form of archives, software packages, source codes, as well as many other files distributed on the Internet are distributed. It is very important to learn how to archive files in Linux through the terminal, you may need it when there is no access to the graphical interface, or it will just become more pleasant to work in the terminal over time.

In this manual, I want to take a closer look at utilities for archiving in Linux, we will consider not only the most popular and universal utility - tar, but also other lesser known, as well as popular compression algorithms.

It is important to note that archiving on linux is not the same as compressing linux files. Archiving is the consolidation of several small files into one, with the aim of more convenient subsequent transfer, storage, encryption or compression. As I said, archiving is performed by special utilities. We will not touch the archiving of files in the graphical interface, you will deal with them yourself, our topic is the terminal.

The most popular Linux archiving utility is tar. It is used almost everywhere, for archiving sources, packaging packages. For compression, other utilities are used, depending on the compression algorithm, for example, zip, bz, xz, lzma, etc. First, archiving is performed, then compression, by separate programs. The automatic launch of some compression utilities for a newly created archive is supported by tar and other similar programs with special options.

Encryption is also a useful archiving feature. But now let's look at what utilities exist that archive linux files and how to use them.

Tar

Tar is a standard utility that can be used to archive Linux files. Gradually, from a small archiving program, it turned into a powerful tool that supports work with many options for archives and compression algorithms. The program supports a large number of parameters. Let's take a look at its syntax and basic parameters:

$ tar options f file_to_record / folder_files_for_archive

Now let's take a look at the main options:

  • A- add file to archive
  • c- create an archive in linux
  • d- compare archive files and unpacked files in the file system
  • j- compress archive with Bzip
  • z- compress archive using Gzip
  • r- add files to the end of the archive
  • t- show the contents of the archive
  • u- update the archive relative to the file system
  • x- extract files from archive
  • v- show detailed information about the work process
  • f- file for recording the archive
  • -C- unpack to the specified folder
  • --strip-components- discard n subfolders

Now let's take a look at archiving files on Linux. To create an archive use the following command:

tar -cvf archive.tar.gz / path / to / files

And to unpack tar linux archive:

tar -xvf archive.tar.gz

It is very easy to remember for packing the option is used c - C reate, and to unpack - x- e X tract.

A compressed archive is created in the same way, only with the -z option, this is the case if gizp encryption was used, if bzip is needed then the -j option is used:

tar -zcvf archive.tar.gz / path / to / files

$ tar -zxvf archive.tar.gz

For example, let's take a look at how to zip a folder on Linux:

tar -zcvf home.tar.gz ~ /

Although you can do it differently, we get the same archive if we first create a regular archive using tar, and then compress it with a compression utility, only here we get more control over the compression process:

gzip archive.tar

You can also remove compression:

gunzip archive.tar.gz

We'll look at the compression utilities below.

To add a file to the archive use:

tar -rvf archive.tar file.txt

To extract a single file, the syntax is the same:

tar -xvf archive.tar file.txt

You can extract multiple files by matching pattern using the wildcard parameter, for example, extract all php files:

tar -xvf archive.tar --wildcards "* .php"

By default, you can unpack the tar linux archive into the current folder with the name of the archive; to unpack it into the desired folder, use the -C switch:

tar -xvf archive.tar -C / path / to / dir

We have reviewed the standard utility, now we will briefly consider its alternatives. There are not many of them, and most of them are already outdated.

Shar

Shar allows you to create self-extracting archives. It is essentially a shell script and needs a Bash or other Bourne Shell compatible shell to decompress. Shar has several advantages, but it is also potentially insecure as the archive is an executable file.

Shar options:

  • -o- save archive to file instead of standard output
  • -l- limit the size of the output file
  • -L- limit the size of the output file and split it into parts
  • -n- the archive name will not be included in the header
  • -a- enable automatic generation of headers

Examples of using shar to archive a linux folder:

Create a shar archive:

shar file_name.extension> filename.shar

Unpack the shar archive:

Ar

ar is a utility for creating and managing archives. It is mainly used for archiving static libraries, but can be used to create any kind of archives. It used to be quite common but has been supplanted by the tar utility. Currently used only for creating and updating static library files.

  • - d- remove modules from archive
  • - m- moving members in the archive
  • - p- print specific members of the archive
  • - q- quick addition
  • - r- add a member to the archive
  • - s- create archive index
  • - a- add a new file to an existing archive

Now let's look at examples of use. Let's create a static library libmath.a from the object files substraction.o and division.o:

ar cr libmath.a substraction.o division.o

Now let's extract the files from the archive:

This way, you can unpack any static library.

Cpio

cpio stands for Copy in and out. This is another standard Linux archiver. Used extensively in the Red Hat package manager, as well as for creating initramfs. Linux archiving does not apply to regular files with this program.

Utility options:

  • -a- reset access time to files after copying them
  • -A- add file
  • -d- create directories if necessary

Usage example. Create a cpio archive:

file1.o file2.o file3.o

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

Unpack the archive:

cpio -idv< /path/to folder/obj.cpio

The linux folder is also archived by itself.

Compressing archives on Linux

How to create an archive in linux was discussed. Now let's talk about compression. As I said, special utilities are used for compression. Let's briefly consider a few of them.

Gzip

The most commonly used is Gzip. This is the standard Unix / Linux compression utility. For decompression, use gunzip or gzip -d First, let's look at the syntax:

$ gzip options file

$ gunzip options file

Now let's take a look at the options:

  • -c- output archive to standard output
  • -d- unpack
  • -f- force unpack or compress
  • -l- show information about the archive
  • -r- recursively iterate over directories
  • -0 - minimum compression level
  • -9 - maximum compression level

You have already seen examples of usage in the description of the tar utility. For example, let's compress a file:

gzip -c file> archive.gz

Now let's unpack:

gunzip -c.gz archive

But to compress a folder on Linux, you have to first zip it with tar, and then compress the zip file with gzip.

Bzip

bzip2 is another alternative compression utility for Linux. It is more efficient than gzip, but slower. Use the bunzip2 utility to unpack it.

I will not describe the options for bzip2, they are similar to gzip. To create an archive on Linux use:

Bz2 file will be created in the current directory

Lzma

New and highly efficient compression algorithm. The syntax and options are similar to Gzip too. Use unlzma to unpack.

Xz

Another highly efficient compression algorithm. Backward compatible with Lzma. The call parameters are similar to Gzip too.

Zip

Cross-platform utility for creating compressed zip archives. Windows compatible implementations of this algorithm. Zip archives are very often used to exchange files on the Internet. With this utility you can compress both files and compress the linux folder.

Utility syntax:

$ zip options files

$ unzip options archive

Utility options:

  • -d delete file from archive
  • -r- recursively traverse directories
  • -0 - only archive, no compression
  • -9 - the best compression ratio
  • -F- fix zip file
  • -e- encrypt files

To create a Zip archive in Linux use.


2021
maccase.ru - Android. Brands. Iron. news