Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k
deleted 51 characters in body
Source Link
rubo77
  • 30.6k
  • 46
  • 141
  • 217

Redirect the output into Execute a fileline of commands with one sudo

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='!!'

Redirect the output into a file with sudo

If I want to create a file and enter text in one line I can use 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 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 !!

Isn't there a way to "recycle" the last line and just add sudo in front?

maybe with an option like

sudo --command='!!'

Execute a line of commands with one sudo

For 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?

added 226 characters in body
Source Link
rubo77
  • 30.6k
  • 46
  • 141
  • 217

If I want to create a file and enter text in one line I can use 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 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 !!

Isn't there a way to "recycle" the last line and just add sudo in front?

maybe with an option like

sudo --command='!!'

If I want to create a file and enter text in one line I can use 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 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 >

If I want to create a file and enter text in one line I can use 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 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 !!

Isn't there a way to "recycle" the last line and just add sudo in front?

maybe with an option like

sudo --command='!!'
Source Link
rubo77
  • 30.6k
  • 46
  • 141
  • 217
Loading