snipt

Ctrl+h for KB shortcuts

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

Bash

Remove all files previously extracted from a tar(.gz) file

tar -tf <file.tar.gz> | xargs rm -r
https://snipt.net/embed/5d8773e660327770fc89ea073fb2625e/
https://snipt.net/raw/5d8773e660327770fc89ea073fb2625e/
5d8773e660327770fc89ea073fb2625e
bash
Bash
1
2016-09-26T13:52:22
True
False
False
Oct 20, 2012 at 10:48 PM
/api/public/snipt/48845/
remove-all-files-previously-extracted-from-a-targz-file
<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>tar -tf &lt;file.tar.gz&gt; <span class="p">|</span> xargs rm -r </span></pre></div> </td></tr></table>
bash, rm, shell, tar

Bash

watch a find/rm in action as it moves through thousands of files

watch -n .5 "ps auxwwf | egrep 'find|rm'"
https://snipt.net/embed/0fb151c68fa9f5bebb586a5bc129fb30/
https://snipt.net/raw/0fb151c68fa9f5bebb586a5bc129fb30/
0fb151c68fa9f5bebb586a5bc129fb30
bash
Bash
1
2016-09-26T12:47:01
True
False
False
/api/public/snipt/8390/
watch-a-findrm-in-action-as-it-moves-through-thousands-of-files
<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>watch -n .5 <span class="s2">&quot;ps auxwwf | egrep &#39;find|rm&#39;&quot;</span> </span></pre></div> </td></tr></table>
auxwwf, egrep, find, ps, rm, watch

Bash

removing text files from a /cache/ directory, this is useful when an rm -rf /cache/ cant handle 100k+ files.

find cache -name '*.txt' -exec rm -f {} \;
https://snipt.net/embed/2031178c1e7867de0e156bb0be965339/
https://snipt.net/raw/2031178c1e7867de0e156bb0be965339/
2031178c1e7867de0e156bb0be965339
bash
Bash
1
2016-09-27T20:38:39
True
False
False
/api/public/snipt/8389/
removing-text-files-from-a-cache-directory-this-is-useful-when-an-rm-rf-cache-cant-handle-100k-files
<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 cache -name <span class="s1">&#39;*.txt&#39;</span> -exec rm -f <span class="o">{}</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
files, mass, quantity, remove, rm

Bash

Remove .svn directories recursively

find -name .svn -delete
https://snipt.net/embed/12d182d2adecb7887be0fc79ea4cb505/
https://snipt.net/raw/12d182d2adecb7887be0fc79ea4cb505/
12d182d2adecb7887be0fc79ea4cb505
bash
Bash
1
2016-09-27T20:41:49
True
False
False
/api/public/snipt/5048/
remove-svn-directories-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 -name .svn -delete </span></pre></div> </td></tr></table>
bash, find, linux, rm, svn

Bash

rm when argument list too long

find $directory -type f -name '*' -exec rm {} $directory2 \;
https://snipt.net/embed/31c54855b8976f504021ea2e317174c5/
https://snipt.net/raw/31c54855b8976f504021ea2e317174c5/
31c54855b8976f504021ea2e317174c5
bash
Bash
1
2016-09-27T09:07:11
True
False
False
/api/public/snipt/3700/
rm-when-argument-list-too-long
<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 <span class="nv">$directory</span> -type f -name <span class="s1">&#39;*&#39;</span> -exec rm <span class="o">{}</span> <span class="nv">$directory2</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
bash, rm
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.