snipt

Ctrl+h for KB shortcuts

Text only

grep

grep -rl 'localhost'*
https://snipt.net/embed/4a037fbac753c858472c616f6ec6d498/
/raw/4a037fbac753c858472c616f6ec6d498/
4a037fbac753c858472c616f6ec6d498
text
Text only
1
2019-07-11T05:03:48
True
False
False
/api/public/snipt/5905/
grep
<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>grep -rl &#39;localhost&#39;* </span></pre></div> </td></tr></table>
ssh

Bash

lsof = list of open files; awk = grab first two columns, sort / uniq makes it pretty

1
2
3
4
5
lsof | awk '{print $1, $2}' | sort | uniq -f 1 -c

or

lsof | awk '{print $1, $2}' | sort | uniq -c | sort -rn 
https://snipt.net/embed/bd03cdc4721feb35fb3bea17091eaa8f/
/raw/bd03cdc4721feb35fb3bea17091eaa8f/
bd03cdc4721feb35fb3bea17091eaa8f
bash
Bash
5
2019-07-28T09:09:08
True
False
False
/api/public/snipt/5723/
lsof-list-of-open-files-awk-grab-first-two-columns-sort-uniq-makes-it-pretty
<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>lsof <span class="p">|</span> awk <span class="s1">&#39;{print $1, $2}&#39;</span> <span class="p">|</span> sort <span class="p">|</span> uniq -f <span class="m">1</span> -c </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>or </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>lsof <span class="p">|</span> awk <span class="s1">&#39;{print $1, $2}&#39;</span> <span class="p">|</span> sort <span class="p">|</span> uniq -c <span class="p">|</span> sort -rn </span></pre></div> </td></tr></table>
"open files", isof, ssh

Bash

add ssh key to remote host

cat ~/.ssh/id_rsa.pub | ssh [email protected] 'sh -c "cat - >>~/.ssh/authorized_keys"'
https://snipt.net/embed/c4115fc0111cbe159b37f30f926abab5/
/raw/c4115fc0111cbe159b37f30f926abab5/
c4115fc0111cbe159b37f30f926abab5
bash
Bash
1
2019-08-16T19:44:40
True
False
False
/api/public/snipt/4985/
add-ssh-key-to-remote-host
<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>cat ~/.ssh/id_rsa.pub <span class="p">|</span> ssh [email protected] <span class="s1">&#39;sh -c &quot;cat - &gt;&gt;~/.ssh/authorized_keys&quot;&#39;</span> </span></pre></div> </td></tr></table>
cli, ssh

Bash

SSH Tunnel

1
2
3
# Forwards local traffic on port 2222 to the remote appserver host on port 9999.
# e.g. http://localhost:2222
ssh -N -p 22 [email protected] -L 2222/appserver/9999
https://snipt.net/embed/58541989f1c1e9f6a67558f8e7359451/
/raw/58541989f1c1e9f6a67558f8e7359451/
58541989f1c1e9f6a67558f8e7359451
bash
Bash
3
2019-08-14T14:46:21
True
False
False
/api/public/snipt/4470/
ssh-tunnel-1
<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"># Forwards local traffic on port 2222 to the remote appserver host on port 9999.</span> </span><span id="L-2"><a name="L-2"></a><span class="c1"># e.g. http://localhost:2222</span> </span><span id="L-3"><a name="L-3"></a>ssh -N -p <span class="m">22</span> [email protected] -L 2222/appserver/9999 </span></pre></div> </td></tr></table>
ssh

Bash

copy PostgreSQL database from remote machine

[email protected] $ sudo -u postgres dropdb mydb
[email protected] $ ssh remote sudo -u postgres pg_dump -C mydb | sudo -u postgres psql
https://snipt.net/embed/24ccfb7bbc25089656f0665e6fca6aef/
/raw/24ccfb7bbc25089656f0665e6fca6aef/
24ccfb7bbc25089656f0665e6fca6aef
bash
Bash
2
2019-08-13T12:42:33
True
False
False
/api/public/snipt/4454/
copy-postgresql-database-from-remote-machine
<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>[email protected] $ sudo -u postgres dropdb mydb </span><span id="L-2"><a name="L-2"></a>[email protected] $ ssh remote sudo -u postgres pg_dump -C mydb <span class="p">|</span> sudo -u postgres psql </span></pre></div> </td></tr></table>
copy, database, postgresql, ssh, sudo

Bash

find large files +email results

cd / ; find . -size '+10000k' -exec ls -Shl {} \; | mail -s"disk usage over 10MB" [email protected]
https://snipt.net/embed/dd57c813ae3b03346e4984f1fb90301a/
/raw/dd57c813ae3b03346e4984f1fb90301a/
dd57c813ae3b03346e4984f1fb90301a
bash
Bash
1
2019-08-16T10:26:35
True
False
False
/api/public/snipt/4108/
find-large-files-email-results
<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><span class="nb">cd</span> / <span class="p">;</span> find . -size <span class="s1">&#39;+10000k&#39;</span> -exec ls -Shl <span class="o">{}</span> <span class="se">\;</span> <span class="p">|</span> mail -s<span class="s2">&quot;disk usage over 10MB&quot;</span> [email protected] </span></pre></div> </td></tr></table>
diskusage, find, ssh