This question already has an answer here:
- How can I `alias sudo !!`? 5 answers
This is a follow-up question to
If you want to redo the same command with
sudo !! after doing a command like this:
You can use the global replace syntax to recall the command:
!!:gs/>/|sudo tee -a /
Use a space after the -a parameter.
This is the equivalent to sudo !! but helps you bypass sudo restrictions for the < and >. Because sudo does not allow you to use [<, >].
How can I put this into an alias on my
.bashrc so I can use it simple?
alias redo='!!:gs/>/|sudo tee -a /'
But this doesn't work, I get the error:
$ echo "sdfdsf">/path/file bash: /path/file: no permissions $ redo bash: /: Is a directory tee: /: Is a directory