Managing file names with spaces in Unix
* Try the regular rm command and enclose your troublesome filename in quotes. This may solve the problem of deleting files with spaces in their name, for example:
rm "File Name"
You can also remove some other characters in this manner, for example:
rm "filename;#"
The quotes prevent the semicolon 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.)
* You can also try renaming the problem file, using quotes around your original filename, by entering:
mv "filename;#" new_filename
If this command successfully renames the file, you can then use the rm command to delete the file using the new name.
* If this does not work, insert a backslash ( \ ) before the meta-character in your filename. The backslash causes the character that follows to be interpreted literally. For example, to remove the file named my$project, enter:
rm my\$project
* To remove a file whose name begins with a dash ( - ) character, refer to the file with the following syntax:
rm ./-filename
Using the redundant ./ directory information prevents the dash from occurring at the beginning of the filename, and being interpreted as an option of the rm command.
* There are some characters that you cannot remove using any of the above methods, such as forward slashes, interpreted by Unix as directory separators. 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:
mdel
You will be asked if you really wish to delete each file in the directory. 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.
Note: If you're using a graphical FTP client, remove these files the same way you remove any other file.
* Some Emacs editors allow you to directly edit a directory, and this provides yet another way to remove a file with a troublesome name. Consult Emacs documentation for more information.
Also see: