Linux archives

From Ever changing code
Revision as of 14:33, 14 September 2016 by Pio2pio (talk | contribs) (→‎Zip)
Jump to navigation Jump to search

TAR, GZ, BZIP

Working with archives in linux where tar = tape archive and the most common used options are:

c - create a new tar file
x - extract file
t - list the contents of an archive
z - compress use gzip compress, extention .tar.gz
j - compress use bzip2 compress, extention .tar.bz2
v - verbose displays files to compress or uncompress
f - file specify the new archive name or an archive to extract from

Compress

Create compress .tar.gz archive

tar -czvf new_tarname.tar.gz /directory/to/be/compressed/
tar -czvf only_conf_backup.tar.gz /path/to/*.confra

Extract

tar -xzvf archive.tar.gz

A single file from compressed .tar.gz

tar -xzvf archive.tar.gz myscript.txt

A single directory (here conf directory) from compressed .tar.gz

tar -xzvf archive.tar.gz conf

Preview files inside archive

tar -tzvf {.tar.gz}
tar -tjvf {.tbz2}

Zip

Install zip and unzip then use interactive method:

Extract using default options, retaining directory structure
unzip file.zip
Compress file or directory
zip name.zip directory/*
zip name.zip file1 file2 file3