snipt

Ctrl+h for KB shortcuts

Bash

Find all files by extension in a directory recursively

find directory/ -name \*.txt -print
https://snipt.net/embed/80b8c205e59dafa2b74aaef8ad089f91/
/raw/80b8c205e59dafa2b74aaef8ad089f91/
80b8c205e59dafa2b74aaef8ad089f91
bash
Bash
1
2019-07-21T03:51:47
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></span><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

Recursively replace BOM-Characters in files

find . -type f -exec sed -i '1 s/^\xef\xbb\xbf//' {} +
https://snipt.net/embed/7b23948a6d67efbc9c7475550756078d/
/raw/7b23948a6d67efbc9c7475550756078d/
7b23948a6d67efbc9c7475550756078d
bash
Bash
1
2019-07-21T09:12:54
True
False
False
/api/public/snipt/30472/
recursively-replace-bom-characters-in-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></span><span id="L-1"><a name="L-1"></a>find . -type f -exec sed -i <span class="s1">&#39;1 s/^\xef\xbb\xbf//&#39;</span> <span class="o">{}</span> + </span></pre></div> </td></tr></table>
bom, recursively, replace, sed, shell, utf8

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

Delete recursively a file (.DS_Store, thumbs.db, desktop.ini, etc.)

find . -name ".DS_Store" -depth -exec rm {} \;
https://snipt.net/embed/faadacd4013789e46ac9532c9829ed72/
/raw/faadacd4013789e46ac9532c9829ed72/
faadacd4013789e46ac9532c9829ed72
bash
Bash
1
2019-07-21T03:32:17
True
False
False
/api/public/snipt/1625/
delete-recursively-a-file-ds_store-thumbsdb-desktopini-etc
<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>find . -name <span class="s2">&quot;.DS_Store&quot;</span> -depth -exec rm <span class="o">{}</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
bash, delete, file, files, find, recursion, recursively