How to delete a file with ^? chars in the name?
Jonathan I. Kamens
jik at athena.mit.edu
Mon Jan 15 16:57:28 AEST 1990
You know, I seem to recall that the thing which got the ball rolling
enough to get a Frequently Asked Questions posting started was a flame
by me about a discussion very similar to this one ("How do I get a
listing of all the files and directories below a specified directory?").
Not since the FAQ posting started have I seen a discussion that was as
irritating as that discussion about find(1) (although the "What is a
wizard?" discussion came close). Until now.
The number of unnecessary postings, many of them wrong, about "How to
delete a file with ^? chars in the name?" is really, really getting
irritating. Can people just *stop* posting, please? And if you *are*
going to post about it, then post about the *real* question, which is
how to deal with files that have the eighth bit set in characters in
their names.
In article <1221 at kl-cs.UUCP>, jonathan at cs.keele.ac.uk (Jonathan Knight) writes:
> Why doesn't anyone suggest 'rm ???H01.b' - assuming that there are no other
> file names ending in H01.b which are exactly 8 chars long this will work
> fine.
Because the symptoms described by the original poster imply very
strongly that the files in question have characters in the filenames
with their eighth bit set. Under BSD at least, none of the system calls
that deal with filenames will accept files that have characters of that
sort in that name; frankly, I am puzzled about how the original poster
managed to get files of that sort on his disk, because I had to edit the
raw disk device to do it. It may be easier under non-BSD versions of Unix.
I created a filesystem on a floppy disk, created a zero-length file
"Afrep" on the disk filesystem, read the filesystem into a regular file,
changed the 'A' in the filename "Afrep" to '\201' ('A' with the high bit
set), then wrote my copy of the file back out to the floppy. All this
with the floppy fs unmounted, of course.
I then tried to fsck the disk device. This is what I got:
pit-manager# fsck /dev/floppy
** /dev/floppy
** Last Mounted on /tmp/disk
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
DIRECTORY CORRUPTED I=2 OWNER=jik MODE=40755
SIZE=512 MTIME=Jan 15 00:14 1990
DIR=
SALVAGE? no
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
UNREF FILE I=4 OWNER=jik MODE=100664
SIZE=0 MTIME=Jan 15 00:14 1990
RECONNECT? no
CLEAR? no
** Phase 5 - Check Cyl groups
3 files, 9 used, 2198 free (14 frags, 273 blocks, 0.6% fragmentation)
So, as you can see, fsck doesn't like at all the fact that there is a
filename with a character with the high bit set. Ignoring the fact that
fsck didn't like the disk, I mounted it anyway (don't try this at home,
folks! :-):
pit-manager# mount /dev/floppy /tmp/disk
pit-manager# cd /tmp/disk
pit-manager# ls
lost+found ?frep
pit-manager# ls -l
frep not found (Invalid argument)
total 4
drwxr-xr-x 2 root 4096 Jan 15 00:12 lost+found
pit-manager# ls -li
frep not found (Invalid argument)
total 4
3 drwxr-xr-x 2 root 4096 Jan 15 00:12 lost+found
pit-manager# rm ?frep
rm: frep nonexistent
The net result of all of this is that it seems that if there really are
characters with the high bit set in filenames on the disk (that would
seem to be suggested even more strongly by E-mail correspondence I have
had with the person having this problem), the only way to solve them is
to either (a) run fsck on the disk and let it fix the corrupted
directories and put the unconnected files that result into lost+found on
the device (if your fsck doesn't notice directories that are corrupted
in this manner, then get a new fsck :-), or (b) unmount the disk and
edit the raw disk device using fsdb (or, if you're even more brave,
emacs :-) to fix the errant filenames.
Now, if you've got another idea for dealing with filenames with
characters with their high bit set, I'd like to hear it, and it probably
would belong in comp.unix.wizards. If you want to talk more about rm -i
and using find and using simple C programs, then please send it to /dev/null!
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8495 Home: 617-782-0710
P.S. In an earlier message on this subject, I said that "ls -li" and
"find -inum" could be used to deal with the file. However, if there
really are high-bit characters in the file name, that won't work.
More information about the Comp.unix.wizards
mailing list