Geek Pop Quiz!
Nov. 24th, 2009 12:28 pmA bunch of folders have been created with a " in the name. A literal quotation mark. Often two.
I want to find and remove the " characters, leaving the rest of the folder intact.
Problem is, find /path -name *\"* doesn't find 'em - it seems that escaping the " is a little more complicated than I'd thought.
What am I missing?
EDIT: A-hah!
What I really wanted was -name '*["]*'
Now, I kind of want -exec mv {} `echo {}|sed 's/[^A-Za-z,.# ()0-9-]/_/g'` \;
I wonder if that will work.
EDIT2: Plan B! The "find" shows me that there are a mere 9 entries, all of which are empty and trivially recreatable. -exec rm -r {} \; it is!
I want to find and remove the " characters, leaving the rest of the folder intact.
Problem is, find /path -name *\"* doesn't find 'em - it seems that escaping the " is a little more complicated than I'd thought.
What am I missing?
EDIT: A-hah!
What I really wanted was -name '*["]*'
Now, I kind of want -exec mv {} `echo {}|sed 's/[^A-Za-z,.# ()0-9-]/_/g'` \;
I wonder if that will work.
EDIT2: Plan B! The "find" shows me that there are a mere 9 entries, all of which are empty and trivially recreatable. -exec rm -r {} \; it is!
(no subject)
Date: 2009-11-24 05:36 pm (UTC)% find /path -type d -print | grep '"' | awk '{nfile=$0;ofile=$0;gsub("\"","",nfile);print "mv \"" ofile "\" \"" nfile "\"";}' | sh -x
Typed from memory, should be close to working. :-) This will NOT deal with file name conflicts if there are any after removing the double quotes.
(no subject)
Date: 2009-11-24 06:19 pm (UTC)(no subject)
Date: 2009-11-24 07:52 pm (UTC)(no subject)
Date: 2009-11-24 08:15 pm (UTC)Empty ones are not the problem.
(My handy dandy script to run on one of the websites to search and destroy all directories named ".svn" was much more useful. Dumbasses! You cannot just upload your SVN checkout! If we wanted to do that, you would be checking *into* the repository and the WEB SERVER would be checking it out, not getting it via FTP! Gah!)
(no subject)
Date: 2009-11-24 09:02 pm (UTC)Problem is with the asterisks - which the shell, per design, expands before really running the command. To prevent that, always escape the asterisks if you want them being handed over to the program you run.
Situation:
tcsh:
bash: