Which Command Would You Use to Create a Compressed File That Can Be Read by Windows Os Linux

The tar command on Linux is often used to create .tar.gz or .tgz annal files, besides called "tarballs." This command has a big number of options, just you just need to recollect a few letters to quickly create archives with tar. The tar command tin excerpt the resulting archives, too.

The GNU tar command included with Linux distributions has integrated compression. It can create a .tar annal and then compress it with gzip or bzip2 compression in a single command. That's why the resulting file is a .tar.gz file or .tar.bz2 file.

Compress an Entire Directory or a Unmarried File

Employ the following command to compress an entire directory or a single file on Linux. Information technology'll also shrink every other directory within a directory you specify–in other words, information technology works recursively.

tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

Here's what those switches actually mean:

  • -c: Create an archive.
  • -z: Compress the annal with gzip.
  • -5: Display progress in the concluding while creating the archive, also known as "verbose" mode. The v is ever optional in these commands, but it's helpful.
  • -f: Allows you lot to specify the filename of the archive.

Let's say you have a directory named "stuff" in the current directory and you desire to save it to a file named archive.tar.gz. You'd run the following command:

tar -czvf archive.tar.gz stuff

Or, let's say in that location's a directory at /usr/local/something on the current system and you want to compress it to a file named archive.tar.gz. You'd run the following command:

tar -czvf archive.tar.gz /usr/local/something

Compress Multiple Directories or Files at Once

RELATED: How to Manage Files from the Linux Last: 11 Commands Y'all Need to Know

While tar is oft used to shrink a single directory, you could likewise use information technology to compress multiple directories, multiple individual files, or both. Only provide a list of files or directories instead of a single one. For example, let'southward say y'all want to compress the /home/ubuntu/Downloads directory, the /usr/local/stuff directory, and the /dwelling/ubuntu/Documents/notes.txt file. Y'all'd just run the following command:

tar -czvf archive.tar.gz /home/ubuntu/Downloads /usr/local/stuff /home/ubuntu/Documents/notes.txt

Merely listing as many directories or files as you lot want to back up.

Exclude Directories and Files

In some cases, you may wish to compress an entire directory, but not include certain files and directories. Y'all tin practice then by appending an --exclude switch for each directory or file you desire to exclude.

For example, let's say you want to compress /home/ubuntu, but you don't desire to shrink the /home/ubuntu/Downloads and /dwelling/ubuntu/.cache directories. Here'due south how yous'd do it:

tar -czvf archive.tar.gz /home/ubuntu --exclude=/domicile/ubuntu/Downloads --exclude=/home/ubuntu/.cache

The --exclude switch is very powerful. It doesn't have names of directories and files–information technology actually accepts patterns. There's a lot more you can do with information technology. For case, you could archive an entire directory and exclude all .mp4 files with the post-obit command:

tar -czvf annal.tar.gz /home/ubuntu --exclude=*.mp4

Apply bzip2 Compression Instead

While gzip compression is most oftentimes used to create .tar.gz or .tgz files, tar also supports bzip2 compression. This allows you to create bzip2-compressed files, oftentimes named .tar.bz2, .tar.bz, or .tbz files. To do so, just replace the -z for gzip in the commands here with a -j for bzip2.

Gzip is faster, but it generally compresses a bit less, so you get a somewhat larger file. Bzip2 is slower, simply it compresses a scrap more, and so yous become a somewhat smaller file. Gzip is also more than common, with some stripped-down Linux systems including gzip support past default, only non bzip2 support. In general, though, gzip and bzip2 are practically the same thing and both will piece of work similarly.

For instance, instead of the starting time instance nosotros provided for compressing the stuff directory, you'd run the following command:

tar -cjvf archive.tar.bz2 stuff

Extract an Annal

One time you lot have an archive, you can extract it with the tar control. The post-obit command volition extract the contents of archive.tar.gz to the current directory.

tar -xzvf archive.tar.gz

It's the aforementioned every bit the archive creation command nosotros used above, except the -ten switch replaces the -c switch. This specifies you desire to eastward10tract an archive instead of create one.

You lot may want to extract the contents of the annal to a specific directory. You can exercise so past appending the -C switch to the terminate of the control. For case, the following command volition extract the contents of the annal.tar.gz file to the /tmp directory.

tar -xzvf archive.tar.gz -C /tmp

If the file is a bzip2-compressed file, replace the "z" in the above commands with a "j".


This is the simplest possible usage of the tar control. The control includes a large number of additional options, so we can't mayhap listing them all here. For more information. run the info tar control at the shell to view the tar control's detailed information page. Press the q central to quit the information page when you're done. You can also read tar'southward manual online.

If you lot're using a graphical Linux desktop, you could besides employ the file-compression utility or file manager included with your desktop to create or extract .tar files. On Windows, you can extract and create .tar archives with the free seven-Zip utility.

grayletly1995.blogspot.com

Source: https://www.howtogeek.com/248780/how-to-compress-and-extract-files-using-the-tar-command-on-linux/

0 Response to "Which Command Would You Use to Create a Compressed File That Can Be Read by Windows Os Linux"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel