Tuesday 13 November 2012

Fast And Easy Tar Archive Tutorial For Linux Begineers





Before You Proceed Take A Sharp Look
Note: All Commands Must Be Performed In The Terminal.
Here # is Not a Command/string It's For Representing
That You Are In Terminal.

-f command for file name/location same as --file=
-c create a new archive same as --create
-v verbosely list files which are processed.
-z filter the archive through gzip
-j filter the archieve through bzip2 or bz2
-x command for extracting same as --extract
-t command for listing archieve same as --list
-r command for appending new files same as --append


filter the archive through bzip2
=====================================
1.Creating an uncompressed tar archive using option cvf
This is the basic command to create a tar archive.

--------------------------------------------------
# tar cvf archive_name.tar dirname/
--------------------------------------------------

2.Creating a tar gzipped archive using option cvzf
The above tar cvf option, does not provide any 
compression. To use a gzip compression on the tar 
archive, use the z option as shown below.

-------------------------------------------------------
# tar cvzf archive_name.tar.gz dirname/
-------------------------------------------------------

Note: .tgz is same as .tar.gz

3.Creating a .tar archieve using complex strings
-----------------------------------------------------------------------------------------
# tar --create --verbose --file=archieve_name.tar file1.png file2.py variousin1.txt
----------------------------------------------------------------------------------------

Here We Created A Tar Archieve of 3 file, you have to provide your full file name 
with extension followed by a single space.

4.Creating a .tar archieve using normal strings
-----------------------------------------------------------------------------------
# tar -c -v -f archieve_name.tar file1.png file2.py variousin1.txt
-----------------------------------------------------------------------------------

5.Creating a .tar archieve using simplest strings
---------------------------------------------------------------------------------
# tar -cvf archieve_name.tar file1.png file2.py variousin1.txt
---------------------------------------------------------------------------------

6. List all the files and folders(contents) of a tar archieve(complex) without extracting it.

---------------------------------------------------------------------------------
# tar --list --verbose --file=archieve_name.tar
---------------------------------------------------------------------------------

7. Add New Files in our tar archieve(complex) without extracting it.

---------------------------------------------------------------------------------
# tar --append --verbose --file=archieve_name.tar file4.png file5.txt
---------------------------------------------------------------------------------

8. Store all tar archieve outputs(dir properties) in a txt file.

---------------------------------------------------------------------------------
# tar --list --index-file=outputfile.txt --verbose --file=archieve_name.tar
---------------------------------------------------------------------------------

Note: The outputfile.txt must be in same dir(folder) where you have placed your tar file.

9. Delete a Single File or folder From a tar archieve.

---------------------------------------------------------------------------------
# tar --delete --verbose --file=archieve_name.tar file5.txt
---------------------------------------------------------------------------------

Note: The file5.txt is now deleted from archieve_name.tar ok...

10. extract archieve_name.tar contents to current working directory.

---------------------------------------------------------------------------------
# tar --extract --verbose --file=archieve_name.tar
---------------------------------------------------------------------------------

11. extract a single file or folder from archieve_name.tar to current working directory.

---------------------------------------------------------------------------------
# tar --extract --verbose --file=archieve_name.tar file4.png
---------------------------------------------------------------------------------

12. extract a single file or folder from archieve_name.tar to current working directory.

---------------------------------------------------------------------------------
# tar --extract --verbose --file=archieve_name.tar file4.png
---------------------------------------------------------------------------------

13. Add New Files in our tar archieve(complex) without extracting it.(overwritting)

---------------------------------------------------------------------------------
# tar --update --verbose --file=archieve_name.tar file4.png file5.txt
---------------------------------------------------------------------------------

Note: Your old Copy Of file5.txt will be replaced by this file5.txt(updated)

14.Creating a bzipped tar archive using option cvjf

---------------------------------------------------------------------------------
# tar cvfj archive_name.tar.bz2 file6.py file7.png
---------------------------------------------------------------------------------

gzip vs bzip2: bzip2 takes more time to compress and decompress than gzip. bzip2 
archival size is less than gzip. so if u worried about your hard drive contents
then compress them with .tar.bz2 archieve compression and see the magic, 
i(devender mahto)personally suggest you this method if you are willing to 
compress your world of plathora in a small tar archieve.

Note: .tbz and .tb2 is same as .tar.bz2

15.Extracting (untar) an archive using tar command(simple)

---------------------------------------------------------------------------------
# tar xvf archive_name.tar
---------------------------------------------------------------------------------

16.Extract a gzipped tar archive ( *.tar.gz ) using option xvzf

---------------------------------------------------------------------------------
# tar xvfz archive_name.tar.gz
---------------------------------------------------------------------------------

17. Extracting a bzipped tar archive ( *.tar.bz2 ) using option xvjf
---------------------------------------------------------------------------------
# tar xvfj archive_name.tar.bz2
---------------------------------------------------------------------------------

18. View the tar archive file content without extracting using option tvf(simple)
---------------------------------------------------------------------------------
# tar tvf archive_name.tar
---------------------------------------------------------------------------------

19. View the *.tar.gz file content without extracting using option tvzf(simple)
---------------------------------------------------------------------------------
# tar tvfz archive_name.tar.gz
---------------------------------------------------------------------------------

20. View the *.tar.bz2 file content without extracting using option tvjf

---------------------------------------------------------------------------------
# tar tvfj archive_name.tar.bz2
---------------------------------------------------------------------------------

21. To extract multiple directories from a tar archive, specify those individual 
directory names at the end of the tar xvf command as shown below.

---------------------------------------------------------------------------------
# tar xvf archive_name.tar /path/to/dir1/ /path/to/dir2/
---------------------------------------------------------------------------------

22. Extract group of files from tar, tar.gz, tar.bz2 archives using regular 
expressions.
In The Following Commands we want only mp3 file so we added .mp3 after the 
astrik(*)sign

---------------------------------------------------------------------------------
# tar xvf archive_name.tar --wildcards '*.mp3'
---------------------------------------------------------------------------------



0 comments:

Post a Comment