Dealing with Odd Characters in UNIX File/Directory Names

Some characters are not interpreted literally in UNIX. For example, the ~, !, $, *, ?, \ , / and blank spaces are called metacharacters and can cause problems when used in filenames because they have other purposes in UNIX and are interpreted as instructions.

If you've uploaded or published files to your Unix/AFS account from a PC or Macintosh with filenames containing what Unix considers to be "meta-characters", you will encounter problems viewing, editing or deleting the files.

To rename or delete the files, try the following methods:

Spaces in the file name:

Try using the rm (remove) or mv (move) command, putting the file name in quotes:

rm "File Name"
mv "file!;#" new_filename

You can also remove some other characters (e.g., ;#)  in this manner:

rm "filename;#"
mv "filename;#" new_filename

The quotes prevent the ";" from being interpreted as a stacking command. (Since you can string commands together in Unix with semicolons, Unix will interpret a semicolon in a filename that way, unless you put it in quotes.)

Dashes - in the file name

Try this syntax (which prevents the minus - from being interpreted as an option for the rm command)

rm ./-filename

Using the \

In UNIX, the \ tells the system means literal character. Use the \ to make UNIX interpret the character literally rather than as an instruction:

rm file\$name
rm file\!name

One last suggestion:

There are some characters that cannot be removed using any of the above methods, such as forward slashes which UNIX interprets as directory separators. In order to remove a file with such meta-characters, you may have to ftp into the account containing the file from a separate account and enter the command:
You will be prompted with each filename in the account and asked whether or not you really wish to delete each file. Be sure to answer N for No for each file except the file containing the difficult character that you wish to delete! Delete that file by typing Y for Yes when prompted. Once you've deleted the intended file, you may press Ctrl-c to discontinue the MDEL process. Use this approach cautiously to avoid deleting other files by mistake.

For additional questions, contact the Help Desk at 758-HELP (4357). Help
Desk FAQ document #0058, June 2000