Removing erroneous directory entries: help needed

Mark Henderson henderso at mpr.ca
Mon May 13 03:53:55 AEST 1991


In article <1991May9.022627.8139 at gpu.utcs.utoronto.ca> aponty at gpu.utcs.utoronto.ca (Adele Ponty) writes:
>One of the users on our system managed to create an entry
>in one of our user_data directories that appears at the top
>of the directory listing as,  -k@  .  A long listing reveals 
>it to be some sort of link they attempted to create;
>l---------  -k@   ...  ...  -k@ -> df
>I don't know how they managed this but can someone tell me how
>to get rid of it?  I have a feeling that I may see more of these.
>Thanks.
>-- 
>                                                 ==== ==M= 
> INTERNET:  aponty at gpu.utcs.utoronto.ca          ==== ==i=
>     UUCP:  wheaties at intacc.uucp         (bbs)   ==== ==n=
>            aponty at agora.rain.com  (alternate)   =======g=

Use ls -i to find out the inode number of the file/link and then either
use
find . -inum xxxx -exec rm '{}' \;
or the following short program to delete the file.

/*
 * remove a file at a given inode number in the current directory usage: rm
 * <inode_number> useful for getting rid of files with strange names. Safer
 * than clri and can be run without being root.
 * Very simple-minded, but useful.
 * Usage:
 *	irm <inode-number>
 * 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
 *
 * Mark Henderson - Tektronix, Inc.
 * 
 * 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/4.1
 */

#include <sys/types.h>
#include <stdio.h>
#ifdef BSD43
#include <sys/dir.h>
#else
#include <dirent.h>
#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 <int>\n");
		exit(1);
	}
	target = atol(argv[1]);
	dirp = opendir(".");
	for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
		/* printf("%s %ld\n",dp->d_name, dp->d_fileno); */
		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);
}



More information about the Comp.unix.wizards mailing list