<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SavvyAdmin.com &#187; Rename</title>
	<atom:link href="http://savvyadmin.com/tag/rename/feed/" rel="self" type="application/rss+xml" />
	<link>http://savvyadmin.com</link>
	<description>For savvy admins everywhere...</description>
	<lastBuildDate>Fri, 21 Jan 2011 17:53:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Rename Files in Bulk from the Command Line</title>
		<link>http://savvyadmin.com/rename-files-in-bulk-from-the-command-line/</link>
		<comments>http://savvyadmin.com/rename-files-in-bulk-from-the-command-line/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 01:22:27 +0000</pubDate>
		<dc:creator>gmendoza</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rename]]></category>

		<guid isPermaLink="false">http://www.savvyadmin.com/?p=59</guid>
		<description><![CDATA[Renaming a large number of files can seem like a daunting task, but no worries, your trusty Linux CLI is at your service. For this example, we will rename a number of MP3&#8242;s located in multiple subdirectories with a couple very easy commands; &#8220;find&#8221; and &#8220;rename&#8221;. By listing the following directory, you&#8217;ll see that the [...]
Related posts:<ol>
<li><a href='http://savvyadmin.com/vim-in-color/' rel='bookmark' title='Vim in Color'>Vim in Color</a></li>
<li><a href='http://savvyadmin.com/split-and-reassemble-files/' rel='bookmark' title='Split and Reassemble Files'>Split and Reassemble Files</a></li>
<li><a href='http://savvyadmin.com/line-wrapping-text-made-easy-with-fold/' rel='bookmark' title='Line wrapping text made easy with fold'>Line wrapping text made easy with fold</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Renaming a large number of files can seem like a daunting task, but no worries, your trusty Linux CLI is at your service.  For this example, we will rename a number of MP3&#8242;s located in multiple subdirectories with a couple very easy commands; &#8220;find&#8221; and &#8220;rename&#8221;.</p>
<p>By listing the following directory, you&#8217;ll see that the MP3&#8242;s have been named with &#8220;(LP Version)&#8221;, and of course I don&#8217;t like this naming convention.</p>
<blockquote><p><code><strong>cd ~/Music/Metallica/Metallica/<br />
ls -1</strong><br />
01 - Enter Sandman (LP Version).mp3<br />
02 - Sad But True (LP Version).mp3<br />
03 - Holier Than Thou (LP Version).mp3<br />
04 - The Unforgiven (LP Version).mp3<br />
05 - Wherever I May Roam (LP Version).mp3<br />
06 - Don't Tread On Me (LP Version).mp3<br />
07 - Through The Never (LP Version).mp3<br />
08 - Nothing Else Matters (LP Version).mp3<br />
09 - Of Wolf And Man (LP Version).mp3<br />
10 - The God That Failed (LP Version).mp3<br />
11 - My Friend Of Misery (LP Version).mp3<br />
12 - The Struggle Within (LP Version).mp3</code></p></blockquote>
<p>We&#8217;ll use the &#8220;rename&#8221; command to search for and delete the string &#8221; (LP Version)&#8221; in any of the mp3 file names.</p>
<p>Syntax:</p>
<blockquote><p><code><strong>rename (search command) (files)<br />
rename 's/search_for_string/replace_string_with_this/' files</strong></code></p></blockquote>
<p>To delete the matching string, simply leave the replace area empty like so:</p>
<blockquote><p><code><strong>rename 's/search_for_string//' files</strong></code></p></blockquote>
<p>Our Example:</p>
<blockquote><p><code><strong>rename 's/ \(LP Version\)//' *.mp3</strong></code></p></blockquote>
<p>Notice, the left and right parentheses need to be preceded with a backslash &#8220;\&#8221; character, although the spaces do not.  The backslash is a metacharacter used to give you control over what your are matching against.  For more info, here&#8217;s a <a title="Linux.com - CLI Magic" href="http://www.linux.com/feature/114045" target="_blank">link to a decent tutorial</a> on the matter.</p>
<p>You can see the results of the command below.</p>
<blockquote><p><code><strong>ls -1</strong><br />
01 - Enter Sandman.mp3<br />
02 - Sad But True.mp3<br />
03 - Holier Than Thou.mp3<br />
04 - The Unforgiven.mp3<br />
05 - Wherever I May Roam.mp3<br />
06 - Don't Tread On Me.mp3<br />
07 - Through The Never.mp3<br />
08 - Nothing Else Matters.mp3<br />
09 - Of Wolf And Man.mp3<br />
10 - The God That Failed.mp3<br />
11 - My Friend Of Misery.mp3<br />
12 - The Struggle Within.mp3</code></p></blockquote>
<p>Now, to rename a large number of files spanning multiple directories, simply combine &#8220;rename&#8221; with the power of the &#8220;find&#8221; command.</p>
<p>Syntax:</p>
<blockquote><p><code><strong>find . -type f -name *.mp3 -exec rename 's/ \(LP Version\)//' '{}' \;</strong></code></p></blockquote>
<p>In this example, we searched starting from the current directory for only files with .mp3 in their file names.  We use the find command&#8217;s -exec option to execute the rename command against the result set.  See the find(1) manpage for more info.</p>
<p>Other useful examples:</p>
<blockquote><p><code>Replace all spaces with underscores.<br />
<strong>rename 's/ /\_/g' *.mp3</strong></code></p>
<p><code>Replace all uppercase with lowercase characters<br />
<strong>rename 'y/[A-Z]/[a-z]/' *.mp3</strong></code></p></blockquote>
<p>Easy stuff, and you don&#8217;t even need any fancy GUI applications to do the job!</p>
<p>Related posts:<ol>
<li><a href='http://savvyadmin.com/vim-in-color/' rel='bookmark' title='Vim in Color'>Vim in Color</a></li>
<li><a href='http://savvyadmin.com/split-and-reassemble-files/' rel='bookmark' title='Split and Reassemble Files'>Split and Reassemble Files</a></li>
<li><a href='http://savvyadmin.com/line-wrapping-text-made-easy-with-fold/' rel='bookmark' title='Line wrapping text made easy with fold'>Line wrapping text made easy with fold</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://savvyadmin.com/rename-files-in-bulk-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

