Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.unix.questions Subject: Re: Accessing files by inode #s Message-ID: <602@cresswell.quintus.UUCP> Date: 29 Jan 88 08:06:22 GMT References: <11525@brl-adm.ARPA> Organization: Quintus Computer Systems, Mountain View, CA Lines: 43 Summary: doesn't work [The task is to delete a file whose name contains strange characters.] [The original poster thought that using Inode numbers was a good idea] [but couldn't quite see what to do next. ] In article <11525@brl-adm.ARPA>, rwelsh@cct.bbn.com (Robert J. Welsh) writes: > If you want to get rid of files that have control characters etc in their > name, this should work: > 1) ls -i to get the inode number > 2) set `ls -i | grep `; rm $2 > This will work in the standard shell, 'sh', and derivatives thereof. I'm afraid it WON'T work if the file name contains any characters in IFS. (In particular, spaces and tabs.) Do the following: $ mkdir scratch $ cd scratch $ cat "foo baz" $ ls -i The output I got was 20545 foo baz $ set `ls -i | grep 20545` $ echo $2 The output I got was foo A subsequence $ rm $2 therefore tries to delete a file called "foo". You have similar problems using wild-cards: $ rm fo* reports the non-existence of "foo" and "baz". find(1) seems to work: $ find . -inum ${DesiredInodeNumber} -exec rm {} \; Of course, in this case $ rm 'foo baz' also works. With a BSD terminal driver, you can type in any characters at all, so you don't need special tools or hacks. For example, if the file you want is ^A^B^Cfoo^Ibaz^D (^X means control-X), and if the literal-next character is ^V, just do $ rm '^V^A^V^B^V^Cfoo^Ibaz^V^D' The ultimate method, of course, is to write a C program, calling unlink().