请问大家linux下,怎么删除一个名字为“-g”的文件?

来源:百度知道 编辑:UC知道 时间:2024/07/04 12:47:48
我编译test.c后,链接的时候,弄的太快,输错了命令,写成了
gcc -o -g test.o 结果就生成了一个名字是"-g"的文件,删除的时候就是下面状况:

[root@localhost DIRprocess]# rm -g
rm: invalid option -- g
Try `rm --help' for more information.
[root@localhost DIRprocess]# rm '-g'
rm: invalid option -- g
Try `rm --help' for more information.
[root@localhost DIRprocess]# rm '\-g'
rm: cannot lstat `\\-g': No such file or directory
[root@localhost DIRprocess]#
... ...

要删除第一个字符为‘-’的文件 (例如‘-foo’),请使用以下其中一种方法:
rm -- -foo

rm ./-foo

原因是,如果不这样做,会认为rm后面跟的不是文件名,而是一个选项.