我该如何回忆前一个bash命令的参数?

本文翻译自:How can I recall the argument of the previous bash command?

Is there a way in Bash to recall the argument of the previous command? Bash中有没有一种方法可以调出前一个命令的参数?

I usually do vi file.c followed by gcc file.c . 我通常先执行vi file.c然后执行gcc file.c

Is there a way in Bash to recall the argument of the previous command? Bash中有没有一种方法可以调出前一个命令的参数?


#1楼

参考:https://stackoom.com/question/e91I/我该如何回忆前一个bash命令的参数


#2楼

If you know the number given in the history for a particular command, you can pretty much take any argument in that command using following terms. 如果您知道历史记录中特定命令的编号,则可以使用以下术语在该命令中使用几乎任何参数。

Use following to take the second argument from the third command in the history, 使用以下命令从历史记录中的第三个命令获取第二个参数,

!3:2

Use following to take the third argument from the fifth last command in the history, 使用以下命令从历史记录中的倒数第五个命令中提取第三个参数,

!-5:3

Using a minus sign, you ask it to traverse from the last command of the history. 使用减号,要求它从历史记录的最后一个命令开始遍历。


#3楼

You can use $_ or !$ to recall the last argument of the previous command. 您可以使用$_!$调用上一个命令的最后一个参数。

Also Alt + . 也是Alt + . can be used to recall the last argument of any of the previous commands. 可用于调用任何先前命令的最后一个参数。


#4楼

是的,您可以使用!$来调用前面命令的最后一个参数。


#5楼

If the previous command had two arguments, like this 如果前面的命令有两个参数,像这样

ls a.txt b.txt

and you wanted the first one, you could type 而您想要第一个,您可以输入

!:1

giving 给予

a.txt

Or if you wanted both, you could type 或者,如果您都想要,则可以输入

!:1-2

giving 给予

a.txt b.txt

You can extend this to any number of arguments, eg: 您可以将其扩展为任意数量的参数,例如:

!:10-12

#6楼

In the command line you can press esc - . 在命令行中,您可以按esc- or alt + . alt +

It cycles through the last argument of your previous commands. 它循环显示先前命令的最后一个参数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值