Linux tar Command and How To Tar A Directory – POFTUT


Generally used to make multiple files and directories one file. We will tar a directory

$ tar cvf dymerge.tar dymerge 
dymerge/ 
dymerge/txt/ 
dymerge/txt/archive_formats.txt 
dymerge/txt/logo.txt
  • for compress but actually it is not compressed
  • for verbosity to see what happens
  • for archive file name
  • dymerge.tar is new tar file name
  • dymerge is the source directory name

Compress While Archiving

We can compress archived with with parameter. is used to gzip format

$ tar cvfz dymerge.tar.gz dymerge
  • is for gzip compression other options are default for our usage

To compress with bzip2 parameter should be provided.

List Files in Tar Archive

We can list files without opening the tar. parameter is used to list. But if the archive is gzip we should provide too. As we see tar.gz is extension for tarred and gzipped files.

$ tar tvfz dymerge.tar.gz
  • list files
  • archive is gzip format
List Files in Tar Archive
List Files in Tar Archive

If the archive is bzip2 we can use following command

$ tar tvfj dymerge.tar.gz

Extract Single File From Archive

With tar a single file can be extracted from archive. is the parameter to be used for this operation

$ tar xvfz  dymerge.tar.gz dymerge/surnames.txt 
dymerge/surnames.txt
  • dymerge.tar.gz is our archive that contains our single file
  • dymerge/surnames.txt is the file we want to extract

Extract Multiple Files From Archive with tar

We can extract multiple files with tar. We need too provide –wildcards parameter and related files for this. Here is used for globing

$ tar xvfz  dymerge.tar.gz --wildcards *.txt  
dymerge/txt/archive_formats.txt 
dymerge/txt/logo.txt 
dymerge/surnames.txt 
dymerge/vbscan/reports/forum.doom9.org/forum.doom9.org_report_2016-10-16_at_4.56.1.txt 
dymerge/vbscan/reports/hello.txt 
dymerge/vbscan/love.txt 
dymerge/vbscan/exploit/vbscandb.txt 
dymerge/dymerged.txt 
dymerge/names.txt
  • –wildcards is the parameter
  • *.txt is the file names we want to exract

Untar Command

We can create some alias to create new untar command like below.

$ export alias untar="tar dvf $1"
Untar Command
Untar Command

Adding File into Archive

After creating an archive we may need to update or add new files and folders to the existing archive. We can use r option to add new file or folder by specifying file and folder names at the end of the command like below. In this example we will add file named test.txtinto the existing archive named dymerge.tar.gz

$ tar rvfz  dymerge.tar.gz test.txt
  • We append test.txt file with option
  • We can add directories too

Estimate Archive Size

Before archiving a directory with tar command we can learn the size of the archive with the help of wc command. We will tar the directory in to the starndard output which will be redirected to the wc command. wc command will count the bytes and provide estimated size of the given archived file.

$ tar -cf - dymerge | wc -c 
573440

 

Linux tar Command and How To Tar A Directory Infografic

Linux tar Command and How To Tar A Directory Infografic


Không có nhận xét nào:

Is it okay to use both fetchpriority="high" and loading="eager" in img tag?

 https://stackoverflow.com/questions/77744344/is-it-okay-to-use-both-fetchpriority-high-and-loading-eager-in-img-tag Yes Fetchpriority and l...