Summer training at Goeduhub Technologies-Jaipur

Online Instructor-Led Live Training Courses/Workshops details || Claim for online workshop's certificate

0 like 0 dislike
12 views
in Tutorial & Interview questions by Goeduhub's Expert (7.3k points)

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.3k points)
 
Best answer

Common Options -

-c --create Create a new archive.

-x --extract Extract files from an archive.

-t --list List the contents of an archive.

-f --file=ARCHIVE Use archive file or dir ARCHIVE.

-v --verbose Verbosely list files processed.

Compression Options -

-a --auto-compress Use archive suffix to determine the compression program.

-j --bzip2 Filter the archive through bzip2.

-J --xz --lzma Filter the archive through xz.

-z --gzip Filter the archive through gzip.

Compress a folder

This creates a simple archive of a folder :
tar -cf ./my-archive.tar ./my-folder/
Verbose output shows which files and directories are added to the archive, use the -v option:
tar -cvf ./my-archive.tar ./my-folder/
For archiving a folder compressed 'gzip', you have to use the -z option :
tar -czf ./my-archive.tar.gz ./my-folder/
You can instead compress the archive with 'bzip2', by using the -j option:
tar -cjf ./my-archive.tar.bz2 ./my-folder/
Or compress with 'xz', by using the -J option:
tar -cJf ./my-archive.tar.xz ./my-folder/

Extract a folder from an archive 

There is an example for extract a folder from an archive in the current location :
tar -xf archive-name.tar
If you want to extract a folder from an archive to a specfic destination :
tar -xf archive-name.tar -C ./directory/destination

List contents of an archive 

List the contents of an archive file without extracting it:
tar -tf archive.tar.gz
Folder-In-Archive/
Folder-In-Archive/file1
Folder-In-Archive/Another-Folder/
Folder-In-Archive/Another-Folder/file2

List archive content 

There is an example of listing content :
tar -tvf archive.tar
The option -t is used for the listing. For listing the content of a tar.gz archive, you have to use the -z option anymore :
tar -tzvf archive.tar.gz

Compress and exclude one or multiple folder 

If you want to extract a folder, but you want to exclude one or several folders during the extraction, you can use the
--exclude option.
tar -cf archive.tar ./my-folder/ --exclude="my-folder/sub1" --exclude="my-folder/sub3"
With this folder tree :
my-folder/
   sub1/
   sub2/
   sub3/
The result will be :
./archive.tar
   my-folder/
     sub2/

Strip leading components 

To strip any number of leading components, use the --strip-components option:
--strip-components=NUMBER
strip NUMBER leading components from file names on extraction
For example to strip the leading folder, use:
tar -xf --strip-components=1 archive-name.tar

 

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Nov 2, 2019 in Tutorial & Interview questions by Goeduhub Goeduhub's Expert (7.3k points)
0 like 0 dislike
1 answer
asked Nov 2, 2019 in Tutorial & Interview questions by Goeduhub Goeduhub's Expert (7.3k points)
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Nov 2, 2019 in Tutorial & Interview questions by Goeduhub Goeduhub's Expert (7.3k points)
0 like 0 dislike
1 answer
asked Nov 1, 2019 in Tutorial & Interview questions by Goeduhub Goeduhub's Expert (7.3k points)
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
 Know About Popular Colleges/Universities  List of IITsList of NITs | RTU-Kota | BTU-Bikaner | Manipal University-Jaipur | JECRC University | Amity University Jaipur | BIT Mesra-Jaipur | MODY UNIVERSITY | LNMIIT-Jaipur | JK Lakshmipat | Banasthali Vidyapith | POORNIMA University
 Exams:   List of Exams After Graduation | List of Engineering Entrance Examinations (UG/PG) | JEE Main | JEE Advanced | GATE | IES | ISROList of PSUs
Placements:  List of companies | Logical Reasoning Questions | Quantitative Aptitude Questions | General English Questions | Technical-MCQ and Interview Questions
 Download Previous Year Papers For:  GATE | IES | RAJASTHAN TECHNICAL UNIVERSITY (RTU-Kota)RPSC Technical Exams | ISRO
 Online Free Training:  Artificial Intelligence(AI) & Machine Learning(ML)Python Programming | Internet of Things-IoT | OpenCV (Open Source Computer Vision Library) | LINUX | Big Data : Hadoop | 
 Goeduhub
About Us | Contact Us   Social::   |  | 
...