Date: Thu, 19 Sep 2002 07:57:21 -0400 From: "Brian T. Schellenberger" <bts@babbleon.org> To: Peter Leftwich <Hostmaster@Video2Video.Com>, FreeBSD LIST <FreeBSD-Questions@freebsd.org> Subject: Re: find case-insensitive challenge Message-ID: <200209190757.22640.bts@babbleon.org> In-Reply-To: <20020919013548.H83658-100000@earl-grey.cloud9.net> References: <20020919013548.H83658-100000@earl-grey.cloud9.net>
next in thread | previous in thread | raw e-mail | index | archive | help
--------------Boundary-00=_L7POY5N4J9GXWY9SX6KQ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit On Thursday 19 September 2002 01:38 am, Peter Leftwich wrote: | Tonight I surprised myself by running `find ~/Desktop/folder/ -name | "*.jpg" -exec mv {} ~/Desktop/folderjpgs/ \;` successfully! My first | custom find command line ever. | | But there were two issues -- I had to escape the semicolon with a "\" Yes, it always works that way. | -- does this ever cause problems for find command lines? No, not really. | Second, | this found only *.jpg files and left behind *.JPG files so how do you | make find be case-insensitive? find ~/Desktop/folder/ \( -name "*.jpg" -o -name "*.JPG" \) \ -exec mv {} ~/Desktop/folderjpgs/ \; Actually, what *I* do is avoid having files with capital letters in them, or spaces, or &'s, or any of those other goofy characters you sometimes find in Windows file names. Then I don't have to do the above. I accomplish that with the attached pair of scripts, though there are no doubts lots of other nice ways to do this. (I run the "unmsdos" script over files that I download from the web or newsgroups or what-have-you. It makes all of file names "Unix-friendly" and, if the file is a text file, it invokes uncrnl to change the cr-nl's at the ends of lines into just plan nl's.) | -exec ThankYouScript.sh {} \; -- Brian, the man from Babble-On . . . . bts@babbleon.org (personal) --------------Boundary-00=_L7POY5N4J9GXWY9SX6KQ Content-Type: application/x-perl; name="unmsdos" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="unmsdos" #! /usr/bin/perl # # By Brian T. Schellenberger (bts@babbleon.org) # Please maintain this credit but otherwise, use as you see fit. # (If it gets substantially transmorgified, it would probably be # best to just say "based on . . . " # if ($ARGV[0] eq '-c') # Special CD-ROM mode { $cdrom = 1; } if ($ARGV[0] eq '-n') { shift; $putname = 1; } foreach (@ARGV) { # unmsdos accpets a "quoting" convention of angle-brackets to # quote names. If it has 'em, strip 'em. If it has the leading, # but not the trailing, bracket then save this one and come # around again. First see if we are continued from before. if ($pending) { $_ = $pending . ' ' .$_; $pending = ""; } if (/^</) { if (/>$/) { s/^<//; s/>$//; } else { $pending = $_; next; } } $path = $_; $path = "." if (! /\//); $path =~ s|/[^/]*$||; s|^.*/||; $newname = $_; if ($cdrom) { next if (length > 12 || /[a-z]/); # 12 = 8.3 (12345678.ABC) goto justLowercase; } # If it's one of my "rated" names, seperate out the rating part. # Always take out leading paths for file renames. $prefix = ""; if (/^(.*\/)?(\w+-\w+-\w+:)?/) { $prefix = $&; $_ = $'; } # name conversions. $newname =~ tr/\x80-\xFF/\x00-\x7F/; $newname =~ s/[\x00- ]/_/g; $newname =~ s/[[\]]/_/g; $newname =~ s/\&/+/g; $newname =~ s/\s/_/g; $newname =~ s/^~/_/g; $newname =~ s/^\+/p_/g; $newname =~ s/([^.])~/$1-/g; $newname =~ s/;/@/g; $newname =~ s/[ `'"!&*$;]/_/g; $newname =~ s/\$/_/g; $newname =~ s/[:{}|()<>]/-/g; $newname =~ s/^-/_/; $newname =~ s/\?/q/g; $newname =~ s/#/=/g; $newname =~ s/\\/_/g; justLowercase: $newname =~ tr/A-Z/a-z/; if ($putname) { print "$newname\n"; next; } $newname = $path . "/" . $newname; $_ = $path . "/" . $_; if ($newname ne $_) { print "$_ -> $newname\n"; if (-e $prefix . $newname) { print STDERR "$newname already exists; can't rename\n"; } else { if (rename($prefix . $_, $prefix . $newname)) { $_ = $newname; } else { print STDERR "Rename to $newname failed.\n"; } } } # Changes to file contents . . . $_ = $prefix . $_; if (-T $_ && !$cdrom) { if (system('uncrnl', $_)/256 == 0) { print "Uncrnl'ed $_\n"; } else { print STDERR "Uncrnl $_ failed.\n"; } } } --------------Boundary-00=_L7POY5N4J9GXWY9SX6KQ Content-Type: application/x-shellscript; name="uncrnl" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="uncrnl" #! /bin/tcsh -f # set echo # By Brian T. Schellenberger # probably pointless but I didn't know about fromdos or whatever the # standard tool is when I wrote it. if ("$1" =~ */*) then set plc = $1:h set file = $1:t cd $plc else set file = $1 endif mv $file }$file} tr < }$file} > $file -d '\r' --------------Boundary-00=_L7POY5N4J9GXWY9SX6KQ-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209190757.22640.bts>