Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2029863
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

分类:

2008-11-09 14:23:19



问题:

有个一文件名里面还有特殊的字符,如"-osample1.c", 但是很难删除这个文件,因为如果删除的时候,系统会认为这个文件名是你要使用的一个命令行选项从而无法删除。而且会报出“ls: illegal option -- .”这类的错误,情况如下

> ls *sample1*
ls: illegal option -- .
usage: ls -1ARadeCxmnlogrtucpFLbqisf [files]
> ls
-osample1.o demo_proc.mk makefile test.sh test1.c test1.o testing
asdf.log inst scripts test1 test1.lis test1.pc
> rm *sample1*
rm: illegal option -- o
rm: illegal option -- s
rm: illegal option -- a
rm: illegal option -- m
rm: illegal option -- p
rm: illegal option -- l
rm: illegal option -- e
rm: illegal option -- 1
rm: illegal option -- .
rm: illegal option -- o
Usage: rm [-Rfir] file ...
> rm -osample1.o
rm: illegal option -- o
rm: illegal option -- s
rm: illegal option -- a
rm: illegal option -- m
rm: illegal option -- p
rm: illegal option -- l
rm: illegal option -- e
rm: illegal option -- 1
rm: illegal option -- .
rm: illegal option -- o
Usage: rm [-Rfir] file ...

解答:
查看系统的帮助手册 man sh

Code:
       --        A -- signals the end of options and disables  further  option
processing. Any arguments after the -- are treated as file-
names and arguments. An argument of - is equivalent to --.
根据描述,我们可以进行如下的操作
Code:
sh-2.05b$ touch -- -123
sh-2.05b$ ls -l -- -123
-rw-r--r-- 1 abcdefgh g900 0 Dec 7 07:17 -123
sh-2.05b$ rm -- -123
sh-2.05b$ ls -l -- -123
ls: -123: No such file or directory
sh-2.05b$


阅读(3652) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~