您尚未登录。

楼主 #1 2018-10-22 15:27:39

lilo
会员
注册时间: 2017-10-15
已发帖子: 215
积分: 215

shell的args 命令能不能把参数放在中间

比如我想删除整个系统 .dump 后缀名的文件, 我这样操作:

find / | grep \\.dump$ |xargs rm -rf

这样我可以删除所有 *.dump 文件,

但是现在问题来了, 如何把所有 .dump 拷贝到指定目录呢?

find / | grep \\.dump$ |xargs cp xxx /tmp

这个命令怎么写呢, 这个 xxx 用什么替代, 困扰我很久的问题.

离线

#2 2018-10-22 15:31:40

晕哥
管理员
所在地: wechat: whycan_cn
注册时间: 2017-09-06
已发帖子: 9,473
积分: 9202

Re: shell的args 命令能不能把参数放在中间

看下 args 的帮助:

/ # xargs --help
BusyBox v1.27.2 (2018-03-28 11:22:26 CST) multi-call binary.

Usage: xargs [OPTIONS] [PROG ARGS]

Run PROG on every item given by stdin

-p Ask user whether to run each command
-r Don't run command if input is empty
-0 Input is separated by NUL characters
-t Print the command on stderr before execution
-e[STR] STR stops input processing
-n N Pass no more than N args to PROG
-s N Pass command line of no more than N bytes
-I STR Replace STR within PROG ARGS with input line
-x Exit if size is exceeded

上面的 -I 可以执行字符串替换的.

find / | grep \\.dump$ | args -I % cp % /tmp

上面这个命令可以完成你的任务, 可以试一试。





离线

#3 2018-10-22 15:37:06

真的是很烦
会员
注册时间: 2018-10-08
已发帖子: 162
积分: 154.5

Re: shell的args 命令能不能把参数放在中间

cp find . -name '*.dump' /tmp

或者用find 的exec 参数

离线

#4 2018-10-22 15:58:18

晕哥
管理员
所在地: wechat: whycan_cn
注册时间: 2017-09-06
已发帖子: 9,473
积分: 9202

Re: shell的args 命令能不能把参数放在中间

真的是很烦 wrote:

cp find . -name '*.dump' /tmp

或者用find 的exec 参数

这个也不错, 看来你的shell也很6





离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn


东莞哇酷科技有限公司开发