snipt

Ctrl+h for KB shortcuts

Bash

拉回git 遠端branch

git checkout --track -b foobar origin/foobar 
# 將遠端的 branch checkout 回來並建立一個新的 local branch,加上 --track 表示你之後還要pull、push回去,所以請 Git 記住對應關係。
https://snipt.net/embed/e29c7918ceec0898b25249475481b39e/
https://snipt.net/raw/e29c7918ceec0898b25249475481b39e/
e29c7918ceec0898b25249475481b39e
bash
Bash
2
2016-09-27T06:05:42
True
False
False
Mar 09, 2016 at 09:01 PM
/api/public/snipt/144644/
git-branch
<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 id="L-1"><a name="L-1"></a>git checkout --track -b foobar origin/foobar </span><span id="L-2"><a name="L-2"></a><span class="c"># 將遠端的 branch checkout 回來並建立一個新的 local branch,加上 --track 表示你之後還要pull、push回去,所以請 Git 記住對應關係。</span> </span></pre></div> </td></tr></table>
git, sh

Bash

Search zombie process in linux with awk or without awk

1
2
3
4
5
#more effective, using awk
ps aux | awk '{ print $8 " " $2 }' | grep -w Z

#less effective, without awk
ps -el | grep 'Z'
https://snipt.net/embed/3bc0b112edf34393e223f18bd9b6d361/
https://snipt.net/raw/3bc0b112edf34393e223f18bd9b6d361/
3bc0b112edf34393e223f18bd9b6d361
bash
Bash
5
2016-09-27T00:52:26
True
False
False
/api/public/snipt/45495/
search-zombie-process-in-linux-with-awk-or-without-awk
<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><span class="c">#more effective, using awk</span> </span><span id="L-2"><a name="L-2"></a>ps aux <span class="p">|</span> awk <span class="s1">&#39;{ print $8 &quot; &quot; $2 }&#39;</span> <span class="p">|</span> grep -w Z </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c">#less effective, without awk</span> </span><span id="L-5"><a name="L-5"></a>ps -el <span class="p">|</span> grep <span class="s1">&#39;Z&#39;</span> </span></pre></div> </td></tr></table>
"search zombie process", awk, bash, linux, process, sh, zombie

Bash

Find all files by extension in a directory recursively

find directory/ -name \*.txt -print
https://snipt.net/embed/80b8c205e59dafa2b74aaef8ad089f91/
https://snipt.net/raw/80b8c205e59dafa2b74aaef8ad089f91/
80b8c205e59dafa2b74aaef8ad089f91
bash
Bash
1
2016-09-27T00:52:32
True
False
False
Aug 10, 2012 at 06:59 AM
/api/public/snipt/45493/
find-all-files-by-extension-in-a-directory-recursively
<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>find directory/ -name <span class="se">\*</span>.txt -print </span></pre></div> </td></tr></table>
all, bash, directory, extension, files, find, linux, recursive, recursively, sh

Bash

List directories in Linux

ls -d */
https://snipt.net/embed/e98a97a309bca1a86772d351bf8f93a5/
https://snipt.net/raw/e98a97a309bca1a86772d351bf8f93a5/
e98a97a309bca1a86772d351bf8f93a5
bash
Bash
1
2016-09-24T17:00:35
True
False
False
/api/public/snipt/25569/
list-directories-in-linux
<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>ls -d */ </span></pre></div> </td></tr></table>
bash, linux, ls, sh

Bash

number of file open by command

lsof | awk '{printf("%s\n",$1)}' | sort | uniq -c | sort -n
https://snipt.net/embed/75ca64e0793a44cbe1d4ec8120e4a6d7/
https://snipt.net/raw/75ca64e0793a44cbe1d4ec8120e4a6d7/
75ca64e0793a44cbe1d4ec8120e4a6d7
bash
Bash
2
2016-09-27T00:43:58
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 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

VimL

Matando processo pelo nome

1
2
3
4
5
6
7
8
# SH para finalizar um processo especifico pelo nome
# Criador - Jefferson Luis Follmann

#!/bin/sh
echo "Digite o nome do processo a ser finalizado"
read process
kill -9 `pgrep $process`
echo "Processo finalizado"
https://snipt.net/embed/9d0a4570f0ad41b65e6fdef47dba82fc/
https://snipt.net/raw/9d0a4570f0ad41b65e6fdef47dba82fc/
9d0a4570f0ad41b65e6fdef47dba82fc
vim
VimL
8
2016-09-26T17:03:42
True
False
False
/api/public/snipt/6669/
matando-processo-pelo-nome
<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># SH <span class="nb">para</span> finalizar um processo especifico pelo nome </span><span id="L-2"><a name="L-2"></a># Criador <span class="p">-</span> Jefferson Luis Follmann </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>#<span class="p">!</span><span class="sr">/bin/</span><span class="k">sh</span> </span><span id="L-5"><a name="L-5"></a>echo <span class="s2">&quot;Digite o nome do processo a ser finalizado&quot;</span> </span><span id="L-6"><a name="L-6"></a>read process </span><span id="L-7"><a name="L-7"></a>kill <span class="m">-9</span> `pgrep $process` </span><span id="L-8"><a name="L-8"></a>echo <span class="s2">&quot;Processo finalizado&quot;</span> </span></pre></div> </td></tr></table>
sh
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.