IfFor example if I want to create a file and enter text in one line I can redirect the output into a file with the use of the > operator:
echo "something" > /path/foobar
but if I don't have access to the folder /path/ and need sudo priviledges, How can I achieve this same command as a normal user with sudo rights?
I tried
sudo echo "something" > /path/foobar
but that doesn't work, because the sudo only counts for the edit but not for the right part
of the >
Sure, I could become root before with sudo su or use tee instead:
echo "something" | sudo tee /path/foobar
But I would like to find a solution where I can work with the last line as replacement via !!
sudo !!
Isn't there a way to "recycle" the last line and just add sudo in front?
maybe with an option like
sudo --command='!!'