Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 from ihnp4 4.3bsd-beta 6/6/85; site chinet.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!chinet!megabyte From: megabyte@chinet.UUCP (Mark E. Sunderlin) Newsgroups: net.unix-wizards Subject: Summary of how to remove file with NULL names Message-ID: <306@chinet.UUCP> Date: Mon, 21-Apr-86 10:51:08 EST Article-I.D.: chinet.306 Posted: Mon Apr 21 10:51:08 1986 Date-Received: Wed, 23-Apr-86 14:43:40 EST Reply-To: megabyte@chinet.UUCP (Mark E. Sunderlin) Distribution: net Organization: chi-net, Public Access UN*X, Chicago IL Lines: 110 Here is the consensis of the net on how to remove files with strange and weird characters in there names. Thanks to all the below who responded to my queery. uokmet!kwthomas,mtgzy!ecl,necis!geo,pegasus!hansen,BRL.ARPA!gwyn jplgodo!steve ,and Robert Sanford whose address I lost in the depths of vi and lines over 80 columns long. >The files have characters over \177 (decimal = 127) in them. /bin/sh doesn't >expand such files correctly, as the upper bit is an internal flag meaning >"this character is quoted" in sh. So it loses the upper bits on the final >parse pass or thereabouts. So "rm" gets a nonexistent file name. >--------------------------------------------------------------------- >Here is a program that uses the "unlink" system call to remove >files with funky names. Be careful when using this program >because it can remove just about anything it wants. You describe >the desired file(s) by using valid filename characters or a >backslash followed by three characters in the range of [0-7] >(octal (gasp!) representation of the character). One example will >follow the program. > >/*************************/ >/* > rmjunk.c > > author: Robert Sanford > usage: rmjunk file [file ...] >*/ > > >#include >#include > > >main ( ac, av ) > int ac; > char **av; >{ > char *ip; > char *op; > char buf[ 200 ]; > > for (av++; *av; av++) > { > for (ip = *av, op = buf; *ip;) > if (*ip == '\\') > { > *op++ = ((ip[1] - '0')*64) + ((ip[2] - '0')*8) + > (ip[3] - '0'); > ip += 4; > } > else > *op++ = *ip++; > *op = 0; > if (unlink( buf ) < 0) > { > xdump( stderr, buf ); > fprintf(stderr, "rmjunk(%s): FAILED errno=%d\n", *av, > errno); > } > } >} > >xdump ( fp, bp ) > FILE *fp; > char *bp; >{ > fputc( '"', fp ); > > for (; *bp; bp++) > if (*bp >= ' ' && *bp <= '~') > fputc( *bp, fp ); > else > fprintf(fp, "\\%03o", *bp); > > fputc( '"', fp ); > fputc( '\n', fp ); >} >/*************************/ > >The best way to identify the exact name of the file you want to remove >is to dump the directory: > > od -c . > >0000000 005 ` . \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 >0000020 \0 002 . . \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 >0000040 005 a . p r o f i l e \0 \0 \0 \0 \0 \0 >0000100 005 c . n e w s r c \0 \0 \0 \0 \0 \0 \0 >0000140 005 s . m a c s \0 \0 \0 \0 \0 \0 \0 \0 \0 >0000160 005 } . n e w s _ t i m e \0 \0 \0 \0 >0000420 005 345 r e a l t i m e 2 \0 \0 \0 \0 \0 >0000440 005 346 \001 e p a r t 2 \0 \0 \0 \0 \0 \0 \0 > >(I'm assuming you have Sys.V fixed size directory entries.) In this example >the last entry is garbage and needs to be removed. (The first two bytes of >each entry are the i-node number. Isn't it convenient that the length of >a directory entry is the same as the number of characters "od" displays >on a line !) Using my "rmjunk" program, you would enter: > > unlink '\001epart2' > >This SHOULD yield the desired results. :-) -- _________________________________________________________________________ UUCP: (1) seismo!dolqci!irsdcp!scsnet!sunder Mark E. Sunderlin (2) ihnp4!chinet!megabyte aka Dr. Megabyte CIS: 74026,3235 (202) 634-2529 Quote: "No matter where you go, There you are" (9-4 EST) Mail: IRS 1111 Constitution Ave. NW PM:S:D:NO Washington, DC 20224