Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!ogicse!zephyr.ens.tek.com!tekcrl!squirrel!markh From: markh@squirrel.LABS.TEK.COM (Mark Henderson) Newsgroups: comp.unix.admin Subject: Re: help removing a file Message-ID: <6753@tekcrl.LABS.TEK.COM> Date: 8 Sep 90 05:57:46 GMT References: <1990Sep5.180847.21767@zaphod.mps.ohio-state.edu> Sender: news@tekcrl.LABS.TEK.COM Reply-To: markh@squirrel.LABS.TEK.COM (Mark Henderson) Distribution: usa Organization: Computer Research Laboratory, Tektronix, Inc., Beaverton OR Lines: 88 In article <1990Sep5.180847.21767@zaphod.mps.ohio-state.edu> harmon@function.mps.ohio-state.edu (Jim Harmon) writes: >Could someone someone help me with removing a file. On our system we have a >file that appears as zhang?evai.tex when doing a `ls` but a tab completion >says it's zhangNevai.tex. I've tried putting a back slash in front of the ? >and quoting the whole name. I even tried doing `rm -i *` and it matches >zhangNevai.tex but says there's No such file or directory. > >thanks >harmon@mps.ohio-state.edu You don't mention what flavour of unix you are using. Here's a simple C program which I keep around called irm, which will allow you to specify an inode number of a file in the current directory and have it deleted. I've been using it for a while on SUN 3's and 4's running SUN OS 4.0.x and Vaxen running 4.3 BSD. I imagine adapting it to almost any flavour of Unix would be easy. It is almost verbatim out of the SUN OS manual entry for directory(3v). It's sloppy in many respects, but then it was a quick hack. For instance I make assumptions about being able to open the current directory, only allow one i-node number to be specified, more or less assume inode numbers are longs, don't check that the parameter is an integer...etc. Use it and modify it absolutely at your own risk. I've placed instructions for using it in the comment. /* * remove a file at a given inode number in the current directory * Mark Henderson, Tektronix, Inc. markh@crl.labs.tek.com * Use this code at your own risk! * Useful for getting rid of files with strange names. Safer * than clri and can be run without being root. * Usage: * irm * The inode number can be obtained by using ls -i * So to get rid of file *****.???'\^C^D^Z * cd into the directory containing the file. * Do an ls -i and find the inode number of the file * (say 30240) then type * irm 30240 * * BSD43 is for VAX BSD 4.3 (do not use BSD43 for SUN OS 4.0) Tested under SUN * OS 4.0 and VAX BSD 4.3. Is BSD43 is not specified compiles for SUN OS 4.0 */ #include #include #ifdef BSD43 #include #else #include #endif main(argc, argv) int argc; char *argv[]; { ino_t target; DIR *dirp; #ifdef BSD43 struct direct *dp; #else struct dirent *dp; #endif if (argc != 2) { printf("\nusage irm \n"); exit(1); } target = atol(argv[1]); dirp = opendir("."); for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { if ((dp->d_fileno) == target) { printf("\nFOUND: %s\n", dp->d_name); closedir(dirp); if (!unlink(dp->d_name)) printf(" deleted\n"); else printf(" delete failed\n"); exit(0); } } printf("\nNOT FOUND\n"); closedir(dirp); } -- Mark Henderson, Tektronix, Inc., MS 50-662, P.O. Box 500, Beaverton, OR 97077 Telephone: +1 503 627 6280 FAX: +1 503 627 5502 TELEX: 6503784996MCI UW INTERNET: markh@crl.labs.tek.com ATTmail: !mchenderson MCI MAIL: 378-4996 X.400: ADMD=MCI/C=US/Surname=Henderson/Given_Name=Mark/DDA ID=3784996