Compress Files in Linux Using tar



The tar command on Linux is often used to create .tgz archive files. It can create a .tar archive and then compress it with gzip or bzip2 compression in a single command

tar Command Options: 
  • c  -  Createa  archive file
  • x  -  Extract archive file 
  • t  -  Display the table of content(list) 
  • v  -  Verbose 
  • z  -  Use compression (gzip) 
  • j  -  Use comprassion (bzip2) 
  • f  -  Use this file 
  • C  -  Specified direcotry for extraction 
  • r  -  Append file to existing archive file
1.  .tar Archive:
tar cf new.tar new

Create a tar archive

tar tf new.tar

List the content of tar file

rm -rf new (remove new dir)
tar xvf new.tar

Extract tar archive in current directory 

tar xvf new.tar -C /root/newfolder

Extract tar archive in a specified directory 

tar xvf new.tar new/file.txt

Extract single file from .tar archive
tar xvf new.tar “new/file.txt” “new/shell.php”

Extract multiple file from .tar archive

tar xvf new.tar --wildcards *.txt

Extract type of files from .tar archive using wildcards

tar rvf new.tar new_file.txt

Append file to existing tar archive 

2.  .tgz (.tar.gz) Archive
tar zcf new.tgz new

Creat a tgz archive

tar tf new.tgz

Display content of tgz archive

tar xvf new.tgz

Extract tgz archive in current directory 
tar xvf new.tgz  -C /root/extract

Extract tgz archive in specified directory

tar xvf new.tgz new/file.txt

Extract single file from .tgz archive

tar xvf new.tbz “new/file” “new/shell.php”

Extract multiple file from .tgz archive

tar xvf new.tgz --wildcards *.txt

Extract type of files from .tgz archive using wildcards 
3.  .tbz (.tar.bz2) Archive
tar cjf new.tbz new

Creat a .tbz archive

tar tf new.tbz

Display content of .tbz archive

tar xvf new.tbz

Extract .tgz archive

tar xvf new.tbz -C /root/extract/

Extract .tbz archive to specified directory

tar xvf new.tbz new/file.txt

Extract single file from .tbz archive

tar xvf new.tbz “new/file.txt” “new/shell.php”

Extract multiple file from .tbz archive

tar xvf new.tbz --wildcards *.txt

Extract type of files from .tbz archive using wildcards
Compress Files in Linux Using tar Compress Files in Linux Using tar Reviewed by vijay pratap singh on March 30, 2017 Rating: 5

No comments:

Powered by Blogger.