UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 23.15 Using unlink to Remove a File with a Strange Name Chapter 23
Removing Files
Next: 23.17 Problems Deleting Directories
 

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


Previous: 23.15 Using unlink to Remove a File with a Strange Name UNIX Power ToolsNext: 23.17 Problems Deleting Directories
23.15 Using unlink to Remove a File with a Strange Name Book Index23.17 Problems Deleting Directories

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System