0

I'm looking for a cmd.exe equivalent to Linux's sudo !! and other bang-commands such as !x, !?x, !!:p and !!* mentioned here.

  • 1
    I don't think so, cmd is an ancient beast with a lot of unfixable problems due to backward compatibility. You don't even have an equivalent to sudo in Windows. Powershell is much more powerful and you can do the above things with Get-History – phuclv Dec 6 '18 at 14:19
  • You can try cygwin if you really miss Linux commands. – Cricrazy Dec 6 '18 at 14:48
  • @Cricrazy cygwin is great, but my use case exclusively involves cmd. – Outman Dec 6 '18 at 15:30
0

The sudo equivalent is the runas command, used to execute a program under a different user account.

Example of use :

runas /user:an-administator-account "cmd.exe /C mycommand"
0

To answer the other half of the question, you can use doskey to view or parse the command history. Doskey is installed and active by default on all supported versions of Windows.

This shows your command history:

doskey /history

You could parse and push the results to runas, but wrapping it in a batch file would make it a lot simpler at the prompt.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.