Linux UNIX

tar – Archiving

“In computing, tar (derived from tape archive) is both a file format (in the form of a type of archive bitstream) and the name of a program used to handle such files.”

$ tar [options]f archive-name.tar.gz /directory-to-archive-or-file-name

Key tar Options

c = create
x = extract
t = test (list)
v = verbose
f = file name
z = gzip
j = bzip2

gzip a directory.

$ tar cvzf filename.tar.gz /directory/path

bzip2 a directory.

$ tar cvjf filename.tar.bz2 /directory/path

gzip all mp3 and m4a files within the current directory.

$ tar cvzf filename.tar.gz *.mp3 *.m4a

To combine multiple files and/or directories into a single file, use the following command.

$ tar cvf filename.tar.gz file1 file2

Read/verify contents.

$ tar -tzf filename.tar.gz

Extract a file in current dirextory.

$ tar xvf filename.tar.gz

If you want to extract a file into specfied directory, cd into that directory and run the extract command from there or…

$ tar xvf filename.tar.gz -C /directory/path

By Tommy Elmesewdy

DevOps Engineer