Difference between revisions of "Linux command: tar"

From RHS Wiki
Jump to navigation Jump to search
Tag: visualeditor
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
<nowiki>
+
==Compression==
#compress .tar.gz
+
 
 +
===.tar.gz===
 +
<syntaxhighlight lang="bash">
 
tar -zcvf /var/my-backup.tar.gz /home/rafa/
 
tar -zcvf /var/my-backup.tar.gz /home/rafa/
#view file contents  
+
</syntaxhighlight>
 +
 
 +
===.tar.gz split with max size===
 +
<syntaxhighlight lang="bash">
 +
tar cvzf - dir/ | split --bytes=200MB - sda1.backup.tar.gz.
 +
tar cvzf - dir/ | split -b 200m - sda1.backup.tar.gz.
 +
tar cvzf - /Applications/Install\ macOS\ Sierra.app/ | split -b 4294967295 - /Volumes/UNTITLED/install_macos_sierra.tgz.
 +
</syntaxhighlight>
 +
 
 +
===.tar.gz exclude files===
 +
<syntaxhighlight lang="bash">
 +
tar --exclude='./folder' --exclude='./upload/folder2' -zcvf /backup/filename.tgz .
 +
tar --exclude='./backup' -zcvf - . | split --bytes=1024MB - backup/content.sdf.backup.tar.gz.
 +
</syntaxhighlight>
 +
 
 +
===With password===
 +
<syntaxhighlight lang="bash">
 +
tar -czf - * | openssl enc -e -aes256 -pbkdf2 -out secured.tar.gz
 +
</syntaxhighlight>
 +
 
 +
==Extraction==
 +
 
 +
===View .tar.gz contents===
 +
<syntaxhighlight lang="bash">
 
tar -ztvf file.tar.gz
 
tar -ztvf file.tar.gz
 +
</syntaxhighlight>
  
 +
===Extract .tar.gz===
 +
<syntaxhighlight lang="bash">
 +
tar -zxvf archive.tar.gz
 +
</syntaxhighlight>
  
#uncompress .tar.gz
+
====With password====
tar -zxvf archive.tar.gz
+
<syntaxhighlight lang="bash">
 +
openssl enc -d -aes256 -pbkdf2 -in secured.tar.gz | tar xz -C target_dir
 +
</syntaxhighlight>
  
#uncompress .txz
+
===Extract .txz===
 +
<syntaxhighlight lang="bash">
 
tar Jxvf file.txz
 
tar Jxvf file.txz
 +
</syntaxhighlight>
  
# uncompress .tar.xz
+
===Extract .tar.xz===
 +
<syntaxhighlight lang="bash">
 
tar -xvf file.tar.xz
 
tar -xvf file.tar.xz
 +
</syntaxhighlight>
  
# view tar.bz2 contents
+
===Extract .tar.bz2===
 +
<syntaxhighlight lang="bash">
 
tar -jtvf file.tar.bz2
 
tar -jtvf file.tar.bz2
</nowiki>
+
</syntaxhighlight>
Note: .gz files are decompressed with <nowiki>gunzip file.gz</nowiki>
+
 
 +
===Extract all files in subdirectories===
 +
<syntaxhighlight lang="bash">
 +
DEST=<Destination Folder>
 +
SRC=<Src Folder>
 +
find $SRC -name "*.tar.gz" -or -name "*.tgz" -exec tar xzvvf -C $DEST {} \;
 +
</syntaxhighlight>Note: .gz files are decompressed with <nowiki>gunzip file.gz</nowiki>

Latest revision as of 07:57, 26 April 2019

Compression

.tar.gz

tar -zcvf /var/my-backup.tar.gz /home/rafa/

.tar.gz split with max size

tar cvzf - dir/ | split --bytes=200MB - sda1.backup.tar.gz.
tar cvzf - dir/ | split -b 200m - sda1.backup.tar.gz.
tar cvzf - /Applications/Install\ macOS\ Sierra.app/ | split -b 4294967295 - /Volumes/UNTITLED/install_macos_sierra.tgz.

.tar.gz exclude files

tar --exclude='./folder' --exclude='./upload/folder2' -zcvf /backup/filename.tgz .
tar --exclude='./backup' -zcvf - . | split --bytes=1024MB - backup/content.sdf.backup.tar.gz.

With password

tar -czf - * | openssl enc -e -aes256 -pbkdf2 -out secured.tar.gz

Extraction

View .tar.gz contents

tar -ztvf file.tar.gz

Extract .tar.gz

tar -zxvf archive.tar.gz

With password

openssl enc -d -aes256 -pbkdf2 -in secured.tar.gz | tar xz -C target_dir

Extract .txz

tar Jxvf file.txz

Extract .tar.xz

tar -xvf file.tar.xz

Extract .tar.bz2

tar -jtvf file.tar.bz2

Extract all files in subdirectories

DEST=<Destination Folder>
SRC=<Src Folder>
find $SRC -name "*.tar.gz" -or -name "*.tgz" -exec tar xzvvf -C $DEST {} \;

Note: .gz files are decompressed with gunzip file.gz