How to delete a file with ^? chars in the name?

Chris Hare / System Manager chris at choreo.COM.COM
Fri Jan 12 00:14:30 AEST 1990


Organization : Choreo Systems Inc, Ottawa, Canada

In article <7711 at unix.SRI.COM>, ubi at ginger.sri.com (Ron Ueberschaer x4399) writes:
> I have a file which is named ^?^?^?H01.b (delete character?) and can't
> find a way to delete it.  An ls -s on the directory produces:
> 
>    ..	... (other files)
>     1	???H01.b
> 
> If I do an ls *.b, it lists the other .b files, but complains:
> 
> 	H01.b not found
> 
> I've tried:
> 
> 	rm -i *			(to selectively delete everything)
> 	rm "???H01.b"
> 	rm "^v^?^v^?^v^?H01.b"  (control-v delete ...)
> 
> and nothing seems to work.
> 
> Help me, o wizards!
> 

This solution was published in UNIX World magazine a couple of years ago
The source code is found after the "---cut here---" line.

The little C program requires that your pwd be the directory where the file
to remove is.  You must find out the i-node number of the affected file 
( using ls -i ).  After you have it, you run this program with the i-node
number as the argument, and the filename will be changed from 'junk' to
fix.out.  Then you can delete it, or do want you want with it.

We have this implemented on a SCO XENIX 386, SCO UNIX 386, Motorola UNIX
V/68, AT&T UNIX SysV.2, SysV.3.

------------------------------------------------------------------------
Chris Hare, Coordinator, Systems Management		Choreo Systems Inc
email : uunet!choreo!chris				Tel 613-238-1050
							Fax 613-238-4453



---cut here---
#include <stdio.h>
#include <sys/types.h>
#include <sys/dir.h>
#include <ctype.h>
#define FIXOUT "fix.out"  /* output file name*/

main(argc,argv)
int argc;
char *argv[];
{
   struct direct dbuf;
   int fd,fix_ino;

   if ( argc != 2 || !isdigit( argv[1][0]))
      {
      fprintf(stderr, "\nUsage:  %s inode-number\n", argv[0]);
      exit(1);
      }
   fix_ino = atoi(argv[1]);

   if ((fd = open(".", 0)) < 0)
      {
      fprintf(stderr, "\nCan't read current directory.\n");
      exit(2);
      }
   while (read(fd, (char *) &dbuf, sizeof(dbuf)) > 0 )
      {
      if ( dbuf.d_ino != fix_ino)
         continue;
      unlink(FIXOUT);  /* erase former fix */
      link (dbuf.d_name, FIXOUT );  /* new link */
      unlink(dbuf.d_name);  /* erase old link */
      printf("\nFixed it: inod-number = %d\n", fix_ino);
      printf("old name was :%s:\n",dbuf.d_name);
      printf("new name is  :%s:\n",FIXOUT);
      exit(0);
      }
   close(fd);
   printf("\nCouldn't find it !!!\n");
}



More information about the Comp.unix.wizards mailing list