snipt

Ctrl+h for KB shortcuts

Bash

buscar archivos por permiso

#buscará los archivos con permiso s en grupo
find . -perm -g=s 
https://snipt.net/embed/7fb2c1de149218ad21cad873b6e085d7/
/raw/7fb2c1de149218ad21cad873b6e085d7/
7fb2c1de149218ad21cad873b6e085d7
bash
Bash
2
2019-07-12T15:48:38
True
False
False
/api/public/snipt/28614/
buscar-archivos-por-permiso
<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">#buscará los archivos con permiso s en grupo</span> </span><span id="L-2"><a name="L-2"></a>find . -perm -g<span class="o">=</span>s </span></pre></div> </td></tr></table>
bash, chmod, find, permission

Bash

change file permission to

1
2
3
4
5
# for files only
$find ./ -type f -exec chmod 644 {} +

# for directories only
$find ./ -type d -exec chmod 644 {} +
https://snipt.net/embed/63036dd4c315da178ae73571de57c0f3/
/raw/63036dd4c315da178ae73571de57c0f3/
63036dd4c315da178ae73571de57c0f3
bash
Bash
5
2019-07-11T18:30:29
True
False
False
/api/public/snipt/25321/
change-file-permission-to
<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"># for files only</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$find</span> ./ -type f -exec chmod <span class="m">644</span> <span class="o">{}</span> + </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1"># for directories only</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$find</span> ./ -type d -exec chmod <span class="m">644</span> <span class="o">{}</span> + </span></pre></div> </td></tr></table>
chmod, files, find, permission, recursively

Bash

generar passwords

 < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c10
https://snipt.net/embed/c0e47c099d30110912c064f69245f23b/
/raw/c0e47c099d30110912c064f69245f23b/
c0e47c099d30110912c064f69245f23b
bash
Bash
1
2019-07-09T03:16:23
True
False
False
/api/public/snipt/25002/
generar-passwords
<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> &lt; /dev/urandom tr -dc _A-Z-a-z-0-9 <span class="p">|</span> head -c10 </span></pre></div> </td></tr></table>
linux, passwords, security

Bash

Promedios de memoria, ejemplo con apache

ps aux|grep apache2|grep -v 'grep'|awk '{s+=$6} END {print "N.Proc",NR," | MemTotal=",s/1024,"M | MemAvg=",(s/NR)/1024,"M"}'
https://snipt.net/embed/1653e3f68ad5ff39a361ea20e3d70e80/
/raw/1653e3f68ad5ff39a361ea20e3d70e80/
1653e3f68ad5ff39a361ea20e3d70e80
bash
Bash
2
2019-07-10T07:26:17
True
False
False
/api/public/snipt/24860/
promedios-de-memoria
<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>ps aux<span class="p">|</span>grep apache2<span class="p">|</span>grep -v <span class="s1">&#39;grep&#39;</span><span class="p">|</span>awk <span class="s1">&#39;{s+=$6} END {print &quot;N.Proc&quot;,NR,&quot; | MemTotal=&quot;,s/1024,&quot;M | MemAvg=&quot;,(s/NR)/1024,&quot;M&quot;}&#39;</span> </span></pre></div> </td></tr></table>
apache, bash, procesos, server

Bash

Renombrar de [1-9].jpg a [01-09].jpg

for a in [1-9].jpg;do mv $a `printf %02d.%s ${a%.*} ${a##*.}`; done
https://snipt.net/embed/8812d182bee590adb4f43b998e6a54bd/
/raw/8812d182bee590adb4f43b998e6a54bd/
8812d182bee590adb4f43b998e6a54bd
bash
Bash
1
2019-07-09T14:42:16
True
False
False
/api/public/snipt/20406/
renombrar-de-1-9jpg-a-01-09jpg
<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="k">for</span> a in <span class="o">[</span>1-9<span class="o">]</span>.jpg<span class="p">;</span><span class="k">do</span> mv <span class="nv">$a</span> <span class="sb">`</span><span class="nb">printf</span> %02d.%s <span class="si">${</span><span class="nv">a</span><span class="p">%.*</span><span class="si">}</span> <span class="si">${</span><span class="nv">a</span><span class="p">##*.</span><span class="si">}</span><span class="sb">`</span><span class="p">;</span> <span class="k">done</span> </span></pre></div> </td></tr></table>
bash, linux, rename

Python

enjoy

1
2
3
from refrigerator import beer

beer.enjoy()
https://snipt.net/embed/76e369257240ded4b1c059cf20e8d9a4/
/raw/76e369257240ded4b1c059cf20e8d9a4/
76e369257240ded4b1c059cf20e8d9a4
python
Python
3
2019-07-08T22:33:11
True
False
False
/api/public/snipt/13171/
enjoy
<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="kn">from</span> <span class="nn">refrigerator</span> <span class="kn">import</span> <span class="n">beer</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="n">beer</span><span class="o">.</span><span class="n">enjoy</span><span class="p">()</span> </span></pre></div> </td></tr></table>
python

MySQL

que encodign tiene mysql

SHOW VARIABLES LIKE "character\_set\_database";
https://snipt.net/embed/ae4f5f5e670b388b1da17f808180c5dd/
/raw/ae4f5f5e670b388b1da17f808180c5dd/
ae4f5f5e670b388b1da17f808180c5dd
mysql
MySQL
1
2019-07-05T13:16:59
True
False
False
/api/public/snipt/13085/
que-encodign-tiene-mysql
<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="k">SHOW</span> <span class="n">VARIABLES</span> <span class="k">LIKE</span> <span class="s2">&quot;character\_set\_database&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
encoding, mysql, unicode, utf-8

Bash

number of file open by command

lsof | awk '{printf("%s\n",$1)}' | sort | uniq -c | sort -n
https://snipt.net/embed/75ca64e0793a44cbe1d4ec8120e4a6d7/
/raw/75ca64e0793a44cbe1d4ec8120e4a6d7/
75ca64e0793a44cbe1d4ec8120e4a6d7
bash
Bash
2
2019-07-10T00:02:13
True
False
False
/api/public/snipt/12772/
number-of-file-open-by-command
<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>lsof <span class="p">|</span> awk <span class="s1">&#39;{printf(&quot;%s\n&quot;,$1)}&#39;</span> <span class="p">|</span> sort <span class="p">|</span> uniq -c <span class="p">|</span> sort -n </span></pre></div> </td></tr></table>
awk, bash, files, lsof, sh, sort, uniq