LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1717|回复: 17

[求助]如何将同一个文件复制到不同目录?

[复制链接]
发表于 2006-10-7 21:26:40 | 显示全部楼层 |阅读模式
用 ls -l | grep "^d" > dlist 得到目录列表
接下来该如何让 cp a.sh  遍历列表呢?
发表于 2006-10-8 02:30:25 | 显示全部楼层
ls -l | grep "^d" | awk '{print "a.sh " $8}' | xargs -L 1 cp
注意:"a.sh " 里有个空格。
回复 支持 反对

使用道具 举报

发表于 2006-10-8 10:30:01 | 显示全部楼层
在我的机器上上面的代码会有错误:
xargs: invalid option -- L
Usage: xargs [-0prtx] [-E eof-str] [-e[eof-str]] [-I replace-str]
       [-i[replace-str]] [-L max-lines] [-l[max-lines]] [-n max-args]
       [-s max-chars] [-P max-procs] [--null] [--eof[=eof-str]]
       [--replace[=replace-str]] [--max-lines[=max-lines]] [--interactive]
       [--max-chars=max-chars] [--verbose] [--exit] [--max-procs=max-procs]
       [--max-args=max-args] [--no-run-if-empty] [--version] [--help]
       [command [initial-arguments]]

Report bugs to <bug-findutils@gnu.org>.

是不是我的版本有问题啊,我的系统是RHEL 4 sp3.
回复 支持 反对

使用道具 举报

发表于 2006-10-8 12:03:44 | 显示全部楼层
Post by shizi4838

Usage: xargs [-0prtx] [-E eof-str] [-e[eof-str]] [-I replace-str]
       [-i[replace-str]] [-L max-lines] [-l[max-lines]] [-n max-args]
       [-s max-chars] [-P max-procs] [--null] [--eof[=eof-str]]
       [--replace[=replace-str]] [--max-lines[=max-lines]] [--interactive]
       [--max-chars=max-chars] [--verbose] [--exit] [--max-procs=max-procs]
       [--max-args=max-args] [--no-run-if-empty] [--version] [--help]
       [command [initial-arguments]]

看上面的usage,明明是有 -L的嘛。
试试 -l 选项吧:
ls -l | grep "^d" | awk '{print "a.sh " $8}' | xargs -l cp
回复 支持 反对

使用道具 举报

发表于 2006-10-8 13:18:41 | 显示全部楼层
ls -l | grep "^d" | awk '{print "a.sh " $8}' | xargs -l cp


It has been tested well
回复 支持 反对

使用道具 举报

发表于 2006-10-8 13:28:41 | 显示全部楼层
The manual page of xargs says that The -l option is deprecated since the POSIX standard specifies -L instead.
回复 支持 反对

使用道具 举报

发表于 2006-10-8 23:01:56 | 显示全部楼层

  1. find -type d -exec cp filename {} \;
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-8 23:03:27 | 显示全部楼层
我用RedHat 9没有 -L选项
另外目的地是 $9 ,cp前无数字1,没有其他问题

两个文件就并排放在print里,如果是要复制a*.sh呢
回复 支持 反对

使用道具 举报

发表于 2006-10-8 23:22:47 | 显示全部楼层
不posix,不兼容

for d (*(/)) cp file $d
回复 支持 反对

使用道具 举报

发表于 2006-10-8 23:42:30 | 显示全部楼层
Post by troll
不posix,不兼容

什么不 posix?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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