sudo !! equivalent on Windows cmd
13,585
You can try gsudo
, a sudo for windows that allows either to run commands with elevated permissions on the current console, to elevate the current shell, or launch elevated commands on a new console.
Examples
gsudo {command} [arguments]
gsudo md "C:\Program Files\MyApp"
# spawn the current shell (Cmd/PowerShell/PSCore) in a new console window
gsudo -n
# spawn PowerShell in a new console window
gsudo -n powershell
UPDATE:
Since gsudo v0.7.1
, it supports the Unix-sudo Bang Bang syntax, on CMD:
-
gsudo !!
elevates the last executed command. -
gsudo !prefix
elevates the last executed command that starts with prefix. -
gsudo !?infix
elevates the last executed command that contains infix.
Installation
- Install with Scoop:
scoop install gsudo
- Install with Chocolatey:
choco install gsudo
Manuall installation methods, docs & source at https://github.com/gerardog/gsudo
Related videos on Youtube
Author by
Outman
Certified C# Programmer and a Microsoft Certified Professional.
Updated on September 18, 2022Comments
-
Outman over 1 year
I'm looking for a cmd.exe equivalent to Linux's
sudo !!
and other bang-commands such as!x
,!?x
,!!:p
and!!*
mentioned here.-
phuclv over 5 yearsI 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 tosudo
in Windows. Powershell is much more powerful and you can do the above things withGet-History
-
NotepadPlusPlus PRO over 5 yearsYou can try
cygwin
if you really miss Linux commands. -
Outman over 5 years@Cricrazy cygwin is great, but my use case exclusively involves
cmd
. -
RaSedg almost 4 yearsThe just released gsudo v0.7.1 suports
!!
on CMD. :)
-
-
RaSedg about 4 yearsUnfortunately this doesn't works in Windows 10. It will run as that user but without elevation/admin rights.
-
harrymc about 4 years@GerardoGrignoli: You are right that a Linux user will expect this, although Windows is different. I added links to some some self-elevation methods.
-
pooter03 over 2 yearsBrilliant! Especially fun as I used winget to install it for that extra-pseudo 'nux feel. :)