Removing a File with a Strange Name

Files with strange characters in their names (like spaces, control characters, beginning hyphens, and so on) pose a problem when you want to remove them. There are a few solutions to this problem.

One way is to use tab completion to complete the name of the file. This works when the name of the file you want to remove has enough characters to uniquely identify it so that completion can work. To use tab completion to remove the file `No Way' in the current directory, type:

$ rm NoTAB Way RET

In the above example, after TAB was typed, the shell filled in the rest of the file name (` Way'). When a file name begins with a control character or other strange character, specify the file name with a file name pattern that uniquely identifies it (see section Specifying File Names with Patterns, for tips on building file name patterns). Use the `−i' option to verify the deletion. To delete the file `^Acat' in a directory that also contains the files `cat' and `dog', type:

$ rm −i ?cat RET
rm: remove `^Acat'? y RET
$

Ιn the above example, the expansion pattern `?cat' matches the file `^Acat' and no other files in the directory. The `−i' option was used because, in some cases, no unique pattern can be made for a file−−for example, if this directory also contained a file called `1cat', the above rm command would also attempt to remove it; with the `−i' option, you can answer n to it. These first two methods will not work with files that begin with a hyphen character, because rm will interpret such a file name as an option; to remove such a file, use the `−−' option−−it specifies that what follows are arguments and not options. · To remove the file `−cat' from the current directory, type:

$ rm −− −cat RET

Posted on: 16/12/2009








0 Comments
If you want to leave a comment please Login or Register