snipt

Ctrl+h for KB shortcuts

Text only

Find directory

find . -type d -name "dir name"
https://snipt.net/embed/4bf1c8134a2ba8424e21dd1b156fac6a/
https://snipt.net/raw/4bf1c8134a2ba8424e21dd1b156fac6a/
4bf1c8134a2ba8424e21dd1b156fac6a
text
Text only
1
2016-09-27T14:48:48
True
False
False
Oct 14, 2015 at 05:13 AM
/api/public/snipt/141676/
find-directory-ea4b954d
<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 d -name &quot;dir name&quot; </span></pre></div> </td></tr></table>
bash, directory, find

Bash

find and delete files older than 15 minutes

$ find /path/to/files/*.json -type f -mmin +15 -delete
https://snipt.net/embed/526b8c150780e8fd47ad7b0adaac0e65/
https://snipt.net/raw/526b8c150780e8fd47ad7b0adaac0e65/
526b8c150780e8fd47ad7b0adaac0e65
bash
Bash
1
2016-09-27T14:46:49
True
False
False
/api/public/snipt/137461/
find-and-delete-files-older-than-15-minutes-e01e1c63
<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>find /path/to/files/*.json -type f -mmin +15 -delete </span></pre></div> </td></tr></table>
bash, delete, find, linux

Text only

chmod all folders but not files (recursively) in current folder

find . -type d -exec chmod 755 {} +
https://snipt.net/embed/83e1497787a15081acd5382519fd0cf9/
https://snipt.net/raw/83e1497787a15081acd5382519fd0cf9/
83e1497787a15081acd5382519fd0cf9
text
Text only
1
2016-09-26T00:08:30
True
False
False
Feb 04, 2014 at 01:48 PM
/api/public/snipt/110909/
chmod-all-folders-but-not-files-recursively-in-current-folder
<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 d -exec chmod 755 {} + </span></pre></div> </td></tr></table>
chmod, find

Bash

Recursively find and list the last modified files in a directory

stat --printf="%y %n\n" $(ls -tr $(find * -type f))
https://snipt.net/embed/658e81891f567c2b90931e8f90e60846/
https://snipt.net/raw/658e81891f567c2b90931e8f90e60846/
658e81891f567c2b90931e8f90e60846
bash
Bash
1
2016-09-26T19:25:48
True
False
False
Jan 31, 2014 at 06:10 AM
/api/public/snipt/109821/
recursively-find-and-list-the-last-modified-files-in-a-directory
<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>stat --printf<span class="o">=</span><span class="s2">&quot;%y %n\n&quot;</span> <span class="k">$(</span>ls -tr <span class="k">$(</span>find * -type f<span class="k">))</span> </span></pre></div> </td></tr></table>
date, find, ls, stat

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-21T14:19:28
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

MySQL

find/replace MySQL

update table set field = REPLACE(field, 'string', 'anothervalue') WHERE field LIKE '%string%';
https://snipt.net/embed/174004aca4c229297e85a91df9066abb/
https://snipt.net/raw/174004aca4c229297e85a91df9066abb/
174004aca4c229297e85a91df9066abb
mysql
MySQL
2
2016-09-23T23:59:21
True
False
False
Jun 11, 2013 at 08:36 AM
/api/public/snipt/63821/
findreplace-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 id="L-1"><a name="L-1"></a><span class="k">update</span> <span class="k">table</span> <span class="kt">set</span> <span class="n">field</span> <span class="o">=</span> <span class="k">REPLACE</span><span class="p">(</span><span class="n">field</span><span class="p">,</span> <span class="s1">&#39;string&#39;</span><span class="p">,</span> <span class="s1">&#39;anothervalue&#39;</span><span class="p">)</span> <span class="k">WHERE</span> <span class="n">field</span> <span class="k">LIKE</span> <span class="s1">&#39;%string%&#39;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
find, mysql, replace

Bash

extract a specific file from a tar.gz

$ tar xfz abc.tar --wildcards --no-anchored 'redpics*'
https://snipt.net/embed/ab0da6899101a03376177ec62f65a74b/
https://snipt.net/raw/ab0da6899101a03376177ec62f65a74b/
ab0da6899101a03376177ec62f65a74b
bash
Bash
1
2016-09-26T13:48:25
True
False
False
Feb 23, 2013 at 07:10 PM
/api/public/snipt/53824/
extract-a-specific-file-from-a-targz
<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>tar xfz abc.tar --wildcards --no-anchored <span class="s1">&#39;redpics*&#39;</span> </span></pre></div> </td></tr></table>
extract, find, gz, tar, zip

Bash

find and delete files older than 5 days

1
2
3
4
5
$ find /path/to/files* -mtime +5 -exec rm {} \;

 
 
 
https://snipt.net/embed/6ba81578b80504eebccf9cbbef117b26/
https://snipt.net/raw/6ba81578b80504eebccf9cbbef117b26/
6ba81578b80504eebccf9cbbef117b26
bash
Bash
5
2016-09-21T11:37:59
True
False
False
/api/public/snipt/49835/
find-and-delete-files-older-than-5-days
<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="nv">$ </span>find /path/to/files* -mtime +5 -exec rm <span class="o">{}</span> <span class="se">\;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> </span></pre></div> </td></tr></table>
delete, find, linux, rm, time, ubuntu, unix
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.