Using bash history to get a previous command, copy it and then 'run' it but with the command commented

后端 未结 10 1146
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 20:34

Just a question to improve my bash skills. I always do this:

$ history | grep some_long_command

...
...
123 some_long_command1.........
124 some_l         


        
10条回答
  •  死守一世寂寞
    2021-01-29 21:10

    Actually, you can just append :p to the command to print it without actually running it. For example:

    $ ls -la
    $ !!:p
    

    Will print out ls -la as the previous command without running it, and you can just press (up) to find it and edit it.

    You can also do

    !123:p
    

    to print out the 123rd command as your previous command.

提交回复
热议问题