snipt

Ctrl+h for KB shortcuts

Bash

Add temp swap

1
2
3
4
SWAP=/tmp/swap
dd if=/dev/zero of=$SWAP bs=1M count=500
mkswap $SWAP
swapon $SWAP
https://snipt.net/embed/4429675f13af24fe0392a6cd87b1c6c0/
https://snipt.net/raw/4429675f13af24fe0392a6cd87b1c6c0/
4429675f13af24fe0392a6cd87b1c6c0
bash
Bash
4
2016-09-25T02:06:55
True
False
False
/api/public/snipt/94767/
add-temp-swap
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nv">SWAP</span><span class="o">=</span>/tmp/swap </span><span id="L-2"><a name="L-2"></a>dd <span class="k">if</span><span class="o">=</span>/dev/zero <span class="nv">of</span><span class="o">=</span><span class="nv">$SWAP</span> <span class="nv">bs</span><span class="o">=</span>1M <span class="nv">count</span><span class="o">=</span>500 </span><span id="L-3"><a name="L-3"></a>mkswap <span class="nv">$SWAP</span> </span><span id="L-4"><a name="L-4"></a>swapon <span class="nv">$SWAP</span> </span></pre></div> </td></tr></table>
swap

C

Swap two var without temp var

1
2
3
4
5
6
7
8
#include <stdio.h>
int main(int argc, const char *argv[])
{
    int a=1,b=2;
	a ^= b ^= a ^= b;
	printf( "%d%d", a, b );
	return 0;
}
https://snipt.net/embed/0b615a104c1dd779b435516ecb21f8c9/
https://snipt.net/raw/0b615a104c1dd779b435516ecb21f8c9/
0b615a104c1dd779b435516ecb21f8c9
c
C
8
2016-09-24T14:49:46
True
False
False
/api/public/snipt/43233/
swap-two-var-without-temp-var
<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> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">#include &lt;stdio.h&gt;</span> </span><span id="L-2"><a name="L-2"></a><span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> </span><span id="L-3"><a name="L-3"></a><span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="kt">int</span> <span class="n">a</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span><span class="n">b</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">a</span> <span class="o">^=</span> <span class="n">b</span> <span class="o">^=</span> <span class="n">a</span> <span class="o">^=</span> <span class="n">b</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">printf</span><span class="p">(</span> <span class="s">&quot;%d%d&quot;</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="p">);</span> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
C, swap

Text only

run mkswap on any swap partitions in /etc/fstab

1
2
3
4
5
AWK en mkswap on 
http://tldp.org/HOWTO/Linux+FreeBSD-3.html
awk -- '/swap/ && ($1 !~ /#/) { system("mkswap "$1"") }' /etc/fstab

This will run mkswap on any swap partitions in /etc/fstab every time you boot except if they are commented out (having ``#'' as the first character in the line.)
https://snipt.net/embed/38a4daca649d69f6d4ac56fa3f097c03/
https://snipt.net/raw/38a4daca649d69f6d4ac56fa3f097c03/
38a4daca649d69f6d4ac56fa3f097c03
text
Text only
6
2016-09-22T18:00:28
True
False
False
/api/public/snipt/10348/
run-mkswap-on-any-swap-partitions-in-etcfstab
<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 id="L-1"><a name="L-1"></a>AWK en mkswap on </span><span id="L-2"><a name="L-2"></a>http://tldp.org/HOWTO/Linux+FreeBSD-3.html </span><span id="L-3"><a name="L-3"></a>awk -- &#39;/swap/ &amp;&amp; ($1 !~ /#/) { system(&quot;mkswap &quot;$1&quot;&quot;) }&#39; /etc/fstab </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>This will run mkswap on any swap partitions in /etc/fstab every time you boot except if they are commented out (having ``#&#39;&#39; as the first character in the line.) </span></pre></div> </td></tr></table>
/etc/fstab, any, in, mkswap, on, partitions, run, swap
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.