18 examples for tar
# 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
# 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
# package up a folder and ignore a subfolder: tar --exclude="project/.git" -czvf ~/Downloads/project.tgz project/
# 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
# 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)
# list files inside tar archive tar tf archive.tar # append txt file to end of archive tar rf archive.tar file.txt
# 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*
# 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
# 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*
# unpacking stuff with tar is obnoxious # check out unp (unpack (almost) everything) brew install unp apt-get install unp