Difference between revisions of "Linux archives"

From Ever changing code
Jump to navigation Jump to search
Line 29: Line 29:
  unzip file.zip
  unzip file.zip
;Compress file or directory
;Compress file or directory
  zip name.zip directory/
  zip name.zip directory/*
  zip name.zip file1 file2 file3
  zip name.zip file1 file2 file3


[[Category:linux]]
[[Category:linux]]

Revision as of 14:33, 14 September 2016

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