Tar: Difference between revisions

From Psygen Wiki
Jump to navigation Jump to search
(Created page with "creates an archive (Commonly called a tarball. 'tar' is short for '<b>t</b>ape <b>ar</b>chive') == Flags == '''-z''' use gzip to compress/read the resulting tarball...")
 
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
creates an archive (Commonly called a tarball. 'tar' is short for '<b>t</b>ape <b>ar</b>chive')
Creates an archive (Commonly called a tarball. 'tar' is short for '<b>t</b>ape <b>ar</b>chive')
 
== Usage ==
 
Command -Flags  tar_ball_name  stuff_to_zip
 


== Flags ==
== Flags ==
    '''-z''' use gzip to compress/read the resulting tarball
 
   
'''-z''' use gzip to compress/read the resulting tarball
    '''-j''' use bzip2 to compress/read the tarball
 
   
'''-j''' use bzip2 to compress/read the tarball
    '''-c''' create a new archive.
 
   
'''-c''' create a new archive.
    '''-v''' verbose. tar will list all the files it's adding to the archive.
 
   
'''-v''' verbose. tar will list all the files it's adding to the archive.
    '''-f''' the result should be saved into a file (as opposed to being stored on a tape)
 
   
'''-f''' the result should be saved into a file (as opposed to being stored on a tape)
    '''-t''' list the contents of an archive
 
   
'''-t''' list the contents of an archive
 
'''-x''' extract files from an archive
 
'''-r''' add files to an existing archive (doesn't work on compressed archives)
 
== Examples: ==
== Examples: ==
   
 
Create a new archive:
'''Create a new archive:'''
   
 
<code>tar -zcvf mytar.tar.gz *</code>
<code>tar -czvf mytar.tgz *</code> - creates a tarball named “mytar.tar.gz”, and archives all files in the current directory into it.
   
 
creates a tarball named “mytar.tar.gz”, and archives all files in the current directory into it.
 
   
'''Extract from an archive to the current directory:'''
    Extract from an archive:
 
   
<code>tar -xzvf mytar.tgz </code>  - Extracts all files in the tarball into the current directory
    tar -zxvf mytar.tar.gz
 
   
You can specify a file name at the end to extract just that file:
        Extracts all files in the tarball into the current directory.
 
       
<code>tar -xzvf mytar.tgz folder/file.php</code>
    List the contents of a tarball:
 
   
 
        tar -ztvf mytar.tar.gz
'''Extract from an archive to the specified directory:'''
 
<code>tar -xzvf mytar.tgz -C /path/to/directory</code> - - Extracts all files in the tarball into the specified directory (You can specify a file name at the end to extract just that file.)
 
 
'''List the contents of a tarball:'''
 
<code>tar -tzvf mytar.tgz</code>


== References ==
== References ==

Latest revision as of 01:27, 31 August 2023

Creates an archive (Commonly called a tarball. 'tar' is short for 'tape archive')

Usage

Command -Flags tar_ball_name stuff_to_zip


Flags

-z use gzip to compress/read the resulting tarball

-j use bzip2 to compress/read the tarball

-c create a new archive.

-v verbose. tar will list all the files it's adding to the archive.

-f the result should be saved into a file (as opposed to being stored on a tape)

-t list the contents of an archive

-x extract files from an archive

-r add files to an existing archive (doesn't work on compressed archives)

Examples:

Create a new archive:

tar -czvf mytar.tgz * - creates a tarball named “mytar.tar.gz”, and archives all files in the current directory into it.


Extract from an archive to the current directory:

tar -xzvf mytar.tgz - Extracts all files in the tarball into the current directory

You can specify a file name at the end to extract just that file:

tar -xzvf mytar.tgz folder/file.php


Extract from an archive to the specified directory:

tar -xzvf mytar.tgz -C /path/to/directory - - Extracts all files in the tarball into the specified directory (You can specify a file name at the end to extract just that file.)


List the contents of a tarball:

tar -tzvf mytar.tgz

References

  1. tar man page
  2. Ultimate Tar Command Tutorial