如何在不重新键入的情况下使用上一个命令的一些参数

May*_*hux 6 command-line

Back to Run a command with the argument from the last command。这篇文章解释了如何在新命令中使用以前的命令参数。

我的问题是如何在这些参数之间进行迭代?

例如:只是例子不需要这个

假设我创建了两个目录 dir1 和 dir2

mkdir dir1 dir2
Run Code Online (Sandbox Code Playgroud)

我想移动dir1dir2无需再次重新输入参数。在处理复杂的参数或长路径时,这是非常少的。

需要最简单的命令

更新

假设我有一个命令

mkdir arg1 arg2 arg3 arg4 ... argn
Run Code Online (Sandbox Code Playgroud)

我想移动arg2argn

May*_*hux 7

我发现了一些有趣的使用选项!

要获取上一个命令的参数,您可以使用:

!^        gives the first argument
!:n       gives the nth argument
!*        gives all the arguments
Run Code Online (Sandbox Code Playgroud)

所以在这种情况下

mkdir arg1 arg2 arg3 arg4 ... argn
Run Code Online (Sandbox Code Playgroud)

移动arg2arg5 例如使用:

mv !:2  !:5
Run Code Online (Sandbox Code Playgroud)