<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: How to go from "this_" to "this" ?</title>
	<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this/</link>
	<description>Comments on Ask MetaFilter post How to go from "this_" to "this" ?</description>
	<pubDate>Thu, 23 Mar 2006 09:01:38 -0800</pubDate>
	<lastBuildDate>Thu, 23 Mar 2006 09:01:38 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: How to go from &quot;this_&quot; to &quot;this&quot; ?</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this</link>	
		<description>Batch unzipping and file renaming on UNIX or OS X? All_ my_ files_ look_ like_ this!_.gz &lt;br /&gt;&lt;br /&gt; I recently lost all files on one of my domains, but was able to recover everything from my server&apos;s backup.  However, all the files now have an underscore appended to the end of the filename (&lt;em&gt;index.html&lt;/em&gt; is now &lt;em&gt;index.html_&lt;/em&gt;, for example).  All the files and all the folders are like this.  &lt;br&gt;
&lt;br&gt;
And some of them are gzipped, so some files are now &lt;em&gt;filename.cgi_.gz&lt;/em&gt;.&lt;br&gt;
&lt;br&gt;
What&apos;s the quickest, easiest way to unzip everything and remove the _ from the end of the files, including those within nested folders?  Is there a shell command I can use? (or a way to do this using Automator on OS X if I copy everything from my server to my computer?)</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2006:site.34947</guid>
		<pubDate>Thu, 23 Mar 2006 08:59:45 -0800</pubDate>
		<dc:creator>Robot Johnny</dc:creator>
		
			<category>mac</category>
		
			<category>osx</category>
		
			<category>unix</category>
		
			<category>rename</category>
		
			<category>file</category>
		
			<category>gzip</category>
		
			<category>unzip</category>
		
			<category>zip</category>
		
			<category>batch</category>
		
			<category>server</category>
		
			<category>backup</category>
		
	</item> <item>
		<title>By: Malor</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544537</link>	
		<description>In Windows, that _ extension can mean the file is compressed.  Are they the undamaged files, you just need to rename them?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544537</guid>
		<pubDate>Thu, 23 Mar 2006 09:01:38 -0800</pubDate>
		<dc:creator>Malor</dc:creator>
	</item><item>
		<title>By: Robot Johnny</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544542</link>	
		<description>Yeah, they just need renaming... they are otherwise exact copies.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544542</guid>
		<pubDate>Thu, 23 Mar 2006 09:04:10 -0800</pubDate>
		<dc:creator>Robot Johnny</dc:creator>
	</item><item>
		<title>By: zsazsa</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544551</link>	
		<description>&quot;&lt;tt&gt;gunzip *gz&lt;/tt&gt;&quot; will ungzip everything.&lt;br&gt;
&lt;br&gt;
&quot;&lt;tt&gt;rename &apos;s/_$//&apos; *&lt;/tt&gt;&quot; will remove the _ from all of the files.  &lt;tt&gt;rename&lt;/tt&gt; may not be on OSX, it&apos;s a fairly standard part of Linux at least.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544551</guid>
		<pubDate>Thu, 23 Mar 2006 09:09:46 -0800</pubDate>
		<dc:creator>zsazsa</dc:creator>
	</item><item>
		<title>By: Robot Johnny</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544552</link>	
		<description>Thanks zsazsa, but will that remove only the _ on the end of the filename? Or every occurance of _?  (Some of my files have a _ elsewhere in the filename that I obviously want to keep)&lt;br&gt;
&lt;br&gt;
Also, will these commands apply to files within nested folders?  Or will I have to go into each folder and repeat the command?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544552</guid>
		<pubDate>Thu, 23 Mar 2006 09:13:38 -0800</pubDate>
		<dc:creator>Robot Johnny</dc:creator>
	</item><item>
		<title>By: leftoverboy</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544555</link>	
		<description>If you have menu scripts turned on there is a script&lt;br&gt;
Finder Scripts &amp;gt; Replace Text in Item Names&lt;br&gt;
&lt;br&gt;
The script opens a little dialog box that allows you to replace &apos;_&apos; with &apos; &apos;. &lt;br&gt;
&lt;br&gt;
If you don&apos;t have menu scripts on you should, there are lots of useful actions available.  Spotlight &apos;Applescript Utility&apos; Open it and click the check boxes &apos;Show Script Menu in menu bar&apos; and &apos;Show Library scripts&apos;&lt;br&gt;
&lt;br&gt;
Like your sites, glad to pay you back for the entertainment.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544555</guid>
		<pubDate>Thu, 23 Mar 2006 09:16:03 -0800</pubDate>
		<dc:creator>leftoverboy</dc:creator>
	</item><item>
		<title>By: leftoverboy</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544559</link>	
		<description>Doh! Just say preview.  To only grab the end under score find and replace  &apos;_.&quot; with &apos;.&apos; and you will get only the ones at the end,</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544559</guid>
		<pubDate>Thu, 23 Mar 2006 09:17:40 -0800</pubDate>
		<dc:creator>leftoverboy</dc:creator>
	</item><item>
		<title>By: zsazsa</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544562</link>	
		<description>Oops. I didn&apos;t see the recursive argument.&lt;br&gt;
&lt;br&gt;
&quot;&lt;tt&gt;gunzip -r .&lt;/tt&gt;&quot;  for the ungzipping...&lt;br&gt;
&lt;br&gt;
&quot;&lt;tt&gt;find -exec rename &apos;s/_$//&apos; {} \;&lt;/tt&gt;&quot; should do it.&lt;br&gt;
&lt;br&gt;
Yes, that will only remove a _ on the end of a filename. A &apos;$&apos; in a regular expression means &quot;end of a line/string&quot;, so it will only match underscores on the ends of filenames.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544562</guid>
		<pubDate>Thu, 23 Mar 2006 09:18:18 -0800</pubDate>
		<dc:creator>zsazsa</dc:creator>
	</item><item>
		<title>By: zsazsa</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544566</link>	
		<description>(By recursive, I mean it&apos;ll work in nested folders.)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544566</guid>
		<pubDate>Thu, 23 Mar 2006 09:19:33 -0800</pubDate>
		<dc:creator>zsazsa</dc:creator>
	</item><item>
		<title>By: zsazsa</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544579</link>	
		<description>(If &lt;tt&gt;rename&lt;/tt&gt; doesn&apos;t come with macos, you can put &lt;a href=&quot;http://www.scs.fsu.edu/~burkardt/pl_src/rename/rename.perl&quot;&gt;this script&lt;/a&gt; in the dir you want and do:&lt;br&gt;
&lt;br&gt;
&quot;&lt;tt&gt;find . -exec perl rename.perl &apos;s/_$//&apos; {} \;&lt;/tt&gt;&quot;&lt;br&gt;
&lt;br&gt;
Or if you&apos;d rather not hassle with this Unix arcanery, leftoverboy&apos;s way looks fine.&lt;br&gt;
&lt;br&gt;
(I added a &apos;.&apos; to the find command because some finds are different and need it, and I don&apos;t have access to a Mac right now to see if that&apos;s the case.  It doesn&apos;t hurt to use it.)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544579</guid>
		<pubDate>Thu, 23 Mar 2006 09:31:11 -0800</pubDate>
		<dc:creator>zsazsa</dc:creator>
	</item><item>
		<title>By: Malor</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544588</link>	
		<description>If all else fails, here is a short batch script that should work.  MAKE SURE you run this ONLY on a backup of the files.  I have only tested this with Linux.  It will recurse directories and seems fine, but I have not tested this extensively. &lt;br&gt;
&lt;br&gt;
&lt;code&gt;&lt;br&gt;
!/bin/sh&lt;br&gt;
# first, set the word break to be newline only.&lt;br&gt;
# This is easier for dealing with filenames.&lt;br&gt;
IFS=$&apos;\n&apos;&lt;br&gt;
&lt;br&gt;
# Do a search for all _ files, and then pipe that result&lt;br&gt;
# through sed...stripping away the _&lt;br&gt;
&lt;br&gt;
for i in `find . -name &quot;*_&quot;  | sed -e s/\_$//`; do&lt;br&gt;
  mv $i\_ $i&lt;br&gt;
done&lt;br&gt;
&lt;/code&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544588</guid>
		<pubDate>Thu, 23 Mar 2006 09:35:10 -0800</pubDate>
		<dc:creator>Malor</dc:creator>
	</item><item>
		<title>By: nicwolff</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544590</link>	
		<description>There&apos;s no &quot;rename&quot; in OS X. Try&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;find / -name &apos;*_&apos; -print0 | perl -n0e &apos;$old = $_; chop; chop; rename $old, $_;&apos;&lt;br&gt;
&amp;nbsp;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544590</guid>
		<pubDate>Thu, 23 Mar 2006 09:36:05 -0800</pubDate>
		<dc:creator>nicwolff</dc:creator>
	</item><item>
		<title>By: nicwolff</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544594</link>	
		<description>Definitely use -print0 by the way, file names on the Mac often contain spaces.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544594</guid>
		<pubDate>Thu, 23 Mar 2006 09:37:33 -0800</pubDate>
		<dc:creator>nicwolff</dc:creator>
	</item><item>
		<title>By: Malor</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544599</link>	
		<description>A bit more documentation... that recurses through your directories and generates a list of files ending with _.  It strips the _ by piping the result through sed. &lt;br&gt;
&lt;br&gt;
Then, for each line, it does: &lt;br&gt;
&lt;br&gt;
mv filename_ filename&lt;br&gt;
&lt;br&gt;
The perl renamer may be fine too... but I don&apos;t know if it will handle spaces properly.  My shell script will... that&apos;s what the IFS command does.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544599</guid>
		<pubDate>Thu, 23 Mar 2006 09:40:05 -0800</pubDate>
		<dc:creator>Malor</dc:creator>
	</item><item>
		<title>By: Robot Johnny</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544629</link>	
		<description>Thanks everyone.&lt;br&gt;
&lt;br&gt;
zsazsa, the unzipping worked, but like others stated, &quot;rename&quot; doesn&apos;t work&lt;br&gt;
&lt;br&gt;
nicwolff, I tried using your method, but it started to search my entire computer so I had to terminate it... how do I limit it to my current directory (and its recursive directories?)&lt;br&gt;
&lt;br&gt;
Malor, if I use your method, how do I run a batch script?  (I&apos;m new to fiddling around in OS X&apos;s terminal)&lt;br&gt;
&lt;br&gt;
Also, I&apos;m not limited to OS X&apos;s Terminal... the files also exist on my Dreamhost server, so any commands that work on their Unix servers are welcome, too.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544629</guid>
		<pubDate>Thu, 23 Mar 2006 10:01:54 -0800</pubDate>
		<dc:creator>Robot Johnny</dc:creator>
	</item><item>
		<title>By: nicwolff</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544638</link>	
		<description>Oh, sorry, you said &quot;everything&quot; so I figured you wanted to do the whole filesystem. Just change the &quot;/&quot; to a &quot;.&quot; to do only the current directory and its subdirectories:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;find . -name &apos;*_&apos; -print0 | perl -n0e &apos;$old = $_; chop; chop; rename $old, $_;&apos;&lt;br&gt;
&amp;nbsp;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544638</guid>
		<pubDate>Thu, 23 Mar 2006 10:06:46 -0800</pubDate>
		<dc:creator>nicwolff</dc:creator>
	</item><item>
		<title>By: nicwolff</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544640</link>	
		<description>And that&apos;ll work fine on any UNIX that has Perl installed.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544640</guid>
		<pubDate>Thu, 23 Mar 2006 10:07:20 -0800</pubDate>
		<dc:creator>nicwolff</dc:creator>
	</item><item>
		<title>By: Robot Johnny</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544644</link>	
		<description>Thanks nicwolff!&lt;br&gt;
Sorry to keep being a nitpicker, but that totally worked for the main directory, but did nothing to the files in its subdirectories.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544644</guid>
		<pubDate>Thu, 23 Mar 2006 10:13:00 -0800</pubDate>
		<dc:creator>Robot Johnny</dc:creator>
	</item><item>
		<title>By: Malor</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544650</link>	
		<description>Robot johnny:  use Text Editor to create a new file, fixfiles.sh, in your home directory.  (that&apos;s the easy place to find it.)  Copy that script in, verbatim.  Save it. &lt;br&gt;
&lt;br&gt;
Then open a terminal.  cd to the directory you stored your backups in.  (make sure it&apos;s not the only copy you have!).  Run the script with ~/fixfiles.sh.  It searches from the current directory down for _ files.&lt;br&gt;
&lt;br&gt;
If for some weird reason you plan to run it a lot, let me know and I&apos;ll tell you how to install it semi-permanently.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544650</guid>
		<pubDate>Thu, 23 Mar 2006 10:18:28 -0800</pubDate>
		<dc:creator>Malor</dc:creator>
	</item><item>
		<title>By: Malor</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544651</link>	
		<description>Crap!  Run the script with:&lt;br&gt;
&lt;br&gt;
&lt;code&gt;sh ~/fixfiles.sh&lt;/code&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544651</guid>
		<pubDate>Thu, 23 Mar 2006 10:19:27 -0800</pubDate>
		<dc:creator>Malor</dc:creator>
	</item><item>
		<title>By: nicwolff</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544658</link>	
		<description>Something else is wrong then; that should work. Does&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;find . -name &apos;*_&apos; -print&lt;br&gt;
&lt;br&gt;
give you a list of the files in the subdirectories?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544658</guid>
		<pubDate>Thu, 23 Mar 2006 10:26:26 -0800</pubDate>
		<dc:creator>nicwolff</dc:creator>
	</item><item>
		<title>By: Robot Johnny</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544670</link>	
		<description>Thanks, Malor!  Worked like a charm.&lt;br&gt;
&lt;br&gt;
A slight problem though: as the script renamed subdirectories ending in _, it spat out error messages that files within those directories couldn&apos;t be found (I assume because the name had been changed in mid-script).&lt;br&gt;
&lt;br&gt;
So I just repeated the script until there were no more error messages.&lt;br&gt;
&lt;br&gt;
Everyone here helped in some way, so time to hand out the &quot;best answers&quot;.  Thanks so much!&lt;br&gt;
&lt;br&gt;
On preview: Yes, nicwolff, just checked on a backup copy of the offending files and that command does list all the files.  Don&apos;t know why the renaming didn&apos;t work.  Thanks for your help!</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544670</guid>
		<pubDate>Thu, 23 Mar 2006 10:31:53 -0800</pubDate>
		<dc:creator>Robot Johnny</dc:creator>
	</item><item>
		<title>By: Robot Johnny</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544674</link>	
		<description>Oh, and thanks leftoverboy, too, but your method wouldn&apos;t work because the _ came &lt;em&gt;after&lt;/em&gt; the extension (ie hello.jpg_)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544674</guid>
		<pubDate>Thu, 23 Mar 2006 10:34:26 -0800</pubDate>
		<dc:creator>Robot Johnny</dc:creator>
	</item><item>
		<title>By: Malor</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544685</link>	
		<description>Robot, I ALMOST posted back with that explicit instruction... I realized that might happen.  But I didn&apos;t want to make it sound overcomplex, and I was having trouble explaining it simply.  I&apos;m glad you figured it out. :)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544685</guid>
		<pubDate>Thu, 23 Mar 2006 10:48:51 -0800</pubDate>
		<dc:creator>Malor</dc:creator>
	</item><item>
		<title>By: aberrant</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544758</link>	
		<description>Um, you might want to consider quoting the filename variables in those examples - if the files have spaces in them, then you&apos;re going to get into IFS problems.  (I learned this the hard way).  For example, the&lt;br&gt;
&lt;br&gt;
 mv $i\_ $i&lt;br&gt;
&lt;br&gt;
in Malor&apos;s example should be&lt;br&gt;
&lt;br&gt;
 mv &quot;$i\_&quot; &quot;$i&quot;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544758</guid>
		<pubDate>Thu, 23 Mar 2006 11:56:47 -0800</pubDate>
		<dc:creator>aberrant</dc:creator>
	</item><item>
		<title>By: Malor</title>
		<link>http://ask.metafilter.com/34947/How-to-go-from-this-to-this#544823</link>	
		<description>aberrant, it worked perfectly in my testing with filenames with spaces.  &lt;br&gt;
&lt;br&gt;
By setting IFS to newline only, and having newlines embedded in the filename, it seems to work without needing the quotes.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34947-544823</guid>
		<pubDate>Thu, 23 Mar 2006 13:34:44 -0800</pubDate>
		<dc:creator>Malor</dc:creator>
	</item>
	</channel>
</rss>
