How to use tar for archiving
If you are running a Linux Distribution, Mac OS X, or other Unix-like operating systems, your system will already have the tar program.
You can check the
tarmanual by typing$man tarin the terminal.
How to unpack a tarball
-
To unpack a
tarball, use the following command:$ tar xvf <tarball>In this command, the
xstands for extract,vstands for verbose output, andfrepresents the filename of the archive. -
To uncompress a gzip-compressed tar, use option
zin addition to the command above.$ tar xvzf <tarball>The
zstands for uncompressing a gzip archive. -
To uncompress a bzip2 compressed tar, use option
jinstead ofz:$ tar xvjf <tarball>
How to create a tarball
-
To create a
tararchive, use the command below:$ tar cvf <tarball name> <file/directory to be archived>The
cstands for create archive,vstands for the verbose list files that have been processed, andfrepresents the filename of the archive. -
To create a compressed archive, use the following command:
$ tar cvzf <tarball name> <file/directory to be archived>This creates a gzip-compressed archive.
-
To create a bzip2 compressed archive, use option
j:$ tar cvjf <tarball name> <file/directory to be archived> -
To add a file or directory to an existing archive, use the following command:
$ tar rvf <tarball name> <file/directory to be added>You cannot add a file or directory to a compressed archive.
How to list an archive
You can use the following command to view the tar content before extraction:
$ tar tvf <tarball>
For a compressed archive, you can use the options j or z, depending on the type of compression.
How to extract a single file
To extract a single file from the archive, you can specify the name of the file at the end of the extract command:
tar xvf <tarball> <path to file>
If we specify a directory instead of a file, the directory will be extracted from the path.
We can also specify multiple files or directories for extraction.
Wildcards can also be used to extract files that match a specific pattern.
Free Resources
- undefined by undefined