xargs 我已经有完整的命令集
我有一个这样的文件。
rm a.txt
mkdir foo
cp a.doc docs
我习惯了 xargs 但以下命令没有执行任何操作。
cat commands.txt | xargs -l1
I have a file like this.
rm a.txt
mkdir foo
cp a.doc docs
I am used to xargs but following command is not doing anything.
cat commands.txt | xargs -l1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你做错了!如果你的文件全是shell命令,就把它当成shell脚本。
然后在命令行上,
chmod u+xcommands.txt
shell脚本的“事实上”命名约定以扩展名
.sh
结尾,尽管它可以是任何东西。所以尝试将你的脚本命名为“.sh”扩展名you are doing it wrong! if your file is all shell commands, treat it as a shell script.
then on command line ,
chmod u+x commands.txt
the "defacto" naming convention for shell script ends with extension
.sh
, although it can be anything. So try to name your script as ".sh" extension呃:
Erm :
如果您不需要使其可执行,请在当前 shell 中获取它:
bash/ksh/...:
。命令.txt
csh/...:
源命令.txt
If you don't need to make it executable, source it in your current shell:
bash/ksh/...:
. commands.txt
csh/...:
source commands.txt
如果您的命令不在文件中,而是程序的输出,您可以使用 GNU Parallel http:// /www.gnu.org/software/parallel/:
如果命令可以并行运行(即不依赖于彼此来完成),您甚至可以这样做:
If you commands are not in a file but the output from a program you may do use GNU Parallel http://www.gnu.org/software/parallel/:
If the commands can be run in parallel (i.e. do not depend on eachother to complete) you can even do: