LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: pumpkin

这个脚本怎么写?[about find&xargs]

[复制链接]
发表于 2003-11-18 23:33:24 | 显示全部楼层
ok, I start to understand... with man xargs ...

     xargs exits with the following status:
       0 if it succeeds
       123 if any invocation of the command exited with status 1-125
       124 if the command exited with status 255
       125 if the command is killed by a signal
       126 if the command cannot be run
       127 if the command is not found
       1 if some other error occurred.


--no-run-if-empty, -r
              If the standard input does not contain any nonblanks, do not run the command.  Normally, the command is run once even if there is no input.
发表于 2003-11-18 23:48:47 | 显示全部楼层
在rm命令行参数中末尾加上--然后再加文件名,可以确保删除掉以-打头的文件,平时在提示符下运行时,文件名是已知的,不会存在太大问题。在脚本中一般并不能预先知道将要操作的文件名,所以--参数是有必要的。如:
rm -rf -- -file1 ---file2 #删除文件-file1和---file2
也许大家主要为了阐述解决问题的思路,不必要太在意细节。但是为了对楼主和各位负责,还有自己的一点点较真的毛病,还是在这儿罗嗦两句。
发表于 2003-11-18 23:54:47 | 显示全部楼层
最初由 werix 发表
对,我也觉得文件少了点。。。兄弟能不能给解释一下为什么 -r0必须放在rm 之前? 我去掉它命令就只删一个文件了。。。不明白,还望阐明原理,谢过了。

参数0表示将管道传过来的字节流用NULL(\0)字符分割然后追加到rm --命令的尾部,并执行该命令。使用NULL做分割符可以正确的处理包含空格和引号的文件名。
 楼主| 发表于 2003-11-20 11:44:09 | 显示全部楼层
谢谢个位帮忙,使我大有收获!呵呵
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表