Any way to recall the file of previous cmd? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • What does !$ mean?

    3 answers



  • Shell: How do I get the last argument the previous command when it was detached?

    4 answers



Frequently I’ll have to do some digging around to figure out what I’m doing on linux, involving quite a bit of ‘’, ‘ls -la’, ‘cd’, ‘cat’, and ‘vim’



Is there any way to quickly reuse the file/target of the previous command?



e.g. I have to look around for a file, say with ls, and when I’ve found it I’ll need to use it with a program like cat or vim. So let’s say I’ve got ‘ls -la /some/path/SomeName’ and hit , say I’ve drilled down to where this is the file I was looking for. What I’d like to do is some kind of ‘!!’ Like when you forget to use sudo; Say I really want to use ‘cat’ but had been searching around with ‘ls’ and ‘’ - or I’ve been searching around with ‘cat’, up-arrow and continuing to refine my ‘cat /file/path/‘ and then when I’ve found what I’m looking for I’ll want to edit that file



I’d like to be able to do something like ‘cat !!’ or ‘vim !!’










share|improve this question













marked as duplicate by muru, Stephen Rauch, G-Man, Satō Katsura, αғsнιη Oct 2 '17 at 3:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Also see: askubuntu.com/q/304830/158442
    – muru
    Oct 2 '17 at 0:25














up vote
0
down vote

favorite













This question already has an answer here:



  • What does !$ mean?

    3 answers



  • Shell: How do I get the last argument the previous command when it was detached?

    4 answers



Frequently I’ll have to do some digging around to figure out what I’m doing on linux, involving quite a bit of ‘’, ‘ls -la’, ‘cd’, ‘cat’, and ‘vim’



Is there any way to quickly reuse the file/target of the previous command?



e.g. I have to look around for a file, say with ls, and when I’ve found it I’ll need to use it with a program like cat or vim. So let’s say I’ve got ‘ls -la /some/path/SomeName’ and hit , say I’ve drilled down to where this is the file I was looking for. What I’d like to do is some kind of ‘!!’ Like when you forget to use sudo; Say I really want to use ‘cat’ but had been searching around with ‘ls’ and ‘’ - or I’ve been searching around with ‘cat’, up-arrow and continuing to refine my ‘cat /file/path/‘ and then when I’ve found what I’m looking for I’ll want to edit that file



I’d like to be able to do something like ‘cat !!’ or ‘vim !!’










share|improve this question













marked as duplicate by muru, Stephen Rauch, G-Man, Satō Katsura, αғsнιη Oct 2 '17 at 3:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Also see: askubuntu.com/q/304830/158442
    – muru
    Oct 2 '17 at 0:25












up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • What does !$ mean?

    3 answers



  • Shell: How do I get the last argument the previous command when it was detached?

    4 answers



Frequently I’ll have to do some digging around to figure out what I’m doing on linux, involving quite a bit of ‘’, ‘ls -la’, ‘cd’, ‘cat’, and ‘vim’



Is there any way to quickly reuse the file/target of the previous command?



e.g. I have to look around for a file, say with ls, and when I’ve found it I’ll need to use it with a program like cat or vim. So let’s say I’ve got ‘ls -la /some/path/SomeName’ and hit , say I’ve drilled down to where this is the file I was looking for. What I’d like to do is some kind of ‘!!’ Like when you forget to use sudo; Say I really want to use ‘cat’ but had been searching around with ‘ls’ and ‘’ - or I’ve been searching around with ‘cat’, up-arrow and continuing to refine my ‘cat /file/path/‘ and then when I’ve found what I’m looking for I’ll want to edit that file



I’d like to be able to do something like ‘cat !!’ or ‘vim !!’










share|improve this question














This question already has an answer here:



  • What does !$ mean?

    3 answers



  • Shell: How do I get the last argument the previous command when it was detached?

    4 answers



Frequently I’ll have to do some digging around to figure out what I’m doing on linux, involving quite a bit of ‘’, ‘ls -la’, ‘cd’, ‘cat’, and ‘vim’



Is there any way to quickly reuse the file/target of the previous command?



e.g. I have to look around for a file, say with ls, and when I’ve found it I’ll need to use it with a program like cat or vim. So let’s say I’ve got ‘ls -la /some/path/SomeName’ and hit , say I’ve drilled down to where this is the file I was looking for. What I’d like to do is some kind of ‘!!’ Like when you forget to use sudo; Say I really want to use ‘cat’ but had been searching around with ‘ls’ and ‘’ - or I’ve been searching around with ‘cat’, up-arrow and continuing to refine my ‘cat /file/path/‘ and then when I’ve found what I’m looking for I’ll want to edit that file



I’d like to be able to do something like ‘cat !!’ or ‘vim !!’





This question already has an answer here:



  • What does !$ mean?

    3 answers



  • Shell: How do I get the last argument the previous command when it was detached?

    4 answers







linux bash shell command-line alias






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 2 '17 at 0:14









EE1337

11




11




marked as duplicate by muru, Stephen Rauch, G-Man, Satō Katsura, αғsнιη Oct 2 '17 at 3:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by muru, Stephen Rauch, G-Man, Satō Katsura, αғsнιη Oct 2 '17 at 3:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • Also see: askubuntu.com/q/304830/158442
    – muru
    Oct 2 '17 at 0:25
















  • Also see: askubuntu.com/q/304830/158442
    – muru
    Oct 2 '17 at 0:25















Also see: askubuntu.com/q/304830/158442
– muru
Oct 2 '17 at 0:25




Also see: askubuntu.com/q/304830/158442
– muru
Oct 2 '17 at 0:25










2 Answers
2






active

oldest

votes

















up vote
0
down vote













If you are using bash with emacs key bindings then you need to know about ESC period (aka dot aka full stop). You can also use $_






share|improve this answer



























    up vote
    0
    down vote













    It sounds like you're looking for the "history event" syntax for arguments. You mention !!, which repeats the whole previous command. But, you can also refer to specific arguments from that command, or all of them. !^ will get you the first argument; !$ will get you the last one (think vi commands or regular expression syntax) and !* will get you all of the arguments (but not the command itself).



    So, after finding your file with ls -l /etc/passwd, you could do cat !$ to display its contents.






    share|improve this answer



























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      If you are using bash with emacs key bindings then you need to know about ESC period (aka dot aka full stop). You can also use $_






      share|improve this answer
























        up vote
        0
        down vote













        If you are using bash with emacs key bindings then you need to know about ESC period (aka dot aka full stop). You can also use $_






        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          If you are using bash with emacs key bindings then you need to know about ESC period (aka dot aka full stop). You can also use $_






          share|improve this answer












          If you are using bash with emacs key bindings then you need to know about ESC period (aka dot aka full stop). You can also use $_







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 2 '17 at 0:24









          icarus

          4,7781725




          4,7781725






















              up vote
              0
              down vote













              It sounds like you're looking for the "history event" syntax for arguments. You mention !!, which repeats the whole previous command. But, you can also refer to specific arguments from that command, or all of them. !^ will get you the first argument; !$ will get you the last one (think vi commands or regular expression syntax) and !* will get you all of the arguments (but not the command itself).



              So, after finding your file with ls -l /etc/passwd, you could do cat !$ to display its contents.






              share|improve this answer
























                up vote
                0
                down vote













                It sounds like you're looking for the "history event" syntax for arguments. You mention !!, which repeats the whole previous command. But, you can also refer to specific arguments from that command, or all of them. !^ will get you the first argument; !$ will get you the last one (think vi commands or regular expression syntax) and !* will get you all of the arguments (but not the command itself).



                So, after finding your file with ls -l /etc/passwd, you could do cat !$ to display its contents.






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  It sounds like you're looking for the "history event" syntax for arguments. You mention !!, which repeats the whole previous command. But, you can also refer to specific arguments from that command, or all of them. !^ will get you the first argument; !$ will get you the last one (think vi commands or regular expression syntax) and !* will get you all of the arguments (but not the command itself).



                  So, after finding your file with ls -l /etc/passwd, you could do cat !$ to display its contents.






                  share|improve this answer












                  It sounds like you're looking for the "history event" syntax for arguments. You mention !!, which repeats the whole previous command. But, you can also refer to specific arguments from that command, or all of them. !^ will get you the first argument; !$ will get you the last one (think vi commands or regular expression syntax) and !* will get you all of the arguments (but not the command itself).



                  So, after finding your file with ls -l /etc/passwd, you could do cat !$ to display its contents.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 2 '17 at 0:40









                  mattdm

                  27.1k1170109




                  27.1k1170109












                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay