snipt

Ctrl+h for KB shortcuts

Text only

Untitled

cd /var/www/html/
find . -name ‘file_name.php’
https://snipt.net/embed/420a2c8ecb773516a87ba6624bcc1801/
https://snipt.net/raw/420a2c8ecb773516a87ba6624bcc1801/
420a2c8ecb773516a87ba6624bcc1801
text
Text only
2
2016-09-29T05:51:32
True
False
False
Oct 19, 2015 at 10:09 AM
/api/public/snipt/141816/
-a15e3f05
<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>cd /var/www/html/ </span><span id="L-2"><a name="L-2"></a>find . -name ‘file_name.php’ </span></pre></div> </td></tr></table>
grep, search

Bash

Grepping large files; fast_grep

1
2
3
4
5
6
7
#!/bin/bash

# Info:  http://www.inmotionhosting.com/support/website/ssh/speed-up-grep-searches-with-lc-all
# LC_ALL=C sets locale to ASCII
# fgrep wraps "grep -F" -- search for plain strings (no regex)

alias fast_grep='LC_ALL=C fgrep --color'
https://snipt.net/embed/342fae09c5198ee93ea599ce9304985a/
https://snipt.net/raw/342fae09c5198ee93ea599ce9304985a/
342fae09c5198ee93ea599ce9304985a
bash
Bash
7
2016-09-29T11:15:27
True
False
False
Aug 07, 2015 at 09:35 AM
/api/public/snipt/140578/
grepping-large-files-fast_grep
<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><span class="c">#!/bin/bash</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c"># Info: http://www.inmotionhosting.com/support/website/ssh/speed-up-grep-searches-with-lc-all</span> </span><span id="L-4"><a name="L-4"></a><span class="c"># LC_ALL=C sets locale to ASCII</span> </span><span id="L-5"><a name="L-5"></a><span class="c"># fgrep wraps &quot;grep -F&quot; -- search for plain strings (no regex)</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="nb">alias </span><span class="nv">fast_grep</span><span class="o">=</span><span class="s1">&#39;LC_ALL=C fgrep --color&#39;</span> </span></pre></div> </td></tr></table>
grep

Bash

git > search history

$ git log -Stext_to_find -p
https://snipt.net/embed/0eb7bfed95040f611c21ad1f4b2dc5ae/
https://snipt.net/raw/0eb7bfed95040f611c21ad1f4b2dc5ae/
0eb7bfed95040f611c21ad1f4b2dc5ae
bash
Bash
2
2016-09-28T02:16:56
True
False
False
Oct 07, 2013 at 09:41 PM
/api/public/snipt/86209/
git-search-history
<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="nv">$ </span>git log -Stext_to_find -p </span></pre></div> </td></tr></table>
bash, find, git, grep, search

Bash

kill process that contains string but not another string

1
2
3
4
5
# command line:
$ pgrep -lf "spork" | grep -v "tmux" | awk '{print $1}' | xargs kill -9

# via yaml or environment hostile to special characters (e.g., tmuxinator config)
$ kill -9 $(pgrep -lf "rails s" | grep -v "tmux" | cut -d " " -f1); rails s
https://snipt.net/embed/f78fdc50c4bf053db181c85adfb124ea/
https://snipt.net/raw/f78fdc50c4bf053db181c85adfb124ea/
f78fdc50c4bf053db181c85adfb124ea
bash
Bash
6
2016-09-29T02:12:27
True
False
False
Apr 11, 2013 at 12:51 AM
/api/public/snipt/56301/
kill-process-that-contains-string-but-not-another-string
<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"># command line:</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$ </span>pgrep -lf <span class="s2">&quot;spork&quot;</span> <span class="p">|</span> grep -v <span class="s2">&quot;tmux&quot;</span> <span class="p">|</span> awk <span class="s1">&#39;{print $1}&#39;</span> <span class="p">|</span> xargs <span class="nb">kill</span> -9 </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c"># via yaml or environment hostile to special characters (e.g., tmuxinator config)</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$ </span><span class="nb">kill</span> -9 <span class="k">$(</span>pgrep -lf <span class="s2">&quot;rails s&quot;</span> <span class="p">|</span> grep -v <span class="s2">&quot;tmux&quot;</span> <span class="p">|</span> cut -d <span class="s2">&quot; &quot;</span> -f1<span class="k">)</span><span class="p">;</span> rails s </span></pre></div> </td></tr></table>
awk, cut, grep, kill, linux, pgrep, process, rails, server, spork, tmux, tmuxinator, ubuntu, xargs

Text only

archive svn modified files

1
2
3
4
5
6
7
8
#archive all svn modified filed
svn st | grep ^M | awk '{print $2}' | xargs tar czf changed.tar.gz

#list contents of the archive
tar -tf changed.tar.gz

#for an entire repository
svn export URL PATH ; tar czf exported_copy.tgz PATH
https://snipt.net/embed/9e9353251d821ca3391aa73acb579fc0/
https://snipt.net/raw/9e9353251d821ca3391aa73acb579fc0/
9e9353251d821ca3391aa73acb579fc0
text
Text only
8
2016-09-22T14:57:39
True
False
False
/api/public/snipt/46533/
archive-svn-modified-files
<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>#archive all svn modified filed </span><span id="L-2"><a name="L-2"></a>svn st | grep ^M | awk &#39;{print $2}&#39; | xargs tar czf changed.tar.gz </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>#list contents of the archive </span><span id="L-5"><a name="L-5"></a>tar -tf changed.tar.gz </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a>#for an entire repository </span><span id="L-8"><a name="L-8"></a>svn export URL PATH ; tar czf exported_copy.tgz PATH </span></pre></div> </td></tr></table>
awk, grep, svn

Bash

Add all the new svn files at once

svn status | grep "^?" | awk '{print $2}' | xargs svn add
https://snipt.net/embed/cf7e32e54cfe6423fd3d164544f2c9b7/
https://snipt.net/raw/cf7e32e54cfe6423fd3d164544f2c9b7/
cf7e32e54cfe6423fd3d164544f2c9b7
bash
Bash
1
2016-09-27T21:12:39
True
False
False
/api/public/snipt/38619/
add-all-the-new-svn-files-at-once
<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>svn status <span class="p">|</span> grep <span class="s2">&quot;^?&quot;</span> <span class="p">|</span> awk <span class="s1">&#39;{print $2}&#39;</span> <span class="p">|</span> xargs svn add </span></pre></div> </td></tr></table>
awk, grep, svn, xarg

Bash

List filenames only when using grep

1
2
3
find -type f -name "..." | xargs grep -l "..."

# grep -l: Suppress normal output; instead print the name of each input file from which no output would normally have been printed.
https://snipt.net/embed/16692c81bac5a0fff5376fb2835e844d/
https://snipt.net/raw/16692c81bac5a0fff5376fb2835e844d/
16692c81bac5a0fff5376fb2835e844d
bash
Bash
3
2016-09-21T12:25:20
True
False
False
/api/public/snipt/34528/
list-filenames-only-when-using-grep
<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>find -type f -name <span class="s2">&quot;...&quot;</span> <span class="p">|</span> xargs grep -l <span class="s2">&quot;...&quot;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c"># grep -l: Suppress normal output; instead print the name of each input file from which no output would normally have been printed.</span> </span></pre></div> </td></tr></table>
grep

Bash

Exclude svn directories when using find and grep.

find -type f -name "..." \( -not -iname "*.svn*" \) | xargs grep "..."
https://snipt.net/embed/04efe668c94740fa12e557630345439e/
https://snipt.net/raw/04efe668c94740fa12e557630345439e/
04efe668c94740fa12e557630345439e
bash
Bash
1
2016-09-28T17:45:59
True
False
False
/api/public/snipt/34137/
exclude-svn-directories-when-using-find-and-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 id="L-1"><a name="L-1"></a>find -type f -name <span class="s2">&quot;...&quot;</span> <span class="se">\(</span> -not -iname <span class="s2">&quot;*.svn*&quot;</span> <span class="se">\)</span> <span class="p">|</span> xargs grep <span class="s2">&quot;...&quot;</span> </span></pre></div> </td></tr></table>
bash, grep
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.