snipt

Ctrl+h for KB shortcuts

Bash

awk command for printing out a list of unique IP addresses from an apache access_log

awk '{ip[$1]=0} END {for (address in ip) { print address} }' /home/admin/logs/access_log
https://snipt.net/embed/b40e2bfb63ad279ce459b5d2ee0d1980/
/raw/b40e2bfb63ad279ce459b5d2ee0d1980/
b40e2bfb63ad279ce459b5d2ee0d1980
bash
Bash
1
2019-08-24T16:23:58
True
False
False
/api/public/snipt/6121/
awk-command-for-printing-out-a-list-of-unique-ip-addresses-from-an-apache-access_log
<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>awk <span class="s1">&#39;{ip[$1]=0} END {for (address in ip) { print address} }&#39;</span> /home/admin/logs/access_log </span></pre></div> </td></tr></table>
awk, bash

Bash

Find the location of the currently used binary on unix

$ which mysql
/usr/bin/mysql
https://snipt.net/embed/5b390f07c5e451699a43dc6d8dfd95e2/
/raw/5b390f07c5e451699a43dc6d8dfd95e2/
5b390f07c5e451699a43dc6d8dfd95e2
bash
Bash
2
2019-07-30T21:27:46
True
False
False
/api/public/snipt/4532/
find-the-location-of-the-currently-used-binary-on-unix
<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>$ which mysql </span><span id="L-2"><a name="L-2"></a>/usr/bin/mysql </span></pre></div> </td></tr></table>
bash, which

Bash

Reset a file's contents to ''

echo -n "" > /path/to/file
https://snipt.net/embed/c856c1428a8d8f8b591840636d6b88ff/
/raw/c856c1428a8d8f8b591840636d6b88ff/
c856c1428a8d8f8b591840636d6b88ff
bash
Bash
1
2019-08-11T16:37:29
True
False
False
/api/public/snipt/3455/
reset-a-files-contents-to
<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">echo</span> -n <span class="s2">&quot;&quot;</span> &gt; /path/to/file </span></pre></div> </td></tr></table>
bash

Bash

process a bunch of XML files w/this python script

find . -name '*.xml' -print | xargs python my-python-script.py
https://snipt.net/embed/d43c22f54e66976a68e152388c3939b3/
/raw/d43c22f54e66976a68e152388c3939b3/
d43c22f54e66976a68e152388c3939b3
bash
Bash
1
2019-08-21T04:04:03
True
False
False
/api/public/snipt/1655/
process-a-bunch-of-xml-files-wthis-python-script
<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>find . -name <span class="s1">&#39;*.xml&#39;</span> -print <span class="p">|</span> xargs python my-python-script.py </span></pre></div> </td></tr></table>
bash, find, xargs

Bash

List all users

1
2
3
4
$ cat /etc/passwd 

$ cat /etc/passwd | cut -d: -f1 
# only show names
https://snipt.net/embed/e7fbbbaa438dd5473d8734dc8f639374/
/raw/e7fbbbaa438dd5473d8734dc8f639374/
e7fbbbaa438dd5473d8734dc8f639374
bash
Bash
4
2019-08-16T08:40:39
True
False
False
/api/public/snipt/1177/
list-all-users
<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></span><span id="L-1"><a name="L-1"></a>$ cat /etc/passwd </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>$ cat /etc/passwd <span class="p">|</span> cut -d: -f1 </span><span id="L-4"><a name="L-4"></a><span class="c1"># only show names</span> </span></pre></div> </td></tr></table>
bash