snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#82705

Bash

infinite netcat

while true; do echo 'hello world' | netcat -l 80; done
https://snipt.net/embed/357df2b5856d7315e30f1650bf9b6c5d/
https://snipt.net/raw/357df2b5856d7315e30f1650bf9b6c5d/
357df2b5856d7315e30f1650bf9b6c5d
bash
Bash
1
2014-04-23T11:10:14
True
False
Sep 23, 2013 at 05:07 PM
/api/public/snipt/82705/
infinite-netcat
<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 id="L-1"><a name="L-1"></a><span class="k">while </span><span class="nb">true</span><span class="p">;</span> <span class="k">do </span><span class="nb">echo</span> <span class="s1">&#39;hello world&#39;</span> <span class="p">|</span> netcat -l 80<span class="p">;</span> <span class="k">done</span> </span></pre></div> </td></tr></table>
bash, netcat
#6723

Bash

Bash—please save my history for ever and eternity (or, at least a really long time)

1
2
3
4
5
6
# In .bashrc or .bash_profile
export HISTCONTROL=ignoredups:ignorespace
export HISTSIZE=10000
export HISTFILESIZE=1000000
export HISTTIMEFORMAT="%F %T "
export PROMPT_COMMAND='history -a'
https://snipt.net/embed/66a35c6d935778d767cbf849bd50c74f/
https://snipt.net/raw/66a35c6d935778d767cbf849bd50c74f/
66a35c6d935778d767cbf849bd50c74f
bash
Bash
7
2014-04-23T18:17:04
True
False
/api/public/snipt/6723/
bashsave-my-history-for-ever-and-eternity-well-almost
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c"># In .bashrc or .bash_profile</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">export </span><span class="nv">HISTCONTROL</span><span class="o">=</span>ignoredups:ignorespace </span><span id="L-3"><a name="L-3"></a><span class="nb">export </span><span class="nv">HISTSIZE</span><span class="o">=</span>10000 </span><span id="L-4"><a name="L-4"></a><span class="nb">export </span><span class="nv">HISTFILESIZE</span><span class="o">=</span>1000000 </span><span id="L-5"><a name="L-5"></a><span class="nb">export </span><span class="nv">HISTTIMEFORMAT</span><span class="o">=</span><span class="s2">&quot;%F %T &quot;</span> </span><span id="L-6"><a name="L-6"></a><span class="nb">export </span><span class="nv">PROMPT_COMMAND</span><span class="o">=</span><span class="s1">&#39;history -a&#39;</span> </span></pre></div> </td></tr></table>
bash, history
#6407

Bash

Change Linux hostname without reboot

1
2
3
vim /etc/hostname
vim /etc/hosts
hostname new-hostname
https://snipt.net/embed/88ab7887b6637d9446fd791c21d5e134/
https://snipt.net/raw/88ab7887b6637d9446fd791c21d5e134/
88ab7887b6637d9446fd791c21d5e134
bash
Bash
3
2014-04-24T12:40:31
True
False
/api/public/snipt/6407/
change-linux-hostname-without-reboot
<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 id="L-1"><a name="L-1"></a>vim /etc/hostname </span><span id="L-2"><a name="L-2"></a>vim /etc/hosts </span><span id="L-3"><a name="L-3"></a>hostname new-hostname </span></pre></div> </td></tr></table>
admin, bash, linux
#5372

Bash

Drop all tables from PostgreSQL DB without superuser

1
2
3
4
5
6
7
psql -t -d my_dbname -c "SELECT 'DROP TABLE ' || n.nspname || '.' ||
c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN
pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind =
'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND
pg_catalog.pg_table_is_visible(c.oid)" >/tmp/droptables

psql -d my_dbname -f /tmp/droptables
https://snipt.net/embed/d4e3c9b96cbc3fd791b8ee43a7edb971/
https://snipt.net/raw/d4e3c9b96cbc3fd791b8ee43a7edb971/
d4e3c9b96cbc3fd791b8ee43a7edb971
bash
Bash
7
2014-04-24T05:53:14
True
False
/api/public/snipt/5372/
drop-all-tables-from-postgresql-db-without-superuser
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>psql -t -d my_dbname -c <span class="s2">&quot;SELECT &#39;DROP TABLE &#39; || n.nspname || &#39;.&#39; ||</span> </span><span id="L-2"><a name="L-2"></a><span class="s2">c.relname || &#39; CASCADE;&#39; FROM pg_catalog.pg_class AS c LEFT JOIN</span> </span><span id="L-3"><a name="L-3"></a><span class="s2">pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind =</span> </span><span id="L-4"><a name="L-4"></a><span class="s2">&#39;r&#39; AND n.nspname NOT IN (&#39;pg_catalog&#39;, &#39;pg_toast&#39;) AND</span> </span><span id="L-5"><a name="L-5"></a><span class="s2">pg_catalog.pg_table_is_visible(c.oid)&quot;</span> &gt;/tmp/droptables </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a>psql -d my_dbname -f /tmp/droptables </span></pre></div> </td></tr></table>
bash, db, postgresql