How to use TAR command in Ubuntu and Centos?

roatate logs in centos 7

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

  1. ZIP
  2. TAR





how to create a ZIP file

[email protected]:~$ zip -r filename.zip dir1
[email protected]:~$ zip -r filename.zip file1 file2 file3

How to extract the ZIP file

[email protected]:~$ unzip filename.zip

How to create a ZIP file while excluding a particular file.

[email protected]:~$ zip filename.zip -x "exclude file name"

How to extract zip file while excluding particular files.

[email protected]:~$ unzip filename.zip -x "exclude filename"
[email protected]:~$ zip -r zipped.zip directory -x "*.svn*"
[email protected]:~$ unzip -l chirag.zip -x "exclude filename"

Tar Commands for Archive

How to extract tar file  
  [email protected]:~$  tar -ztvf config.tar.gz
[email protected]:~$  tar -zxvf config.tar.gz etc/default/sysstat
[email protected]:~$  tar -xvf {tarball.tar} {path/to/file}

Example – tar -xvf tarfile.tar /home/viking

How to Extract Single file from tar file

[email protected]:~$ tar --extract --file={tarball.tar} {file}




Or

[email protected]:~$ tar --extract --file={tarball.tar} {file}

Or

[email protected]:~$ tar --extract --file=cbz.tar css

Important Links :-

Know more About  TAR and ZIP format

techouse

I love helping beautiful people like you. I love hanging out with my dogs.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.