Gonçalo Borges
Gonçalo Borges

Reputation: 49

How to execute one specific command from history command?

Example:

PS C:\Users\user01\Desktop\jogoForcaMVCSpring> history
    Id CommandLine
    -- -----------
    1 history
    2 ls
    3 cd ..
    4 cd .\jogoForcaMVCSpring
PS C:\Users\user01\Desktop\jogoForcaMVCSpring>

How can I execute the exact command with the Id 2?

Maybe something like...

PS C:\Users\user01\Desktop\jogoForcaMVCSpring> execute history command -id 2

Upvotes: 0

Views: 51

Answers (1)

Gonçalo Borges
Gonçalo Borges

Reputation: 49

Got it:

invoke-history -id 2

After seeing the "get-help history", I noticed a "related link": invoke-history

PS C:\Users\user01\Desktop\jogoForcaMVCSpring> history
   Id CommandLine
   -- -----------
   1 history
   2 ls
   3 cd ..
   4 cd .\jogoForcaMVCSpring
   5 history
   6 get-help history
   7 get-help invoke-history -examples
PS C:\Users\user01\Desktop\jogoForcaMVCSpring> invoke-history -id 2
ls
Directory: C:\Users\user01\Desktop\jogoForcaMVCSpring
Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        22/09/2016     13:56            src
d----        23/09/2016     14:59            target
-a---        22/09/2016     15:14          7 .gitignore
-a---        19/09/2016     15:16       6308 pom.xml
-a---        22/09/2016     16:08        308 README.txt
PS C:\Users\user01\Desktop\jogoForcaMVCSpring>

Upvotes: 1

Related Questions