Because of various reasons some of which hearken back to the era of tape drives, Unix uses a program named tar to archive data, which can then be compressed with a compression program like gzip, bzip2, 7zip, etc.
In order to "zip" a directory, the correct command would be
tar -zcvf archive.tar.gz directory/
This will tell tar to c (create) an archive from the files in directory (tar is recursive by default), compress it using the z (gzip) algorithm, store the output as a f (file) named archive.tar.gz, and v (verbosely) list all the files it adds to the archive.
To decompress and unpack the archive into the current directory you would use
----------------------------------
ARCHIVE FOLDER CONTENTS & CREATE NEW BACKUP FILE:
----------------------------------
atoorpu@linux01:[~] $ tar -zcvf Output_File.tar.gz SourceFile
ziptest/
ziptest/readme1.txt
--->>> Output_File.tar.gz >>> output file
--->>> SourceFile >>> source directory
atoorpu@linux01:[~] $ ls
oswbb733.tar patches readme.txt sys_checker.sh ziptest.tar.gz
p19543113_851499_Linux-x86-64.zip pitt_4_21_2014.dmp.gz scripts ziptest1
LIST CONTENTS OF TAR FILE:
atoorpu@linux01:[~] $ tar -ztvf ziptest.tar.gz
drwxrwxr-x atoorpu/atoorpu 0 2015-08-27 14:16:41 ziptest/
-r--r--r-- atoorpu/atoorpu 50 2015-08-27 14:14:20 ziptest/readme1.txt
----------------------------------
EXTRACT/UNTAR THE FILE USE :
----------------------------------
To extract one or more members from an archive, enter:
$ tar -zxvf {file.tar.gz}
If your tarball name is backup.tar.gz, enter the following at a shell prompt to extract files:
$ tar -zxvf backup.tar.gz
To extract resume.doc file from backup.tar.gz tarball, enter:
$ tar -zxvf backup.tar.gz resume.doc
Thursday, November 5, 2015
Backup unix files and folders using tar - compress and backup files
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment