Need help reading a file with unusual name(s)
Guy Harris
guy at auspex.auspex.com
Tue Apr 18 17:56:50 AEST 1989
> to edit "maps\033w" type "vi maps\\033w". This interprets the
>backslash as a literal charachter rather that the introducer to a special
>charachter.
"\033" doesn't mean "the character backslash, followed by the character
'0', followed by...", it means "the character with the octal value 33",
also known as "escape". (He said "non-graphic character, and "\", "0",
and "3" are all graphic.) To type in that character, you'd have to hit
the <ESC> key, or its moral equivalent, on your keyboard (or resort to
some trickery involving backquotes or something like that).
>Similarly, for a file with a CR try "vi filename\<cr>"
Which, if you type it on your keyboard, will probably cause the terminal
driver to see your CR, map it to NL, and treat it as an end-of-line
terminator. Your shell will probably treat the backslash at the end of
the line (it has only a NL following it, which means it's at the end of
the line) as a "continued on next line" indication (both the Bourne/Korn
and C shells do this), and wait for you to type another line.
No, to manipulate a file with <CR> at the end of the name requires even
more trickery. On *some* systems you can keep the terminal driver from
mapping the CR to an NL by typing your "literal-next" character,
normally ^V (control-V) before it. Doing
vi filename^V<return><return>
where ^V is control-V and <return> is the RETURN key, will let you edit
the file. On other systems, you can't do this, and will have to use
other trickery.
In both cases, the best thing to do is probably to rename the file
first, giving it a name lacking non-graphic characters. You can
generally do this with the "?" shell metacharacter:
mv filename? filenameCR
"filename?" will match all files whose names consist of "filename"
followed by any character, including CR; the "?" matches any character.
If there is only one such file, for example filename<CR>, this will
rename that file "filenameCR" (make sure there's not already a file with
that name, otherwise "mv" will try to remove it; if there is such a
file, or if you don't like the name "filenameCR", pick another name).
If there is more than one such file, this, unfortunately, won't work.
Stronger medicine is needed. One fix would be to make a new directory
in the current directory:
mkdir temporary
move all the files in question into that directory:
mv filename? temporary
move all the files *except* the one you wnat back out of that directory:
mv temporary/filename1 . # move into "." - current directory
mv temporary/filename2 .
...
and then deal with the funny-named file:
mv temporary/filename? filenameCR
which moves it out of that directory and gives it a new name.
(Yes, this is a bit painful, and can be taken out of context and used to
bash UNIX. I suspect the same could be done with just about any other
OS out there; there are situations where a given OS feature - in this
case, UNIX's willingness to put almost any byte value into a file name -
is a blessing, and situations where it's a nuisance.)
More information about the Comp.unix.questions
mailing list