18 examples for tar

{{ score }}
  # Create a tar archive
tar -cf archive.tar file1 file2 ... fileN

# Create a tar gzipp'd archive
tar -zcf archive.tar.gz file1 file2 ... fileN

# Create multi-part tar archives from a directory
tar cf - /path/to/directory|split -bM - archive.tar

# Extract all files from a tar archive
tar -xf archive.tar

# Extract all files from a tar gzipped archive
tar -zxf archive.tar.gz

# Extract one file from a tar archive
tar -xf archive.tar the_one_file

# Lists all files in a tar archive
tar -tf archive.tar
        
{{ score }}
  # Unzip to target directory
tar -xvf file.zip -C target_directory_path
        
{{ score }}
  # Create a tar file:
tar cf archive.tar file1 [...]

# Create a compressed tar file:
tar cjf archive.tar.bz2 file1 [...]

# Create a older compressed tar file:
tar czf archive.tar.gz file [...]

# Extract a .tar, .tar.gz, .tgz, .tar.bz, or .tbz2 file:
tar xf archive.tbz2

# list the files inside the archive:
tar tf archive.tar
        
{{ score }}
  # package up a folder and ignore a subfolder:
tar --exclude="project/.git" -czvf ~/Downloads/project.tgz project/
        
{{ score }}
  # List contents of a tar.gz file
tar -tvf filename.tar.gz
        
{{ score }}
  # exclude a file/directory from your tar archive
tar cvf archive.tar --exclude=.svn *
        
{{ score }}
  # Extract all files from tar gzipped archive verbosely
tar xzvf archive.tar.gz

# Create a tar gzipp'd archive verbosely
tar czvf archive.tar.gz /path/to/directory fileN
        
{{ score }}
  # extract a tarball
bro -xjf package.tar.bz2
        
{{ score }}
  # Create tar.bz2 archive
tar -c file(s) | bzip2 > yourfilename.tar.bz2

# Extract all files from a tar.bz2 archive
tar jvxf yourcompressfile.tar.bz2 (only in modern tar versions)
        
{{ score }}
  # list files inside tar archive
tar tf archive.tar

# append txt file to end of archive
tar rf archive.tar file.txt
        
{{ score }}
  # List contents of a tar.bz2 file
tar -tvf filename.tar.bz2
        
{{ score }}
  # compress to bz2 archive with highest (-9) or lowest (-1) possible
# compression, whereas the lower method is faster than the higher.
GZIP=-9 tar cjf archive.tar.bz2 file*
        
{{ score }}
  # dtrx
dtrx -l archivo.zip
        
{{ score }}
  # unpacking stuff with tar is obnoxious
# heres a useful shell script for unpacking with tar
# throw it in your .bashrc as a function or whatever.
if [ -f "$1" ] ; then
	case "$1" in
		*.tar.bz2)   tar xvjf "$1"    ;;
		*.tar.gz)    tar xvzf "$1"    ;;
		*.tar)       tar xvf "$1"     ;;
		*.tbz2)      tar xvjf "$1"    ;;
		*.tgz)       tar xvzf "$1"    ;;
		*.tar.xz)    tar xJf "$1"     ;;
		*) echo "don't know how to extract "$1"..." ;;
	esac
else
	echo ""$1" is not a valid file!"
fi
        
{{ score }}
  # add (txt-)file to an existing archive
tar -A archive.tar file.txt
        
{{ score }}
  # compress to bz2 archive with highest (-9) or lowest (-1) possible
# compression, whereas the lower method is faster than the higher.
GZIP=-9 tar cjz archive.tar.gz file*
        
{{ score }}
  # copy directory
tar -c source_dir | tar -xC destination_dir
        
{{ score }}
  # unpacking stuff with tar is obnoxious
# check out unp (unpack (almost) everything)
brew install unp
apt-get install unp