How to use TAR command in Ubuntu and Centos?
Command to archive files in Linux
What is Archive?
Archive files are used to collect multiple data files together into a single file for easier portability and storage, or simply to compress files to use less storage space.
There are 2 commands to archive files in Linux
- ZIP
- TAR
how to create a ZIP file
chirag@chirag-MacBookAir:~$ zip -r filename.zip dir1 chirag@chirag-MacBookAir:~$ zip -r filename.zip file1 file2 file3
How to extract the ZIP file
chirag@chirag-MacBookAir:~$ unzip filename.zip
How to create a ZIP file while excluding a particular file.
chirag@chirag-MacBookAir:~$ zip filename.zip -x "exclude file name"
How to extract zip file while excluding particular files.
chirag@chirag-MacBookAir:~$ unzip filename.zip -x "exclude filename" chirag@chirag-MacBookAir:~$ zip -r zipped.zip directory -x "*.svn*" chirag@chirag-MacBookAir:~$ unzip -l chirag.zip -x "exclude filename"
Tar Commands for Archive
How to extract tar file chirag@chirag-MacBookAir:~$ tar -ztvf config.tar.gz chirag@chirag-MacBookAir:~$ tar -zxvf config.tar.gz etc/default/sysstat chirag@chirag-MacBookAir:~$ tar -xvf {tarball.tar} {path/to/file}
Example – tar -xvf tarfile.tar /home/viking
How to Extract Single file from tar file
chirag@chirag-MacBookAir:~$ tar --extract --file={tarball.tar} {file}
Or
chirag@chirag-MacBookAir:~$ tar --extract --file={tarball.tar} {file}
Or
chirag@chirag-MacBookAir:~$ tar --extract --file=cbz.tar css
Important Links :-
Know more About TAR and ZIP format