Difference between revisions of "Linux command: tar"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) m (Protected "Linux command: tar" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))) |
Rafahsolis (talk | contribs) m (→With password) Tag: visualeditor |
||
| (9 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | ==Compression== | |
| − | + | ||
| − | + | ===.tar.gz=== | |
| + | <syntaxhighlight lang="bash"> | ||
tar -zcvf /var/my-backup.tar.gz /home/rafa/ | tar -zcvf /var/my-backup.tar.gz /home/rafa/ | ||
| + | </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 | ||
| + | </syntaxhighlight> | ||
| − | + | ===Extract .tar.gz=== | |
| + | <syntaxhighlight lang="bash"> | ||
tar -zxvf archive.tar.gz | tar -zxvf archive.tar.gz | ||
| + | </syntaxhighlight> | ||
| − | + | ====With password==== | |
| + | <syntaxhighlight lang="bash"> | ||
| + | openssl enc -d -aes256 -pbkdf2 -in secured.tar.gz | tar xz -C target_dir | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===Extract .txz=== | ||
| + | <syntaxhighlight lang="bash"> | ||
tar Jxvf file.txz | tar Jxvf file.txz | ||
| − | </nowiki> | + | </syntaxhighlight> |
| + | |||
| + | ===Extract .tar.xz=== | ||
| + | <syntaxhighlight lang="bash"> | ||
| + | tar -xvf file.tar.xz | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===Extract .tar.bz2=== | ||
| + | <syntaxhighlight lang="bash"> | ||
| + | tar -jtvf file.tar.bz2 | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===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