xargs - 将参数放在命令中的不同位置

xargs - place the argument in a different location in the command

假设我想编写一个脚本,该脚本 ls 每个文件名都有一个前缀。我试过这个

ls | xargs -n 1 echo prefix_

但结果是

prefix_ first_file
prefix_ second_file
...

如何删除前缀和文件名之间的 space? IE。如何让 xargs 将变量放在命令之后,而不使用 space? (或在任何其他地方)

解决方法:-I

-I 允许您命名您的论点并将其放在您喜欢的任何地方。例如

ls | xargs -n 1 -I {} echo prefix_{}

(用任意字符串替换{}