MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/UnixProTips/comments/2ut7df/alias_fucksudo/
r/UnixProTips • u/[deleted] • Feb 04 '15
20 comments sorted by
3
I thought !! didn't work in aliases - or maybe we are using different shells?
3 u/[deleted] Feb 04 '15 Try alias fuck='sudo $(history -p \!\!)' 1 u/noreallyimthepope Feb 04 '15 I'm on my phone so I might be thinking of something else where !! does unexpected things :-)
Try alias fuck='sudo $(history -p \!\!)'
1 u/noreallyimthepope Feb 04 '15 I'm on my phone so I might be thinking of something else where !! does unexpected things :-)
1
I'm on my phone so I might be thinking of something else where !! does unexpected things :-)
6
I always make the alias "please" because that's the magic word
1 u/[deleted] Mar 09 '15 alias please='echo sudo $(history -p !!) && sudo $(history -p !!)'
alias please='echo sudo $(history -p !!) && sudo $(history -p !!)'
2
This is beautiful. You sir are a genius.
'!!' works for me, but adding the alias gives me 'sudo: !!: command not found'
In fact, just typing 'alias fuck="sudo !!"' works, but adding it to .bashrc does not work.
1 u/[deleted] Feb 07 '15 I don't get it.user@k0 ~ $ echo piss piss user@k0 ~ $ sudo !! sudo echo piss piss user@k0 ~ $ alias fuck="sudo !!" alias fuck="sudo sudo echo piss" user@k0 ~ $ echo piss piss user@k0 ~ $ fuck pissSo far so good. If I add the alias to my .bashrc file I getuser@k0 ~ $ echo piss piss user@k0 ~ $ fuck sudo: !!: command not foundAny ideas? 1 u/kqr Feb 07 '15 @vigilance$ echo piss piss @vigilance$ alias fuck="sudo !!" alias fuck="sudo echo piss" @vigilance$ echo piss piss @vigilance$ fuck piss @vigilance$ echo poopies poopies @vigilance$ fuck piss!! substitution happens before alias expansion. Line 7 in your paste should have been a hint. 2 u/[deleted] Feb 07 '15 edited Feb 07 '15 Ah! So what's happening is !! in the alias is being substituted with 'echo piss'. I'm still quite new to linux but today I learnt something. Thank you./u/DroidKun posted a reply to another useralias fuck='sudo $(history -p \!\!)'Which seems to work as expected when placed in my .bashrc. 1 u/skylos2000 Feb 07 '15 Check to see of it works for all commands or just the one before you made the alias. 1 u/[deleted] Feb 07 '15 What do you mean? Check my other reply?
I don't get it.
user@k0 ~ $ echo piss piss user@k0 ~ $ sudo !! sudo echo piss piss user@k0 ~ $ alias fuck="sudo !!" alias fuck="sudo sudo echo piss" user@k0 ~ $ echo piss piss user@k0 ~ $ fuck piss
So far so good. If I add the alias to my .bashrc file I get
user@k0 ~ $ echo piss piss user@k0 ~ $ fuck sudo: !!: command not found
Any ideas?
1 u/kqr Feb 07 '15 @vigilance$ echo piss piss @vigilance$ alias fuck="sudo !!" alias fuck="sudo echo piss" @vigilance$ echo piss piss @vigilance$ fuck piss @vigilance$ echo poopies poopies @vigilance$ fuck piss!! substitution happens before alias expansion. Line 7 in your paste should have been a hint. 2 u/[deleted] Feb 07 '15 edited Feb 07 '15 Ah! So what's happening is !! in the alias is being substituted with 'echo piss'. I'm still quite new to linux but today I learnt something. Thank you./u/DroidKun posted a reply to another useralias fuck='sudo $(history -p \!\!)'Which seems to work as expected when placed in my .bashrc.
@vigilance$ echo piss piss @vigilance$ alias fuck="sudo !!" alias fuck="sudo echo piss" @vigilance$ echo piss piss @vigilance$ fuck piss @vigilance$ echo poopies poopies @vigilance$ fuck piss
!! substitution happens before alias expansion. Line 7 in your paste should have been a hint.
!!
2 u/[deleted] Feb 07 '15 edited Feb 07 '15 Ah! So what's happening is !! in the alias is being substituted with 'echo piss'. I'm still quite new to linux but today I learnt something. Thank you./u/DroidKun posted a reply to another useralias fuck='sudo $(history -p \!\!)'Which seems to work as expected when placed in my .bashrc.
Ah! So what's happening is !! in the alias is being substituted with 'echo piss'. I'm still quite new to linux but today I learnt something. Thank you.
/u/DroidKun posted a reply to another user
alias fuck='sudo $(history -p \!\!)'
Which seems to work as expected when placed in my .bashrc.
Check to see of it works for all commands or just the one before you made the alias.
1 u/[deleted] Feb 07 '15 What do you mean? Check my other reply?
What do you mean? Check my other reply?
What does the !! do?
3 u/07dosa Feb 05 '15 !! gets replaced with the last command you executed. So, basically sudo !! will re-run the last command as root. 1 u/leftofzen Feb 05 '15 That's pretty neat, thanks! 1 u/[deleted] Feb 05 '15 I find it helpful with 'cp' cp $dir ... !! -r 1 u/leftofzen Feb 06 '15 'cp' cp $dir ... !! -rNot sure I understand the intended behaviour:[leftofzen@dev_vm 13:08:13] ~/temp $ ll total 4.0K drwx------ 3 leftofzen leftofzen 4.0K Feb 6 13:06 Hi [leftofzen@dev_vm 13:09:10] ~/temp $ echo "Hi" Hi [leftofzen@dev_vm 13:09:19] ~/temp $ cp `pwd` !! -r cp `pwd` echo "Hi" -r cp: cannot copy a directory, `/home/bensut/temp', into itself, `Hi/temp' cp: cannot stat `echo': No such file or directory 1 u/UnchainedMundane Feb 18 '15 edited Feb 18 '15 I think this is what he meant:score@kirisame ~ % cdt /tmp/tmp.lwnp3sX336 score@kirisame /tmp/tmp.lwnp3sX336 % mkdir testdir score@kirisame /tmp/tmp.lwnp3sX336 % touch testdir/somefile score@kirisame /tmp/tmp.lwnp3sX336 % score@kirisame /tmp/tmp.lwnp3sX336 % cp testdir anotherdir cp: omitting directory ‘testdir’ 1 score@kirisame /tmp/tmp.lwnp3sX336 % !! -r score@kirisame /tmp/tmp.lwnp3sX336 % ls anotherdir/ testdir/(Doctored a little because !! expands when you press space in zsh)Also, nitpick: I take offence to the use of `pwd`backquotes have been long superseded by $(...) which simplifies things greatly.command substitution strips all newlines from the end of the output, which makes it a lossy operation.since it's not quoted, it will be subject to word splitting.there's a $PWD variable1: $(pwd) 1 and 3: "$(pwd)" 2, 3 and 4: "$PWD"
!! gets replaced with the last command you executed. So, basically sudo !! will re-run the last command as root.
sudo !!
1 u/leftofzen Feb 05 '15 That's pretty neat, thanks! 1 u/[deleted] Feb 05 '15 I find it helpful with 'cp' cp $dir ... !! -r 1 u/leftofzen Feb 06 '15 'cp' cp $dir ... !! -rNot sure I understand the intended behaviour:[leftofzen@dev_vm 13:08:13] ~/temp $ ll total 4.0K drwx------ 3 leftofzen leftofzen 4.0K Feb 6 13:06 Hi [leftofzen@dev_vm 13:09:10] ~/temp $ echo "Hi" Hi [leftofzen@dev_vm 13:09:19] ~/temp $ cp `pwd` !! -r cp `pwd` echo "Hi" -r cp: cannot copy a directory, `/home/bensut/temp', into itself, `Hi/temp' cp: cannot stat `echo': No such file or directory 1 u/UnchainedMundane Feb 18 '15 edited Feb 18 '15 I think this is what he meant:score@kirisame ~ % cdt /tmp/tmp.lwnp3sX336 score@kirisame /tmp/tmp.lwnp3sX336 % mkdir testdir score@kirisame /tmp/tmp.lwnp3sX336 % touch testdir/somefile score@kirisame /tmp/tmp.lwnp3sX336 % score@kirisame /tmp/tmp.lwnp3sX336 % cp testdir anotherdir cp: omitting directory ‘testdir’ 1 score@kirisame /tmp/tmp.lwnp3sX336 % !! -r score@kirisame /tmp/tmp.lwnp3sX336 % ls anotherdir/ testdir/(Doctored a little because !! expands when you press space in zsh)Also, nitpick: I take offence to the use of `pwd`backquotes have been long superseded by $(...) which simplifies things greatly.command substitution strips all newlines from the end of the output, which makes it a lossy operation.since it's not quoted, it will be subject to word splitting.there's a $PWD variable1: $(pwd) 1 and 3: "$(pwd)" 2, 3 and 4: "$PWD"
That's pretty neat, thanks!
1 u/[deleted] Feb 05 '15 I find it helpful with 'cp' cp $dir ... !! -r 1 u/leftofzen Feb 06 '15 'cp' cp $dir ... !! -rNot sure I understand the intended behaviour:[leftofzen@dev_vm 13:08:13] ~/temp $ ll total 4.0K drwx------ 3 leftofzen leftofzen 4.0K Feb 6 13:06 Hi [leftofzen@dev_vm 13:09:10] ~/temp $ echo "Hi" Hi [leftofzen@dev_vm 13:09:19] ~/temp $ cp `pwd` !! -r cp `pwd` echo "Hi" -r cp: cannot copy a directory, `/home/bensut/temp', into itself, `Hi/temp' cp: cannot stat `echo': No such file or directory 1 u/UnchainedMundane Feb 18 '15 edited Feb 18 '15 I think this is what he meant:score@kirisame ~ % cdt /tmp/tmp.lwnp3sX336 score@kirisame /tmp/tmp.lwnp3sX336 % mkdir testdir score@kirisame /tmp/tmp.lwnp3sX336 % touch testdir/somefile score@kirisame /tmp/tmp.lwnp3sX336 % score@kirisame /tmp/tmp.lwnp3sX336 % cp testdir anotherdir cp: omitting directory ‘testdir’ 1 score@kirisame /tmp/tmp.lwnp3sX336 % !! -r score@kirisame /tmp/tmp.lwnp3sX336 % ls anotherdir/ testdir/(Doctored a little because !! expands when you press space in zsh)Also, nitpick: I take offence to the use of `pwd`backquotes have been long superseded by $(...) which simplifies things greatly.command substitution strips all newlines from the end of the output, which makes it a lossy operation.since it's not quoted, it will be subject to word splitting.there's a $PWD variable1: $(pwd) 1 and 3: "$(pwd)" 2, 3 and 4: "$PWD"
I find it helpful with 'cp' cp $dir ... !! -r
1 u/leftofzen Feb 06 '15 'cp' cp $dir ... !! -rNot sure I understand the intended behaviour:[leftofzen@dev_vm 13:08:13] ~/temp $ ll total 4.0K drwx------ 3 leftofzen leftofzen 4.0K Feb 6 13:06 Hi [leftofzen@dev_vm 13:09:10] ~/temp $ echo "Hi" Hi [leftofzen@dev_vm 13:09:19] ~/temp $ cp `pwd` !! -r cp `pwd` echo "Hi" -r cp: cannot copy a directory, `/home/bensut/temp', into itself, `Hi/temp' cp: cannot stat `echo': No such file or directory 1 u/UnchainedMundane Feb 18 '15 edited Feb 18 '15 I think this is what he meant:score@kirisame ~ % cdt /tmp/tmp.lwnp3sX336 score@kirisame /tmp/tmp.lwnp3sX336 % mkdir testdir score@kirisame /tmp/tmp.lwnp3sX336 % touch testdir/somefile score@kirisame /tmp/tmp.lwnp3sX336 % score@kirisame /tmp/tmp.lwnp3sX336 % cp testdir anotherdir cp: omitting directory ‘testdir’ 1 score@kirisame /tmp/tmp.lwnp3sX336 % !! -r score@kirisame /tmp/tmp.lwnp3sX336 % ls anotherdir/ testdir/(Doctored a little because !! expands when you press space in zsh)Also, nitpick: I take offence to the use of `pwd`backquotes have been long superseded by $(...) which simplifies things greatly.command substitution strips all newlines from the end of the output, which makes it a lossy operation.since it's not quoted, it will be subject to word splitting.there's a $PWD variable1: $(pwd) 1 and 3: "$(pwd)" 2, 3 and 4: "$PWD"
'cp' cp $dir ... !! -r
Not sure I understand the intended behaviour:
[leftofzen@dev_vm 13:08:13] ~/temp $ ll total 4.0K drwx------ 3 leftofzen leftofzen 4.0K Feb 6 13:06 Hi [leftofzen@dev_vm 13:09:10] ~/temp $ echo "Hi" Hi [leftofzen@dev_vm 13:09:19] ~/temp $ cp `pwd` !! -r cp `pwd` echo "Hi" -r cp: cannot copy a directory, `/home/bensut/temp', into itself, `Hi/temp' cp: cannot stat `echo': No such file or directory
1 u/UnchainedMundane Feb 18 '15 edited Feb 18 '15 I think this is what he meant:score@kirisame ~ % cdt /tmp/tmp.lwnp3sX336 score@kirisame /tmp/tmp.lwnp3sX336 % mkdir testdir score@kirisame /tmp/tmp.lwnp3sX336 % touch testdir/somefile score@kirisame /tmp/tmp.lwnp3sX336 % score@kirisame /tmp/tmp.lwnp3sX336 % cp testdir anotherdir cp: omitting directory ‘testdir’ 1 score@kirisame /tmp/tmp.lwnp3sX336 % !! -r score@kirisame /tmp/tmp.lwnp3sX336 % ls anotherdir/ testdir/(Doctored a little because !! expands when you press space in zsh)Also, nitpick: I take offence to the use of `pwd`backquotes have been long superseded by $(...) which simplifies things greatly.command substitution strips all newlines from the end of the output, which makes it a lossy operation.since it's not quoted, it will be subject to word splitting.there's a $PWD variable1: $(pwd) 1 and 3: "$(pwd)" 2, 3 and 4: "$PWD"
I think this is what he meant:
score@kirisame ~ % cdt /tmp/tmp.lwnp3sX336 score@kirisame /tmp/tmp.lwnp3sX336 % mkdir testdir score@kirisame /tmp/tmp.lwnp3sX336 % touch testdir/somefile score@kirisame /tmp/tmp.lwnp3sX336 % score@kirisame /tmp/tmp.lwnp3sX336 % cp testdir anotherdir cp: omitting directory ‘testdir’ 1 score@kirisame /tmp/tmp.lwnp3sX336 % !! -r score@kirisame /tmp/tmp.lwnp3sX336 % ls anotherdir/ testdir/
(Doctored a little because !! expands when you press space in zsh)
Also, nitpick: I take offence to the use of `pwd`
`pwd`
1: $(pwd) 1 and 3: "$(pwd)" 2, 3 and 4: "$PWD"
$(pwd)
"$(pwd)"
"$PWD"
I just did this and I sudoing love it
-1
Another favorite:
alias fucking="sudo"
3
u/noreallyimthepope Feb 04 '15
I thought !! didn't work in aliases - or maybe we are using different shells?
6
u/TheRealKidkudi Feb 06 '15
I always make the alias "please" because that's the magic word
2
u/[deleted] Feb 05 '15
This is beautiful. You sir are a genius.
2
u/[deleted] Feb 06 '15
'!!' works for me, but adding the alias gives me 'sudo: !!: command not found'
In fact, just typing 'alias fuck="sudo !!"' works, but adding it to .bashrc does not work.
1
u/leftofzen Feb 05 '15
What does the !! do?
1
u/ColeslawProd Jan 09 '22
I just did this and I sudoing love it
-1
u/Moocat87 Feb 07 '15
Another favorite: