Can't delete file. Invalid file name
Hi we have accidentally created a very large file with the name "-C" without the quotes in the root directory. If I issue an ls it doesn't show up, if I issue an ls -ltr I see it.
following is the response I receive when we try to delete it:
# rm -C
rm: illegal option -- C
usage: rm [-fiRr] file ...
#
How can I remove this file ? How was is able to be created if it's an illegal name ?
Thanks in advance.
Dave
[475 byte] By [
dscarani] at [2007-11-25 23:24:31]

# 1
hi dave
that's easy ;-)
if you have filenames, starting with a "-" use the [dot][slash]-option:
rm ./-C
> How was is able to be created if it's an illegal name ?
>
possible, that it's caused by a failed "mv"-command
e.g.
mv foo -foo leads to an abort with error, but an empty -foo file will be created.
cheers - jenny
# 2
Wow ! That was easy.
I thank you and my storage thanks you.
One other question if I may. I seem to recall I had accidentally created a file similar to that once before, but I don't remember where it is. Do you know a find command that can find files that start with something other than an alpha character ?
Thanks again.
Dave
# 3
hi dave, surely ;-)
change to / and use ' find ' with wildcards (? for one character, * for multiple characters etc).
e.g.:
find -name '-*'lists all filenames starting with -
find -name '?foo*'search for files starting with *one* character, followed of foo and any number of characters.
c'ya & have a nice day
jenny
btw.
it's the first time, a storage unit thanks me -
my servers and nat's are not as polite as your's :-))
i assume, you use a HAL9000, dave ? [big grin]
# 4
(chuckle) .... I like the Space Oddessy reference .... ;-]
What about removing files with control characters in them ? I can't remember how to do that, I remember a prankster putting a file on a machine with a CTRL-G in the name, of course, giving you a beep every time you did an ls on the directory... you can view the full filename with ls -lb but I can't remember how to remove it ...
# 5
hi brian !
hmmm....try to think as modular as unix is *gg*
you and dave can search for files with wildcards like ? * , so why not use them in rm ?
e.g.
rm ?foo deletes every file with one character, followed by foo, whether it is a control character or not.
rm ?foo deletes every file with two characters, followed by foo........
etcetcetc
if your not sure, use the -i interactiv option.
rm asks for every file, whether it shall be deleted or not.
> (chuckle) .... I like the Space Oddessy reference ....
> ;-]
*ggg*
may i reference to "The Life of Brian" too, brian ?
cu and have a nice weekend
jenny
# 6
hi brian,me again.
there's another method, if you know what control-character it is.
use rm (-i) but before you type in the wanted control-character, mark it as non executable (ctrl + v).
e.g.
filename to delete is [ctrl-g]atineau;-)
do
rm ctrl+v ctrl+gatineau
cheers,jenny
btw - post 5:
buy a "refer", accept "reference" in part payment
# 7
and if you don't know the characters, you can always try something like ls <insert your arguments here> | od -xCand see if it gives you more information about what is in the filename
# 8
ThanksI too craeted many files with name -i and removed sucessfully through above mentioned command.thanks
# 9
Another easy approach is the -- option. This works in Solaris 10, I am not too sure about earlier versions. But then you simply tell rm that everything behind the -- is to be treated literally:rm -- -this*is*a-stupid-file-I-made.Etc..
LionO at 2007-7-5 18:11:31 >
