tar

>Usage

tar is a command-line tool used to create, maintain, and extract file archives. It combines multiple files into a single archive file, often for easier storage or transfer. It can also compress the archive to save space.

>Synopsis

tar [option] archive-file file

>Options

-f

file: This option allows to specify the name of the new archive, when we manipulate an archive we always need to specify the name

-c

create: This option is used to create a new archive. When we use -c we combine the specified files or directories into an archive

Example 1:

Dots

-zsh

tar -cf archive.tar file1.txt file2.txt


we create a new archive named archive.tar containing the files file1.txt and file2.txt

-x

extract: used to extract files and directories from a specified archive. Note that we have to use the option -f to specify the name of the archive.

Example 2:

Dots

-zsh

tar -xf archive.tar


we are extracting the content of archive.tar.

-v

verbose: With this option tar will display detailed output of the files as they are being added to (when creating) or extracted from (when extracting) the archive. This allows you to see each file being processed in real-time.

Example 3:

Dots

-zsh

tar -cvf archive.tar file1.txt file2.txt


with the option -v the files are shown as they are added to archive.tar

-z

gzip compression: This option in the tar command is used to compress (or decompress) an archive using gzip (gunzip). This option allows tar to directly create or extract .tar.gz files

Example 4:

Dots

-zsh

tar -czf archive.tar.gz file1.txt


this command will create an archive archive.tar.gz containing the file file1.txt and compressing it using gzip

-t

list: this option allows you to view the contents of an archive without extracting the files, used to check what's inside an archive.

Example 5:

Dots

-zsh

tar -tf archive.tar


this command will list all the element in the archive archive.tar

-u

update: this option allows you to add new files (or directories) to an existing tar archive. The files are added only if they are newer than the versions already in the archive or if they didn't exist in the archive.

Example 6:

Dots

-zsh

tar -uf archive.tar file2.txt


this command will add file2.txt to the existing archive archive.tar

>Quiz

Progress: Question ? out of ?

Question Title

Page written by Oliviero Vescovo