Ban*_*ach 7 command-line bash line-editor
如果我想搬到一个名为longfile
来自/longpath/
于/longpath/morepath/
我可以这样做
mv (/longpath)/(longfile) $1/morepath/$2
Run Code Online (Sandbox Code Playgroud)
即我可以让 bash 知道它应该记住输入的特定部分,以便我以后可以在同一输入中重用它吗?(在上面的例子中,我使用了一个虚构的记忆命令,它通过用括号括起来和一个$
插入组内容的虚构重用命令来工作)
gle*_*man 23
你可以这样做:
mv /longpath/longfile !#:1:h/morepath/
Run Code Online (Sandbox Code Playgroud)
见https://www.gnu.org/software/bash/manual/bashref.html#History-Interaction
!#
是当前命令:1
是此命令中的第一个参数:h
是“头”——认为 dirname
/morepath/
将其附加到头部如果要更改“longfile”名称,例如添加“.txt”扩展名,您可以
mv /longpath/longfile !#:1:h/morepath/!#:1:t.txt
Run Code Online (Sandbox Code Playgroud)
就个人而言,我会用鼠标剪切和粘贴。在实践中,我从来没有比!!
or !$
or更复杂!!:gs/foo/bar/
Wil*_*ard 15
你也可以用大括号扩展来做到这一点:
mv /longpath/{,morepath/}longfile
Run Code Online (Sandbox Code Playgroud)
shell 将其展开,以便mv
命令将其视为与以下内容相同:
mv /longpath/longfile /longpath/morepath/longfile
Run Code Online (Sandbox Code Playgroud)
如果您希望在命令行中更有效地输入,您可能会发现各种 readline 快捷方式很有用。Readline 已经内置在你的 shell 中。对于您的特定情况,您可以猛拉/删除部分行,然后从 readline killiring 中召回它们。
此外,如果您将 EDITOR 环境变量设置为您最喜欢的编辑器,那么 Ctrl-X、Ctrl-E 会将您当前的命令行复制到编辑器窗口中,您可以在其中拥有所有编辑器功能来修改您的行。完成后,您保存/退出编辑器,该行将在您的 shell 中执行。
归档时间: |
|
查看次数: |
1410 次 |
最近记录: |