相关疑难解决方法(0)

是否可以安全地使用`find -exec sh -c`?

我正在尝试将findtoecho 0用于某些文件,但显然这仅适用于sh -c

find /proc/sys/net/ipv6 -name accept_ra -exec sh -c 'echo 0 > {}' \;
Run Code Online (Sandbox Code Playgroud)

但是使用sh -cwithfind -exec让我觉得很不安,因为我怀疑引用问题。我稍微摆弄了一下,显然我的怀疑是有道理的:

  • 我的测试设置:

    martin@dogmeat ~ % cd findtest 
    martin@dogmeat ~/findtest % echo one > file\ with\ spaces
    martin@dogmeat ~/findtest % echo two > file\ with\ \'single\ quotes\'
    martin@dogmeat ~/findtest % echo three > file\ with\ \"double\ quotes\"
    martin@dogmeat ~/findtest % ll
    insgesamt 12K
    -rw-rw-r-- 1 martin martin 6 Sep 17 12:01 file with "double …
    Run Code Online (Sandbox Code Playgroud)

shell find

40
推荐指数
1
解决办法
1万
查看次数

通过 xargs 传递多个参数

我希望能够xargs在命令的不同部分执行多个参数。

例如,以下内容:

echo {1..8} | xargs -n2 | xargs -I v1 -I v2 echo the number v1 comes before v2
Run Code Online (Sandbox Code Playgroud)

我希望它会回来

the number 1 comes before 2
the number 3 comes before 4 
Run Code Online (Sandbox Code Playgroud)

... 等等

这是可以实现的吗?我怀疑我的多次使用-I是不正确的。

xargs

25
推荐指数
2
解决办法
3万
查看次数

标签 统计

find ×1

shell ×1

xargs ×1