现在感觉自己像个白痴。为什么这不起作用?
echo "/some/directory/path" | xargs -n1 cd
Run Code Online (Sandbox Code Playgroud) 在 Linux 中,您可以使用以下顺序对四个不同的服务器xargs -d,快速运行hostname命令:
echo -n 1,2,3,4 |xargs -d, -I{} ssh root@www{}.example.com hostname
看起来 OSX xargs 命令不支持分隔符参数。您可以使用不同格式的echo或通过其他一些命令行实用程序获得相同的结果吗?
假设我想删除目录中除名为“notes.txt”的文件之外的所有文件。我会用管道来做到这一点,ls | grep -v "notes.txt" | xargs rm. 如果第二个管道的输出是 rm 应该使用的输入,为什么我需要 xargs?
为了进行比较,管道echo "#include <knowledge.h>" | cat > foo.c将回显的文本插入到文件中,而不使用 xargs。这两个管道有什么区别?
我想知道这有什么区别
ls | xargs rm
ls | xargs -i{} rm {}
两者都为我工作
为什么这不起作用?
ls *.txt | xargs cat > all.txt
Run Code Online (Sandbox Code Playgroud)
(我想将所有文本文件的内容加入一个“all.txt”文件中。) find 与 -exec 也应该可以工作,但我真的很想了解 xargs 语法。
谢谢
我正在寻找一个可以在不同目录中重新创建整个文件树的命令。我希望所有符号链接都是绝对的。我可以用 find 和 xargs 做到这一点吗?;-)
我需要转换视频,但我不知道它们在哪里,所以我需要find它们。我怎么能放弃的结果和输出文件名的FFmpeg用xargs?
我已经发现我可以用这个命令构造两个参数:
find . -iname "*.mov" -printf "%p %f\n"
Run Code Online (Sandbox Code Playgroud)
我在xargs手册中找不到任何相关内容。我想要这样的东西:
find . -iname "*.mov" -printf "%p %f\n" | xargs ffmpeg -i {param1} -f flv {param2}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我正在尝试跟踪 apache2。这些是我试图运行的命令。
ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace >> trace.txt
Run Code Online (Sandbox Code Playgroud)
我试过
(ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace ) >> trace.txt
Run Code Online (Sandbox Code Playgroud)
或者
ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace | xargs >> trace.txt
Run Code Online (Sandbox Code Playgroud) 根据我的理解,以下含义应该完全相同:
ls -1 | xargs file {}
ls -1 | xargs -I{} file {}
Run Code Online (Sandbox Code Playgroud)
如果未指定 -I 选项,则默认为 -I{}。
我想列出当前目录中的所有文件file并对每个文件运行命令。有些名字中有空格。但是,我注意到了差异。见下文:
$ ls -1
Hello World
$ ls -1 | xargs file {}
{}: ERROR: cannot open `{}' (No such file or directory)
Hello: ERROR: cannot open `Hello' (No such file or directory)
World: ERROR: cannot open `World' (No such file or directory)
$ ls -1 | xargs -I{} file {}
Hello World: directory
Run Code Online (Sandbox Code Playgroud)
明确指定 -I{} 后,文件名中的空格会按预期处理。