snipt

Ctrl+h for KB shortcuts

Bash

Rename multiple files

1
2
3
4
5
6
7
8
# Rename all *.txt to *.text
for f in *.txt; do 
    mv -- "$f" "${f%.txt}.text";
done

# or

rename "s/oldExtension/newExtension/" *.txt
https://snipt.net/embed/7bc9442f97afc132a8f65cf9a6ca88bb/
https://snipt.net/raw/7bc9442f97afc132a8f65cf9a6ca88bb/
7bc9442f97afc132a8f65cf9a6ca88bb
bash
Bash
8
2016-09-26T16:46:39
True
False
False
Dec 10, 2015 at 10:01 AM
/api/public/snipt/138790/
rename-multiple-files-723d6e4b
<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><span class="c"># Rename all *.txt to *.text</span> </span><span id="L-2"><a name="L-2"></a><span class="k">for</span> f in *.txt<span class="p">;</span> <span class="k">do</span> </span><span id="L-3"><a name="L-3"></a> mv -- <span class="s2">&quot;</span><span class="nv">$f</span><span class="s2">&quot;</span> <span class="s2">&quot;</span><span class="si">${</span><span class="nv">f</span><span class="p">%.txt</span><span class="si">}</span><span class="s2">.text&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="k">done</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="c"># or</span> </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a>rename <span class="s2">&quot;s/oldExtension/newExtension/&quot;</span> *.txt </span></pre></div> </td></tr></table>
rename

Bash

Bulk rename a lot of files removing all the occurrences of a specific string in their names

1
2
3
4
5
6
7
# Bulk rename a lot of files removing all the occurrences of a specific string in their names

# Example:
#     foo_1.jpg ---> 1.jpg
#     foo_AAA.pdf ---> AAA.pdf

for i in foo_*; do mv $i ${i/foo_/}; done
https://snipt.net/embed/23564cc60db7c0f3e62faed5efa2bdc5/
https://snipt.net/raw/23564cc60db7c0f3e62faed5efa2bdc5/
23564cc60db7c0f3e62faed5efa2bdc5
bash
Bash
7
2016-09-25T22:29:21
True
False
False
/api/public/snipt/66215/
-5176
<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"># Bulk rename a lot of files removing all the occurrences of a specific string in their names</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c"># Example:</span> </span><span id="L-4"><a name="L-4"></a><span class="c"># foo_1.jpg ---&gt; 1.jpg</span> </span><span id="L-5"><a name="L-5"></a><span class="c"># foo_AAA.pdf ---&gt; AAA.pdf</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="k">for</span> i in foo_*<span class="p">;</span> <span class="k">do</span> mv <span class="nv">$i</span> <span class="si">${</span><span class="nv">i</span><span class="p">/foo_/</span><span class="si">}</span><span class="p">;</span> <span class="k">done</span> </span></pre></div> </td></tr></table>
bash, for, mv, rename

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-09-26T12:04:16
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 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

Bash

Renombrar de [1-9].jpg a [01-09].jpg

for a in [1-9].jpg;do mv $a `printf %02d.%s ${a%.*} ${a##*.}`; done
https://snipt.net/embed/8812d182bee590adb4f43b998e6a54bd/
https://snipt.net/raw/8812d182bee590adb4f43b998e6a54bd/
8812d182bee590adb4f43b998e6a54bd
bash
Bash
1
2016-09-27T00:43:42
True
False
False
/api/public/snipt/20406/
renombrar-de-1-9jpg-a-01-09jpg
<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">for</span> a in <span class="o">[</span>1-9<span class="o">]</span>.jpg<span class="p">;</span><span class="k">do</span> mv <span class="nv">$a</span> <span class="sb">`</span><span class="nb">printf</span> %02d.%s <span class="si">${</span><span class="nv">a</span><span class="p">%.*</span><span class="si">}</span> <span class="si">${</span><span class="nv">a</span><span class="p">##*.</span><span class="si">}</span><span class="sb">`</span><span class="p">;</span> <span class="k">done</span> </span></pre></div> </td></tr></table>
bash, linux, rename
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.