how to delete '#FTP.last' file

59 views
Skip to first unread message

Eric Gammeter

unread,
Mar 2, 2022, 4:27:16 PM3/2/22
to weewx-user
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.  ?? 

Tom Keffer

unread,
Mar 2, 2022, 4:36:41 PM3/2/22
to weewx-user
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 <n8a...@gmail.com> 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 weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/d5c3b71b-32e7-44c7-9961-bcf520731aden%40googlegroups.com.

cric...@pobox.com

unread,
Mar 2, 2022, 5:38:53 PM3/2/22
to weewx-user
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";
      }
   }


vince

unread,
Mar 2, 2022, 7:33:11 PM3/2/22
to weewx-user
escape the # sign with a backslash

cd into the directory then 
     rm -i ./\#FTP.last

The -i will prompt you juuuuuust in case you typo it and would otherwise do something unexpected/bad.

Tests ok on a pi here.

Eric Gammeter

unread,
Mar 3, 2022, 3:43:53 PM3/3/22
to weewx-user
Yes!  That (the rm *FTP*) did it.  Thank you! 

Eric Gammeter

unread,
Mar 3, 2022, 3:46:35 PM3/3/22
to weewx-user
This is RESOLVED.   (how do I close it out?) 
Reply all
Reply to author
Forward
0 new messages