[Chapter 23] 23.16 Removing a Strange File by its I-number
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:41:13Z

#

| Chapter 23 Removing Files |

## 23.16 Removing a Strange File by its I-number

If wildcards don't work (23.12) to remove a file with a strange name, try getting the file's i-number (1.22). Then use find's -inum operator (17.10) to remove the file.

Here's a directory with a weird filename. ls (with its default -q option (16.14) on BSD UNIX) shows that it has three unusual characters in it. Running ls -i shows each file's i-number. The strange file has i-number 6239. Give the i-number to find and the file is gone:

>     % ls
>     adir      afile     b???file  bfile     cfile     dfile
>     % ls -i
>       6253 adir        6239 b???file    6249 cfile
>       9291 afile       6248 bfile       9245 dfile
>     % find . -inum 6239 -exec rm {} \;
>     % ls
>     adir   afile  bfile  cfile  dfile

Instead of deleting the file, I could also have renamed it to newname with the command:

>     % find . -inum 6239 -exec mv {} newname \;

If the current directory has large subdirectories, you'll probably want to add the find -prune operator (17.23) for speed.

- JP

23.15 Using unlink to Remove a File with a Strange Name |  | 23.17 Problems Deleting Directories