Problem
Users have created files on a UNIX filesystem (which could be one of the following types of filesystems):
DTFS -- Desktop Filesystem
S51K -- UNIX filesystem
HTFS -- High Throughput Filesystem
EAFS -- Enhanced ACER Fast Filesystem
AFS -- ACER Fast Filesystem
XENIX - XENIX Filesystem)that have special DOS-type characters or escape sequences
embedded in the filenames. (Some of the characters are not
reproducible by the keyboard - others are the backslash ("\")
character.)How do I remove files that have special characters embedded in the name?
Solution
Here are five possible solutions to this problem:
1. If you can use wildcards to list the filename that
contains unprintable characters, and only that filename
appears in the listing, then you can also use wildcards
to remove the file. First, display the files in the
directory with:# ls -b | moreThis will cause unprintable characters to be displayed
with "?"'s as placeholders. For example, if the file
you want to remove was displayed as "f?oo?bar", then
do the following:# ls -lb f?oo?barThe "?"'s in the above command are interpreted by the
shell to match one character each. One line should
display, with the name of the file you wish to remove.
Finally, to remove, do:# rm f?oo?barNote that you can also use the "*" wildcard to match
zero or more characters in the filename, trying to
match just the file you want to remove. Then use the
same pattern in the rm statement. For example, if:# ls -lb *barmatches just the "f?oo?bar" file, then you can remove with:
# rm *bar2. By inode - if the files to be deleted are few in number, then locate the file by the inode number. Issue the command:
(NOTE: The "#" represents the prompt and should not be typed.)
# ls -li
total 630
10985 drwxr-xr-x 2 root other 32 Feb 17 03:00 680053
10510 -rw-r--r-- 1 root other 0 Jun 15 13:52 \foo
10938 drwxr-xr-x 2 root other 64 Jun 02 03:00 dev2695
10899 drwxr-xr-x 3 sys sys 48 Apr 08 1994 init
11014 drwxr-xr-x 2 root other 32 Feb 10 15:20 junk1
10792 drw-r--r-- 2 bin bin 32 Mar 24 1993 messages
10900 drwxr-xr-x 2 root other 32 May 23 07:51 sme0The number that appears in the first column is the inode number bound to the filename.
Next, remove only the file which has the appropriate inode
number. In the previous example, the target file is "\foo"
and the inode number for this file is 10510.
^^^^^To remove the file, use a compound find(S) command:
# find . -inum 10510 -exec rm {} \;
^^^^^It is important to realize that you must be in the same
directory as the target file. This find command will delete
the "\foo" file as it has inode number 10510 assigned to it.3. By using escape sequences - If the special character in
the filename is a printable character, then you can escape the
special character by preceding it with a backslash (\). For
example, to remove the file "\foo", preceed the special character,
in this case a "\", with a backslash, as:# rm \\fooThis will remove the file that appears as "\foo" in the previous example.
4. By selective removal -- ***CAUTION*** This can erase every
file in the current working directory! Please read the
next section carefully before proceeding:Sometimes, especially from a networked DOS environment, files can be created which contain unprintable characters. Since these unprintable characters cannot be duplicated from the keyboard, you need to specify all files in the target directory as files to be removed,
There is an argument to the rm(C) command that will place
rm in interactive mode. The "-i" argument requires
confirmation for each and every file to be deleted.
By combining this option with a wildcard to specify all
files in the current working directory, you can target
only those files which have unprintable characters for
deletion:# cd {target-directory}
# rm -i *Once you have selected the files to be deleted, by responding with a 'y' at the prompt, you can break out of the rm command by pressing the <Del> key.
5. You can change the current working directory to the
directory that contains the improper file names. Once
there, you can use the hd(C) command. This will tell
you what non-printable characters exist within a file
name by displaying the octal values of those codes:# cd {target-directory}
# ls | hd | more
-- or --
# ls | od -c | moreYou can then remove the file by typing in the literal code string which was displayed in the hex dump:
# rm "f\0157oo\0142bar" See also
man pages for rm(C) and find(C)