Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

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/
https://snipt.net/raw/80b8c205e59dafa2b74aaef8ad089f91/
80b8c205e59dafa2b74aaef8ad089f91
bash
Bash
1
2016-12-10T09:15:31
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 Session

How to concatenate all files in unix

1
2
3
$ cd /path/to/files
$ files=*
$ cat $files > bigfile
https://snipt.net/embed/5bd379349afa8d92754a3c6acd3b4b0f/
https://snipt.net/raw/5bd379349afa8d92754a3c6acd3b4b0f/
5bd379349afa8d92754a3c6acd3b4b0f
console
Bash Session
3
2016-12-07T20:06:11
True
False
False
/api/public/snipt/44068/
how-to-concatenate-all-files-in-unix
<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></span><span id="L-1"><a name="L-1"></a><span class="gp">$</span> <span class="nb">cd</span> /path/to/files </span><span id="L-2"><a name="L-2"></a><span class="gp">$</span> <span class="nv">files</span><span class="o">=</span>* </span><span id="L-3"><a name="L-3"></a><span class="gp">$</span> cat <span class="nv">$files</span> &gt; bigfile </span></pre></div> </td></tr></table>
concatenate, file, files, unix

Bash

Rename multiple files with nomenclature Linux

count=1; for i in *.jpg; do j=`printf "%04d" $count`; j="DSCM"$j".jpg"; count=$((count + 1)); mv "$i" $j; done
https://snipt.net/embed/d2ee1531297a4a3db622e5ffe2a81651/
https://snipt.net/raw/d2ee1531297a4a3db622e5ffe2a81651/
d2ee1531297a4a3db622e5ffe2a81651
bash
Bash
1
2016-12-09T20:47:09
True
False
False
/api/public/snipt/35217/
rename-multiple-files-with-nomenclature-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></span><span id="L-1"><a name="L-1"></a><span class="nv">count</span><span class="o">=</span>1<span class="p">;</span> <span class="k">for</span> i in *.jpg<span class="p">;</span> <span class="k">do</span> <span class="nv">j</span><span class="o">=</span><span class="sb">`</span><span class="nb">printf</span> <span class="s2">&quot;%04d&quot;</span> <span class="nv">$count</span><span class="sb">`</span><span class="p">;</span> <span class="nv">j</span><span class="o">=</span><span class="s2">&quot;DSCM&quot;</span><span class="nv">$j</span><span class="s2">&quot;.jpg&quot;</span><span class="p">;</span> <span class="nv">count</span><span class="o">=</span><span class="k">$((</span>count <span class="o">+</span> <span class="m">1</span><span class="k">))</span><span class="p">;</span> mv <span class="s2">&quot;</span><span class="nv">$i</span><span class="s2">&quot;</span> <span class="nv">$j</span><span class="p">;</span> <span class="k">done</span> </span></pre></div> </td></tr></table>
files, linux, mv, rename

Text only

"Too many open files" solution

1
2
3
4
5
6
7
1. In /etc/security/limits.conf 
* soft nofile 10000
* hard nofile 65535
2. Increase ulimit by "ulimit -n 65535"
3. echo 65535 > /proc/sys/fs/file-max
4. In /etc/sysctl.conf 
fs.file-max=65535
https://snipt.net/embed/75876659ef79e4cc8a4e6e38cd108264/
https://snipt.net/raw/75876659ef79e4cc8a4e6e38cd108264/
75876659ef79e4cc8a4e6e38cd108264
text
Text only
7
2016-12-10T19:40:14
True
False
False
/api/public/snipt/27936/
too-many-open-files-solution
<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></span><span id="L-1"><a name="L-1"></a>1. In /etc/security/limits.conf </span><span id="L-2"><a name="L-2"></a>* soft nofile 10000 </span><span id="L-3"><a name="L-3"></a>* hard nofile 65535 </span><span id="L-4"><a name="L-4"></a>2. Increase ulimit by &quot;ulimit -n 65535&quot; </span><span id="L-5"><a name="L-5"></a>3. echo 65535 &gt; /proc/sys/fs/file-max </span><span id="L-6"><a name="L-6"></a>4. In /etc/sysctl.conf </span><span id="L-7"><a name="L-7"></a>fs.file-max=65535 </span></pre></div> </td></tr></table>
bash, debian, files, linux, many, too, ubuntu

Bash

reset directory and file permissions

find . -type d -exec chmod 755 '{}' \;
find . -type f -exec chmod 644 '{}' \;
https://snipt.net/embed/13c44930f8c15d25f5f14a9f66db4ff9/
https://snipt.net/raw/13c44930f8c15d25f5f14a9f66db4ff9/
13c44930f8c15d25f5f14a9f66db4ff9
bash
Bash
2
2016-12-07T20:07:43
True
False
False
/api/public/snipt/27678/
reset-directory-and-file-permissions
<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></span><span id="L-1"><a name="L-1"></a>find . -type d -exec chmod <span class="m">755</span> <span class="s1">&#39;{}&#39;</span> <span class="se">\;</span> </span><span id="L-2"><a name="L-2"></a>find . -type f -exec chmod <span class="m">644</span> <span class="s1">&#39;{}&#39;</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
bash, directories, files, permissions

Bash

change all files in directory modification date

 find . -exec touch {} \;
https://snipt.net/embed/69971c8558a1e76384e7044439811f13/
https://snipt.net/raw/69971c8558a1e76384e7044439811f13/
69971c8558a1e76384e7044439811f13
bash
Bash
1
2016-12-10T18:51:17
True
False
False
/api/public/snipt/27437/
change-all-files-in-directory-modification-date
<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 . -exec touch <span class="o">{}</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
bash, files, linux, touch
Copyrighted, illegal, or inappropriate content? Email [email protected].