TAR and ZIP command in Linux

TAR and ZIP command in Linux - www.techiev.com Tar-Tape archive: Tar usage and options:   c - create an archive file  ...

TAR and ZIP command in linux -www.techiev.com
TAR and ZIP command in Linux - www.techiev.com

Tar-Tape archive:
Tar usage and options:

  c - create an archive file

  x - extract an archive file

v - show the progress of the archive file

f  - filename of archive file

t  - viewing the content of the file

j  - filter archive through bzip2(bz2)

  z -  filter archive through gzip(gz)

r -  append or update files or directories to an existing archive file


1. To Create tar Archive File:
     Cmd: tar -cvf testing.tar /root/testing
Where
Testing.tar is the archive file now we are created
/root/testing is the saving location of this file as.tar
TAR and ZIP command in linux -www.techiev.com

2. To Create tar.gz & tar.tgz Archive Files;
Cmd: tar cvzf testing.tar.gz  /root/testing (or) tar cvzf testing.tgz /root/testing
Where Z is archived through gzipTAR and ZIP command in linux -www.techiev.comTAR and ZIP command in linux -www.techiev.com

3. To Create tar.bz2 Archive File:
It will compress and create archive files less than the size of gzip. It takes more time to compress (zip). It takes less time to decompress compared to gzip(unzip).
To create a highly compressed tar file we use the option j.

CMD: tar cvfj testing.tar.bz2 /root/testing
(or)
tar cvfj testing.tar.tbz /root/testing
(or)
tar cvfj testing.tar.tb2 /root/testing                                                       TAR and ZIP command in linux -www.techiev.com          
4.To Untar tar Archive File:
If you want to untar in a different directory then use option as -C (specified directory).


5. To Uncompress tar.gz, Archive File:
        Cmd: untar for current directory untar to other directories
tar -xvf testing.tar.gz tar -xvf testing.tar.gz -C /root/me/

6. To Uncompress tar.bz2 Archive File
Cmd: tar -xvf testing.tar.bz2

7. To List Content of .tar, .tar.bz2, .tar.gz Archive File
Cmd:  tar -tvf testing.tar
tar -tvf testing.tar.g
tar -tvf testing.tar.bz2
8. To Untar Single file
tar File -->  tar-xvf testing.tar jing-trang-20091111-14.el7.src.rpm
gzip (or) .gz file --> tar -zxvf testing.tar jing-trang-20091111-14.el7.src.rpm
(or)
tar --extract --file=testing.tar jing-trang-20091111-14.el7.src.rpm
tar.bz2 File -->  tar -jxvf testing.tar jing-trang-20091111-14.el7.src.rpm
(or)
tar --extract --file=testing.tar jing-trang-20091111-14.el7.src.rpm

9. To Untar Multiple files from tar, tar.gz, and tar.bz2 File
Cmd: tar -xvf testing.tar “FILE1” “FILE2”
tar -zxvf testing.tar “FILE1” “FILE2”
tar -jxvf testing.tar “FILE1” “FILE2”
10. To Extract Group of Files using Wildcard :


11. To Add Files or Directories to tar Archive File
To add files or directories to the existing tar archive file we use option r (append).
Cmd: tar -rvf testing.tar loss.txt

12. To Add Files or Directories to tar.gz and tar.bz2 files
In the .gzip file and bz2 files, I cant add the directories and files if tried it shows an error
Cmd:
13. To Verify tar Archive File
To verify any tar or compressed archived file we use the option W (verify).
You cannot do verification on a compressed ( *.tar.gz, *.tar.bz2 ) archive file).
Cmd:  tar tvfW testing.tar
14. Check the size of the tar, tar.gz and tar.bz2 Archive File
 For tar →>>  tar -czf - testing.tar | wc -c
 For .gzip →>> tar -czf - testing.gz | wc -c
 For .bz2 →>> tar -czf - testing.bz2 | wc -c

ZIP:
“.zip” file extension for zip files, which is used to compress the files larger into the smaller size in Linux, UNIX windows environment.
It is used to compress or zip any files, folders (or) directories.
          Transfer the large files from one place to another using zip to convert the files and folders and transfer from one place to another.

1. To zip the particular folder:
Syntax: zip -r  name.zip  folder name Where -r recursive  name.zip-->  what is the name we are going to give to the zip file 
Ex: Michel..zip, my.zip
folder name/--> folder we are going to zip.
Ex: zip -r Michel.zip Michel/ 
2. To Unzip the folder:
Unzip Michel.zip 
3. To Unzip the folder in another location Unzip Michel.zip -d /home/documents
where ---> /home/documents---> path for the directory 

Options:

 1. -d Option: It Removes the file from the zip archive.  After creating a zip file, you can remove a file from the archive using the -d option.
           Syntax:
  $zip –d filename.zip file.txt
     Command:
$zip –d myfile.zip hello7.c
2.  -u option: Add the new file inside the already created zip file.
Syntax:
$zip –u filename.zip file.txt
3. -m Option: it will delete the source folder or file after zipped
Syntax:
$zip –m filename.zip file.txt
It will zip the file inside the filename.zip but the original source file file.txt will delete automatically.
4. -r Option:  it will zip the files and folder recursively so it can be used to zip all files and folders present in the specified directory or folder.
Syntax:
$zip –r filename.zip directory_name
5. -x Option:  It is used to exclude the particular  files and folder while taking a zip
Syntax:
$zip –x filename.zip file_to_be_excluded

If I want to exclude the test_folder 

          Example:  $zip –r myfile.zip ./myfile -x '*test_folder*'

6, -v Option:  verbose mode or print the information. It applied to real operations, this option enables the display of a progress indicator during compression
Syntax:
$zip –v filename.zip filex.txt
Example:
$zip -v filex.zip *.c
Output :
                       adding: hello1.c (in=0) (out=0) (stored 0%)
                       adding: hello2.c (in=0) (out=0) (stored 0%)
                       adding: hello3.c (in=0) (out=0) (stored 0%)
                       adding: hello4.c (in=0) (out=0) (stored 0%)
                       total bytes=0, compressed=0 -> 0% savings

------------------------------------------------!!!Happy Learning!!!! -------------------------------------------------------

COMMENTS

Name

AWS,9,Devops,18,linux,10,
ltr
item
Techie View: TAR and ZIP command in Linux
TAR and ZIP command in Linux
https://1.bp.blogspot.com/-9T2lqhOe1O4/XaYQWCcZaPI/AAAAAAAAAAY/B198lv9HAnwerWhv7c_XDf3MWcpXN6QJQCLcBGAsYHQ/s400/tar%2Bzip.jpg
https://1.bp.blogspot.com/-9T2lqhOe1O4/XaYQWCcZaPI/AAAAAAAAAAY/B198lv9HAnwerWhv7c_XDf3MWcpXN6QJQCLcBGAsYHQ/s72-c/tar%2Bzip.jpg
Techie View
https://www.techiev.com/2019/10/tar-and-zip-command-in-linux-www.html
https://www.techiev.com/
https://www.techiev.com/
https://www.techiev.com/2019/10/tar-and-zip-command-in-linux-www.html
true
7013663511659419322
UTF-8
Loaded All Posts Not found any posts VIEW ALL View Full Article Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy