Even using wildcards fails sometimes. Here's something I wrote years ago.
It's meant for tweaking
when you run across a nasty file or directory name, so it won't solve your
problem without a little work.
The foreach loop at the bottom is to print out non-printable characters are
their ordinal value, which
is invaluable when you can't figure out what's going on. The trick is not
trying to handle the names
in a shell at all. Even perl can fail in this regard using rename and
unlink. I may have something to
do with invoking a shell anyway when there are shell variables in the name,
but that's what the added
backslashes are supposed to prevent.
Chris
#!/usr/bin/perl -w
# adjust as necessary. This was written to delete a dir that included a
0xA (\n)
# and square brackets in the actual name, so it was really tough to handle
from the shell.
opendir(DIR, '.');
while(defined($dir_ent=readdir(DIR))) {
#next if ( $dir_ent !~ /GetSubrDir/ );
print " \$dir_ent [$dir_ent]\n";
$dir_ent =~ s/([\[])/\\$1/g; # '\' protect the brackets so they aren't
handled as special shell things
$dir_ent =~ s/([\]])/\\$1/g;
print " \$dir_ent [$dir_ent]\n";
# rename( $dir_ent, 'bad_dir' ) or print "failed to rename: $!\n";
@chars = split('',$dir_ent); # the split is on a pair of single quotes
with no space; you get a list of individual characters
foreach $char(@chars) {
$ord=ord($char);
#print " \$ord [$ord], \$char [$char]\n";
}
}
On Wednesday, March 2, 2022 at 2:36:41 PM UTC-7 [email protected] wrote:
> What I use to delete hard to handle names is either a wild card, or the
> Emacs "directory" mode.
>
> Try something like
>
> *rm *FTP**
>
> Adjust as necessary. Make sure you do an "ls *FTP*" first, so you know
> what you're targeting!
>
>
> On Wed, Mar 2, 2022 at 1:27 PM Eric Gammeter <[email protected]> wrote:
>
>> Need to delete my #FTP.last file but I cannot get RM or UNLINK commands
>> to do the job. I get "missing operand" for both commands. The file name
>> has a ' (single quote) in front and at the end of the name. ??
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "weewx-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/weewx-user/d5c3b71b-32e7-44c7-9961-bcf520731aden%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/weewx-user/d5c3b71b-32e7-44c7-9961-bcf520731aden%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/b747bd9b-188e-4f8a-a8ce-56d2c58f85fbn%40googlegroups.com.