Suppose you have a filename with spaces or special characters, such as:
-rw-r--r-- 1 someuser student 273 Apr 9 18:45 My Filename With Spaces -rw-r--r-- 1 someuser student 352 Apr 9 19:25 My Other File
In general, it's easiest to allow the shell to decide how it wants you to type in that filename. Most modern UNIX shells provide a feature called 'tab-completion', which allows the shell to automatically fill in partially typed commands and filenames. To do this, you type part of the filename, then hit <TAB>; the shell will fill is as much of the filename as it can without arbitrarily guessing.
In the case of the two files above, say you want to use the mv command to rename the file 'My Other File' to 'my_file'. To do this, type in as much of the command as you know:
Now hit <TAB>. The shell will automatically fill in as much as it can without arbitrarily guessing; that is, it knows the next character is a space, but it doesn't know whether you mean 'My Filename With Spaces' or 'My Other File'. So now you would have, on the command line:
Give the shell a little more information by typing in some more of the filename (now that it has filled in the space for you):
mv My\ Oth
At this point, you can just hit <TAB> again and the shell will finish the filename for you:
mv My\ Other\ File
Now you can finish the command:
mv My\ Other\ File my_file
It may occasionally be the case that this solution won't work for you; for example, what if your directory had a third file:
-rw-r--r-- 1 someuser student 273 Apr 9 18:45 My Filename With Spaces -rw-r--r-- 1 someuser student 352 Apr 9 19:25 My Other File -rw-r--r-- 1 someuser student 2127 Apr 9 18:12 My_Favorite_File
In this case, when you hit <TAB> the first time, the shell won't be able to tell whether the next character should be a space or an underscore. If you didn't know how to type the space, you would be up a proverbial creek without a paddle.
A surefire, though painful, way to remove such directories or files is to use the -i option and the wildcard character (*) on the rm command. The -i option causes the system to prompt you for verification before it removes a file or directory, and the * character matches any number of characters.
BE CAREFUL: The * means ANY file, and it's easy for you to delete a file you need. The -i option is essential.
To remove a file with a special character in the filename, type:
rm -i *
and answer "n" (no) for the files that you don't want to remove and "y" (yes) for the files you do want to remove. The * character displays all filenames in the directory, including those with blanks or special characters.
To remove a directory with a special character in the name, type:
rm -ir *