← 返回命令列表

Linux command

apply 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Apply a command to each argument

apply [command] [arg1] [arg2] [arg3]

Apply a command using placeholders

apply "diff %1 %2" [file1] [file2] [file3] [file4]

Apply with a specific number of arguments per invocation

apply -2 diff [file1] [file2] [file3] [file4]

Apply echo to each file

apply echo *

Apply rm to files matching pattern

apply rm [file1] [file2] [file3]

说明

apply runs a command repeatedly, passing a specified number of arguments to each invocation. It provides a simple alternative to xargs or shell loops for applying a command across multiple arguments. By default, apply passes one argument at a time to the command. With -n 2, it groups arguments in pairs, useful for commands like diff or cmp that take two files. The %n placeholders allow flexible positioning of arguments within the command string. When the command contains spaces or special characters, it should be quoted. Without placeholders, arguments are appended to the end of the command.

参数

-a _char_
Use _char_ as the placeholder character instead of the default %.
-n _num_
Pass _num_ arguments to each command invocation. The default is 1.
%n
In the command string, %1, %2, etc. refer to the 1st, 2nd, etc. arguments in each group.

FAQ

What is the apply command used for?

apply runs a command repeatedly, passing a specified number of arguments to each invocation. It provides a simple alternative to xargs or shell loops for applying a command across multiple arguments. By default, apply passes one argument at a time to the command. With -n 2, it groups arguments in pairs, useful for commands like diff or cmp that take two files. The %n placeholders allow flexible positioning of arguments within the command string. When the command contains spaces or special characters, it should be quoted. Without placeholders, arguments are appended to the end of the command.

How do I run a basic apply example?

Run `apply [command] [arg1] [arg2] [arg3]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -a _char_ do in apply?

Use _char_ as the placeholder character instead of the default %.