Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Bash

Tar ball tar.gz compress quick

#!/bin/bash
tar -cvzf $1.tar.gz $1
https://snipt.net/embed/55ef009ae34e3468eecef57053db1179/
https://snipt.net/raw/55ef009ae34e3468eecef57053db1179/
55ef009ae34e3468eecef57053db1179
bash
Bash
2
2016-12-02T07:25:34
True
False
False
/api/public/snipt/95069/
tar-ball-targz-compress-quick
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="ch">#!/bin/bash</span> </span><span id="L-2"><a name="L-2"></a>tar -cvzf <span class="nv">$1</span>.tar.gz <span class="nv">$1</span> </span></pre></div> </td></tr></table>
compress, gz, tar, zip

Bash

TAR command to preserve files' permissions

1
2
3
4
5
# Compression
tar -pcvzf ABC.tar.gz ABC

# Decompression
tar -pxvzf ABC.tar.gz
https://snipt.net/embed/4d97bbd42854bf8c9bcb8d0c3b31e472/
https://snipt.net/raw/4d97bbd42854bf8c9bcb8d0c3b31e472/
4d97bbd42854bf8c9bcb8d0c3b31e472
bash
Bash
5
2016-12-03T16:32:35
True
False
False
Oct 18, 2013 at 03:10 AM
/api/public/snipt/87757/
tar-command-to-preserve-files-permissions
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># Compression</span> </span><span id="L-2"><a name="L-2"></a>tar -pcvzf ABC.tar.gz ABC </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1"># Decompression</span> </span><span id="L-5"><a name="L-5"></a>tar -pxvzf ABC.tar.gz </span></pre></div> </td></tr></table>
bash, gz, permissions, tar

Bash

extract a specific file from a tar.gz

$ tar xfz abc.tar --wildcards --no-anchored 'redpics*'
https://snipt.net/embed/ab0da6899101a03376177ec62f65a74b/
https://snipt.net/raw/ab0da6899101a03376177ec62f65a74b/
ab0da6899101a03376177ec62f65a74b
bash
Bash
1
2016-12-03T23:54:16
True
False
False
Feb 23, 2013 at 07:10 PM
/api/public/snipt/53824/
extract-a-specific-file-from-a-targz
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>$ tar xfz abc.tar --wildcards --no-anchored <span class="s1">&#39;redpics*&#39;</span> </span></pre></div> </td></tr></table>
extract, find, gz, tar, zip

Bash

Remove all files previously extracted from a tar(.gz) file

tar -tf <file.tar.gz> | xargs rm -r
https://snipt.net/embed/5d8773e660327770fc89ea073fb2625e/
https://snipt.net/raw/5d8773e660327770fc89ea073fb2625e/
5d8773e660327770fc89ea073fb2625e
bash
Bash
1
2016-12-02T14:16:09
True
False
False
Oct 20, 2012 at 10:48 PM
/api/public/snipt/48845/
remove-all-files-previously-extracted-from-a-targz-file
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>tar -tf &lt;file.tar.gz&gt; <span class="p">|</span> xargs rm -r </span></pre></div> </td></tr></table>
bash, rm, shell, tar

Bash

Recursive tar folder

tar cvzf www.tar.gz --recursive /folder
https://snipt.net/embed/d0c6ea3f276a4ab28ca9b3d16c48b0a5/
https://snipt.net/raw/d0c6ea3f276a4ab28ca9b3d16c48b0a5/
d0c6ea3f276a4ab28ca9b3d16c48b0a5
bash
Bash
1
2016-12-03T15:58:46
True
False
True
Oct 01, 2012 at 11:09 AM
/api/public/snipt/47863/
recursive-tar-folder
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>tar cvzf www.tar.gz --recursive /folder </span></pre></div> </td></tr></table>
"recursive tar", tar

Bash

Compact tar.bz2 and on destination

1
2
3
#This is useful when you don't have much space on server, and need backup or copy
#So, you can backup direct to destination.
tar -cf - /home/dir_backup |bzip2 -9vv | ssh [email protected] "cat > /backups/dir_backup.tar.bz2"
https://snipt.net/embed/ff3556c4d1185c97e7eacbd696ca6a35/
https://snipt.net/raw/ff3556c4d1185c97e7eacbd696ca6a35/
ff3556c4d1185c97e7eacbd696ca6a35
bash
Bash
4
2016-12-02T14:15:38
True
False
False
Sep 29, 2012 at 03:39 PM
/api/public/snipt/47820/
compact-tarbz2-and-on-destination
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">#This is useful when you don&#39;t have much space on server, and need backup or copy</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">#So, you can backup direct to destination.</span> </span><span id="L-3"><a name="L-3"></a>tar -cf - /home/dir_backup <span class="p">|</span>bzip2 -9vv <span class="p">|</span> ssh [email protected] <span class="s2">&quot;cat &gt; /backups/dir_backup.tar.bz2&quot;</span> </span></pre></div> </td></tr></table>
backup, bz2, bzip2, ssh, tar, tar.bz2

Bash

Untar file

# For *.tar.gz
tar -zxvf <filename>
https://snipt.net/embed/94fd0df1188a3ffad23c4a80b2c6ce4f/
https://snipt.net/raw/94fd0df1188a3ffad23c4a80b2c6ce4f/
94fd0df1188a3ffad23c4a80b2c6ce4f
bash
Bash
2
2016-12-02T14:16:15
True
False
False
Jul 19, 2012 at 07:54 PM
/api/public/snipt/44184/
untar-file-1
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># For *.tar.gz</span> </span><span id="L-2"><a name="L-2"></a>tar -zxvf &lt;filename&gt; </span></pre></div> </td></tr></table>
shell, tar

Bash

compress a file

tar -czvf archive.tgz files
https://snipt.net/embed/19b7759abc360f157f9fe4f99477320b/
https://snipt.net/raw/19b7759abc360f157f9fe4f99477320b/
19b7759abc360f157f9fe4f99477320b
bash
Bash
1
2016-12-03T14:16:06
True
False
False
/api/public/snipt/39160/
compress-a-file
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>tar -czvf archive.tgz files </span></pre></div> </td></tr></table>
gzip, tar

Bash

Extracting an Entire tar.gz Archive

tar -xvf [filename].tar.gz
https://snipt.net/embed/513f65aa5c3f3e3f7782b6859d26eecc/
https://snipt.net/raw/513f65aa5c3f3e3f7782b6859d26eecc/
513f65aa5c3f3e3f7782b6859d26eecc
bash
Bash
1
2016-12-04T02:43:25
True
False
False
/api/public/snipt/36516/
extracting-an-entire-targz-archive
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>tar -xvf <span class="o">[</span>filename<span class="o">]</span>.tar.gz </span></pre></div> </td></tr></table>
archive, extract, gz, tar
Copyrighted, illegal, or inappropriate content? Email [email protected].