Add Sudo to Your Last Bash Command With "!!" Dodaj Sudo to Your Last Bash ukaz s "!" Syntax Sintaksa
How often have you typed in a command in your linux shell, and then realized that you forgot to type sudo, so you end up with an error or editing the dreaded read-only file? Kako pogosto ste vnesli v vašem linux ukaz v lupini, nato pa spoznal, da si pozabil na vrsto sudo, tako da boste na koncu z napako ali urejanje bal samo za branje datoteke? This happens to me much more than I'd like to admit, so I'm writing about it. To se zgodi, da mi veliko več, kot bi rad priznam, da pišem o tem.
You have a couple of options, the easiest one is to just use !! Imate nekaj možnosti, ena je najlažji šele raba! to tell bash to use the last command. povedati, bash za uporabo zadnji ukaz.
For instance, if you tried to type this, you'd get an error that you are editing a read-only file: Na primer, če ste poskusili s tem tipom, bi vi zaslužiti zmota to urejate samo za branje datoteke:
vi /etc/apt/sources.list vi / etc / apt / sources.list
Once that happens, then you can just use this command: Ko se to zgodi, torej vi moči šele raba to zapoved:
sudo !! sudo!
Which bash will then expand into this command: Kateri bash bo nato razširi v ta ukaz:
sudo vi /etc/apt/sources.list sudo vi / etc / apt / sources.list
Screenshot of this in action: Screenshot to v praksi:

An alternative method would be to just hit the up arrow key, hit either the Home key or Ctrl+A, and then type sudo. Alternativno metodo bi bila šele zadeti puščico gor ključ, zadeti niti ključ Home ali Ctrl + A in nato vnesite sudo.

Daily Email Updates Dnevni Email Updates
You can get our how-to articles in your inbox each day for free. Lahko dobite našo kako do člankov v vašo mapo »Prejeto vsak dan brezplačno. Just enter your name and email below: Preprosto vpišite vaše ime in e-pošto spodaj:



Thanks. Hvala.
Thanks you very much, this is very usefull. Hvala lepa, to je zelo koristen.
That is surprisingly useful, I like the way you give us more than one way to do a lot of these things, the alternative methods can be useful for other stuff too To je presenetljivo uporaben, mi je všeč način, ki nam jih več kot en način, da to veliko teh stvari, lahko alternativne metode, uporabne za druge stvari preveč
the !! ! also works with other commands like man sodeluje tudi z drugimi ukazi, kot človek
Just wondering if it would be possible to create a script that would execute this or an alias in ~/.bashrc or something. Šele začuden če bi bilo mogoče ustvariti skript, ki bi izvršiti to, ali alias v ~ /. Bashrc ali kaj podobnega. I'm super-lazy so “sudo !!” is too many characters to type. Jaz sem super-leni tako "sudo!" Je preveč znakov na vrsto. Why not something like “sss” The issue is that when I try a script or alias, it doesn't execute the previous command. Zakaj ne bi nekaj podobnega "sss", problem je, da ko sem se scenarij ali drugo ime, ne izvršiti prejšnji ukaz. Any ideas? Vse ideje?
I've been working on heavily modding my Ubuntu desktop, and whatever I google, howtogeek.com comes up as a top result. Sem delal na zelo modding svoj Ubuntu pult, in karkoli sem google, howtogeek.com pride gor kot top rezultat. Your suggestions, tips, and tricks are spot-on and incredibly useful, and I just wanted to say thank you. Vaši predlogi, nasveti in zvijače so na kraju samem in neverjetno koristna, in sem hotel reči hvala.
great, i love this one velik, jaz ljubezen to ena
no emacs love, huh? no Emacs ljubezen, kajne?
This is so useful – thanks a lot. To je tako uporabno - hvala veliko. It's *SO* annoying to have go all the way to the beginning of a command to add sudo after you forgot to the first time. It's * SO * siten, da gredo vse do začetka ukaz dodati sudo potem ste pozabili, da prvič.
Yes!!! Ja! This is one of the most useful things I have ever heard To je eden izmed najbolj uporabnih stvari, ki sem jih kdaj slišal
Thanks! Hvala! This would help me a lot. To bi mi veliko pomagal.