<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: rename &#8211; Batch renaming files in command line</title>
	<atom:link href="http://blog.tordeu.com/?feed=rss2&#038;p=112" rel="self" type="application/rss+xml" />
	<link>http://blog.tordeu.com/?p=112</link>
	<description>a blog about stuff</description>
	<lastBuildDate>Mon, 01 Sep 2014 22:51:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.2</generator>
	<item>
		<title>By: Namit</title>
		<link>http://blog.tordeu.com/?p=112#comment-6516</link>
		<dc:creator>Namit</dc:creator>
		<pubDate>Fri, 07 Mar 2014 03:26:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tordeu.com/?p=112#comment-6516</guid>
		<description><![CDATA[tell me to rename folder end with asd to space]]></description>
		<content:encoded><![CDATA[<p>tell me to rename folder end with asd to space</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: whatever</title>
		<link>http://blog.tordeu.com/?p=112#comment-4192</link>
		<dc:creator>whatever</dc:creator>
		<pubDate>Tue, 20 Aug 2013 18:25:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tordeu.com/?p=112#comment-4192</guid>
		<description><![CDATA[many thanks for this detailed and useful information on &#039;rename&#039; CMD!!
much appreciated documentation!]]></description>
		<content:encoded><![CDATA[<p>many thanks for this detailed and useful information on &#8216;rename&#8217; CMD!!<br />
much appreciated documentation!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tordeu</title>
		<link>http://blog.tordeu.com/?p=112#comment-1937</link>
		<dc:creator>tordeu</dc:creator>
		<pubDate>Thu, 25 Apr 2013 06:49:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tordeu.com/?p=112#comment-1937</guid>
		<description><![CDATA[You can create a small script like this:

&lt;code&gt;#!/bin/bash

basename=&quot;image&quot;

if [ $# -ne 1 ]; then
  echo &quot;usage: this script needs exactly 1 parameter&quot;
  exit 1
fi

if [ ! -d &quot;$1&quot; ]; then
  echo &quot;$1 is not a directory&quot;
  exit 1
fi

cd &quot;$1&quot;

i=1
for img in *.jpg; do
  mv -n &quot;$img&quot; $(printf &quot;$basename%d.jpg&quot; $i)
  let i=i+1
done
&lt;/code&gt;

Then you just call the script (let&#039;s imagine it is called script.sh) with the directory in which the images are; like this:

&lt;code&gt;./script.sh ~/images&lt;/code&gt;

But this script will be &quot;problematic&quot;, if you use it several times with the same directory, because then there are already files named &quot;image1.jpg&quot; etc. As it is the script will not overwrite existing files (because of the -n switch for mv), so data loss should not be a problem, but this could happen:

If you have the file &quot;a.jpg and image1.jpg&quot;, then it might try to rename a.jpg to image1.jpg. This won&#039;t be done, because image1.jpg already exists. Then it tries to rename image1.jpg to image2.jpg and you now have the files a.jpg and image2.jpg.

There are numerous ways to improve it, but it would depend on the situation and also on the desired workflow. You might find it working for you as it is. If not, just write back and I try to improve it.

EDIT: Just a tip: always make a backup before running new scripts like this! I tested it with a few empty files, but everytime I use a new script with real data, I make a backup before, because you can&#039;t back otherwise.]]></description>
		<content:encoded><![CDATA[<p>You can create a small script like this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/bin/bash<br />
<br />
basename=&quot;image&quot;<br />
<br />
if [ $# -ne 1 ]; then<br />
&nbsp; echo &quot;usage: this script needs exactly 1 parameter&quot;<br />
&nbsp; exit 1<br />
fi<br />
<br />
if [ ! -d &quot;$1&quot; ]; then<br />
&nbsp; echo &quot;$1 is not a directory&quot;<br />
&nbsp; exit 1<br />
fi<br />
<br />
cd &quot;$1&quot;<br />
<br />
i=1<br />
for img in *.jpg; do<br />
&nbsp; mv -n &quot;$img&quot; $(printf &quot;$basename%d.jpg&quot; $i)<br />
&nbsp; let i=i+1<br />
done</div></div>
<p>Then you just call the script (let&#8217;s imagine it is called script.sh) with the directory in which the images are; like this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">./script.sh ~/images</div></div>
<p>But this script will be &#8220;problematic&#8221;, if you use it several times with the same directory, because then there are already files named &#8220;image1.jpg&#8221; etc. As it is the script will not overwrite existing files (because of the -n switch for mv), so data loss should not be a problem, but this could happen:</p>
<p>If you have the file &#8220;a.jpg and image1.jpg&#8221;, then it might try to rename a.jpg to image1.jpg. This won&#8217;t be done, because image1.jpg already exists. Then it tries to rename image1.jpg to image2.jpg and you now have the files a.jpg and image2.jpg.</p>
<p>There are numerous ways to improve it, but it would depend on the situation and also on the desired workflow. You might find it working for you as it is. If not, just write back and I try to improve it.</p>
<p>EDIT: Just a tip: always make a backup before running new scripts like this! I tested it with a few empty files, but everytime I use a new script with real data, I make a backup before, because you can&#8217;t back otherwise.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tordeu</title>
		<link>http://blog.tordeu.com/?p=112#comment-1936</link>
		<dc:creator>tordeu</dc:creator>
		<pubDate>Thu, 25 Apr 2013 06:20:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tordeu.com/?p=112#comment-1936</guid>
		<description><![CDATA[Hi, 

The &quot;ren&quot; command? Are you on windows? In this case I can not help you, because I don&#039;t have windows myself and am not familiar with its command line.

In your case I would not use just rename (maybe I would not even use rename at all). If the files always have this format and are in a separate directory I would write a script and have it go into this directory and then do f=$(ls&#124;tail -1) and this would set f to the name of the file with the latest date. And then I would rename it.

But if the files are not in a separate directory or if the format changes, this would not necessarily work. And then it also depends on how the files should be renamed. If it should just be renamed as something fixed (like &quot;latest&quot; or &quot;foobar&quot;), I would not use rename, but mv instead.

If you are not on windows and provide me with some further information I might help you with a small script. If you are on windows, I might not be able to solve the problem, but I might be able to help you a little.

Hi, 

The &quot;ren&quot; command? Are you on windows? In this case I can not help you, because I don&#039;t have windows myself and am not familiar with its command line.

In your case I would not use just rename (maybe I would not even use rename at all). If the files always have this format and are in a separate directory I would write a script and have it go into this directory and then do f=$(ls&#124;tail -1) and this would set f to the name of the file with the latest date. And then I would rename it.

But if the files are not in a separate directory or if the format changes, this would not necessarily work. And then it also depends on how the files should be renamed. If it should just be renamed as something fixed (like &quot;latest&quot; or &quot;foobar&quot;), I would not use rename, but mv instead.

If you are not on windows and provide me with some further information I might help you with a small script. If you are on windows, I might not be able to solve the problem, but I might be able to help you a little.]]></description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>The &#8220;ren&#8221; command? Are you on windows? In this case I can not help you, because I don&#8217;t have windows myself and am not familiar with its command line.</p>
<p>In your case I would not use just rename (maybe I would not even use rename at all). If the files always have this format and are in a separate directory I would write a script and have it go into this directory and then do f=$(ls|tail -1) and this would set f to the name of the file with the latest date. And then I would rename it.</p>
<p>But if the files are not in a separate directory or if the format changes, this would not necessarily work. And then it also depends on how the files should be renamed. If it should just be renamed as something fixed (like &#8220;latest&#8221; or &#8220;foobar&#8221;), I would not use rename, but mv instead.</p>
<p>If you are not on windows and provide me with some further information I might help you with a small script. If you are on windows, I might not be able to solve the problem, but I might be able to help you a little.</p>
<p>Hi, </p>
<p>The &#8220;ren&#8221; command? Are you on windows? In this case I can not help you, because I don&#8217;t have windows myself and am not familiar with its command line.</p>
<p>In your case I would not use just rename (maybe I would not even use rename at all). If the files always have this format and are in a separate directory I would write a script and have it go into this directory and then do f=$(ls|tail -1) and this would set f to the name of the file with the latest date. And then I would rename it.</p>
<p>But if the files are not in a separate directory or if the format changes, this would not necessarily work. And then it also depends on how the files should be renamed. If it should just be renamed as something fixed (like &#8220;latest&#8221; or &#8220;foobar&#8221;), I would not use rename, but mv instead.</p>
<p>If you are not on windows and provide me with some further information I might help you with a small script. If you are on windows, I might not be able to solve the problem, but I might be able to help you a little.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amit</title>
		<link>http://blog.tordeu.com/?p=112#comment-1825</link>
		<dc:creator>Amit</dc:creator>
		<pubDate>Thu, 18 Apr 2013 16:07:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tordeu.com/?p=112#comment-1825</guid>
		<description><![CDATA[I have 100&#039;s of &quot;.jpg&quot; files with different names. I want to give all of them the same name followed by a number such as (image1.jpg, image2.jpg and so on). How can do this in linux.]]></description>
		<content:encoded><![CDATA[<p>I have 100&#8242;s of &#8220;.jpg&#8221; files with different names. I want to give all of them the same name followed by a number such as (image1.jpg, image2.jpg and so on). How can do this in linux.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Petar</title>
		<link>http://blog.tordeu.com/?p=112#comment-1779</link>
		<dc:creator>Petar</dc:creator>
		<pubDate>Sun, 14 Apr 2013 06:10:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tordeu.com/?p=112#comment-1779</guid>
		<description><![CDATA[Hello,

I have two files where the date varies. I would like renamed with the REN command only the latest. How can i do this if you can help me?

Z__C_EDZW_20130412000000_fax01,waf_swc_eur_000024_700150__EGRR.png
Z__C_EDZW_20130413000000_fax01,waf_swc_eur_000024_700150__EGRR.png

This file is last:  Z__C_EDZW_20130413000000*

Best regards,

Petar]]></description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I have two files where the date varies. I would like renamed with the REN command only the latest. How can i do this if you can help me?</p>
<p>Z__C_EDZW_20130412000000_fax01,waf_swc_eur_000024_700150__EGRR.png<br />
Z__C_EDZW_20130413000000_fax01,waf_swc_eur_000024_700150__EGRR.png</p>
<p>This file is last:  Z__C_EDZW_20130413000000*</p>
<p>Best regards,</p>
<p>Petar</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tordeu</title>
		<link>http://blog.tordeu.com/?p=112#comment-816</link>
		<dc:creator>tordeu</dc:creator>
		<pubDate>Tue, 01 Jan 2013 19:13:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tordeu.com/?p=112#comment-816</guid>
		<description><![CDATA[So, you have files like 475.jpg and 1928.jpg (for example) and you just want to add a prefix to get cf475.jpg and cf1928.jpg, for example?

This is covered as Example 4 in the article, but I noticed that the formatting in the article was off, so you probably did not notice Example 4. I corrected that. But you can make this more convenient by creating a small script (i called this add-prefix.sh):
&lt;code&gt;
#!/bin/bash

TEST=0
if [[ $1 == &#039;-n&#039; ]]; then
        TEST=1
fi
PREFIX=$1
shift
if [[ $TEST == 1 ]]; then
        echo &quot;just testing&quot;
        rename -n &#039;s/(.*)/&#039;$PREFIX&#039;$1/&#039; &quot;$@&quot;
else
        rename &#039;s/(.*)/&#039;$PREFIX&#039;$1/&#039; &quot;$@&quot;
fi
&lt;/code&gt;

you can then call
&lt;code&gt;add-prefix.sh &lt;prefix&gt; &lt;files&gt;&lt;/code&gt;
to add a prefix to files. To add &quot;cf&quot; to all jpgs in the current directory, you would call
&lt;code&gt;add-prefix.sh cf *.jpg&lt;/code&gt;

You might want to test if what you are about to do is correct. So the best way is to backup all files, then rename them and if anything goes wrong you still have your backup. The script also allows testing. Just add &quot;-n&quot; as the first option and the script will not actually rename anything, but instead tell you what would be renamed. To test the above renaming, run:
&lt;code&gt;add-prefix.sh -n cf *.jpg&lt;/code&gt;

And be careful, because making a mistake when batch renaming can be a real pain (hence my backup suggestion).

I hope this is what you asked for. Please feel free to get back to me in case you need further help or I somehow misunderstood what you wanted to do.]]></description>
		<content:encoded><![CDATA[<p>So, you have files like 475.jpg and 1928.jpg (for example) and you just want to add a prefix to get cf475.jpg and cf1928.jpg, for example?</p>
<p>This is covered as Example 4 in the article, but I noticed that the formatting in the article was off, so you probably did not notice Example 4. I corrected that. But you can make this more convenient by creating a small script (i called this add-prefix.sh):</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/bin/bash<br />
<br />
TEST=0<br />
if [[ $1 == '-n' ]]; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; TEST=1<br />
fi<br />
PREFIX=$1<br />
shift<br />
if [[ $TEST == 1 ]]; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;just testing&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; rename -n 's/(.*)/'$PREFIX'$1/' &quot;$@&quot;<br />
else<br />
&nbsp; &nbsp; &nbsp; &nbsp; rename 's/(.*)/'$PREFIX'$1/' &quot;$@&quot;<br />
fi</div></div>
<p>you can then call</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">add-prefix.sh &lt;prefix&gt; &lt;files&gt;</div></div>
<p>to add a prefix to files. To add &#8220;cf&#8221; to all jpgs in the current directory, you would call</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">add-prefix.sh cf *.jpg</div></div>
<p>You might want to test if what you are about to do is correct. So the best way is to backup all files, then rename them and if anything goes wrong you still have your backup. The script also allows testing. Just add &#8220;-n&#8221; as the first option and the script will not actually rename anything, but instead tell you what would be renamed. To test the above renaming, run:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">add-prefix.sh -n cf *.jpg</div></div>
<p>And be careful, because making a mistake when batch renaming can be a real pain (hence my backup suggestion).</p>
<p>I hope this is what you asked for. Please feel free to get back to me in case you need further help or I somehow misunderstood what you wanted to do.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joyce</title>
		<link>http://blog.tordeu.com/?p=112#comment-813</link>
		<dc:creator>Joyce</dc:creator>
		<pubDate>Tue, 01 Jan 2013 16:12:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tordeu.com/?p=112#comment-813</guid>
		<description><![CDATA[I need to know how to add a prefix to a batch of jpg images...
The images are titled with sku numbers or numbers and letters, which MUST remain the same, but I need to add a prefix to them, such as cf or CF denoting the manufacturer, so as not to confuse just numbers that may match with other manufacturer&#039;s numbers.
I have only seen prefixes added and then the image sku or name gets changed to a sequential number 1 through the amount of items in the batch, such as 1,2,3,4 ... with the prefix added, which is NOT helpful.
Can you assist me with this ASAP and as simple as possible, since I only know what I happen to discover... I am not computer or soft ware savvy!
THANKS!
Joyce]]></description>
		<content:encoded><![CDATA[<p>I need to know how to add a prefix to a batch of jpg images&#8230;<br />
The images are titled with sku numbers or numbers and letters, which MUST remain the same, but I need to add a prefix to them, such as cf or CF denoting the manufacturer, so as not to confuse just numbers that may match with other manufacturer&#8217;s numbers.<br />
I have only seen prefixes added and then the image sku or name gets changed to a sequential number 1 through the amount of items in the batch, such as 1,2,3,4 &#8230; with the prefix added, which is NOT helpful.<br />
Can you assist me with this ASAP and as simple as possible, since I only know what I happen to discover&#8230; I am not computer or soft ware savvy!<br />
THANKS!<br />
Joyce</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tordeu</title>
		<link>http://blog.tordeu.com/?p=112#comment-236</link>
		<dc:creator>tordeu</dc:creator>
		<pubDate>Tue, 22 May 2012 10:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tordeu.com/?p=112#comment-236</guid>
		<description><![CDATA[In this case, you can add a &#039;g&#039; after the last slash in the pattern. This will make sure that all matches are replaced and not just the first one (which is the default behavior):

rename &#039;s/foo/bar/g&#039; *]]></description>
		<content:encoded><![CDATA[<p>In this case, you can add a &#8216;g&#8217; after the last slash in the pattern. This will make sure that all matches are replaced and not just the first one (which is the default behavior):</p>
<p>rename &#8216;s/foo/bar/g&#8217; *</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haritha</title>
		<link>http://blog.tordeu.com/?p=112#comment-234</link>
		<dc:creator>Haritha</dc:creator>
		<pubDate>Tue, 22 May 2012 03:37:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tordeu.com/?p=112#comment-234</guid>
		<description><![CDATA[Thanks for the prompt reply and examples. Also, how to make rename work for more than one pattern match? Suppose I have to replace &quot;foo&quot; in a file name with &quot;bar&quot; for all files in folder. I can use the command: rename  &#039;s/foo/bar/&#039; *

But, if I have a file like foo foo.txt, it is getting renamed to bar foo.txt, not bar bar.txt. How to achieve desired result. Thanks in advance.]]></description>
		<content:encoded><![CDATA[<p>Thanks for the prompt reply and examples. Also, how to make rename work for more than one pattern match? Suppose I have to replace &#8220;foo&#8221; in a file name with &#8220;bar&#8221; for all files in folder. I can use the command: rename  &#8216;s/foo/bar/&#8217; *</p>
<p>But, if I have a file like foo foo.txt, it is getting renamed to bar foo.txt, not bar bar.txt. How to achieve desired result. Thanks in advance.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
