theweaselking: (Work now)
[personal profile] theweaselking
A 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!

(no subject)

Date: 2009-11-24 05:36 pm (UTC)
From: [identity profile] dukehyena.livejournal.com
While not a solution to having 'find' find the files, this should do the trick:

% 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)
From: [identity profile] theweaselking.livejournal.com
I'm not worried about file conflicts. But thanks!

(no subject)

Date: 2009-11-24 07:52 pm (UTC)
From: [identity profile] anivair.livejournal.com
Speaking of empty folders, I headed off a nearly upsetting issue at work with one employee trying to "helpfully" run a program that would delete all empty folders on a system. On a windows machine that might not be bad, but I need some of those empty folders. Fortunately he didn't really understand how to make the program run, so I caught it. Good stuff.

(no subject)

Date: 2009-11-24 08:15 pm (UTC)
From: [identity profile] theweaselking.livejournal.com
... why would you wipe out *empty* folders?

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)
From: [identity profile] rbarclay.livejournal.com
Assuming an up-to-date Leegnux, and bash, your first attempt was nearly correct. And with some versions of bash it'd even have worked (I know it didn't a couple years ago when I first ran into this type of problem).

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:
fsck:~> ls -1 /tmp/ | egrep \"
"
1"2


tcsh:
fsck:~> find /tmp/ -name *\"*
find: No match.
fsck:~> find /tmp/ -name \*\"\*
/tmp/1"2
/tmp/"


bash:
fsck:~> bash
waldner@fsck->~ $ find /tmp/ -name *\"*
/tmp/1"2
/tmp/"
waldner@fsck->~ $ find /tmp/ -name \*\"\*
/tmp/1"2
/tmp/"

Profile

theweaselking: (Default)theweaselking
Page generated Mar. 10th, 2026 07:41 pm