Possible duplicate:How to use sudo to redirect output to a location to which I do not have write permission?
Let's say I want to change the file "foo" that lives in / home, applying some kind of regular expression to it (via sed ) and putting the result in a file called / home / foo 2.
I do not have read / write access to either / home or foo, so I use sudo . However, I still get permission rejected
sudo sed "s/bar/baz/" <foo >foo2 bash: foo2: Permission denied
Any ideas? Thanks
Use the in place, -i option. Your syntax will look like this:
-i
sed -i [pattern] filename
Although sh may be a bad idea in general, it will give permission to create a new foo2 file for your shell:
sh
foo2
sudo sh -c "sudo sed 's/bar/baz/' <foo >foo2"
Source: https://habr.com/ru/post/1443013/More articles:Lock file without blocking Ruby process during crashes - ruby | fooobar.comCheck if a user is a member of a dbo role in SQL Server - sql-serverUsing Ant, how can I set the jars directory? - androidConfiguring a virtual directory on IIS7 - asp.netJava: convert an obsolete dictionary instance to a map - javaNothing appears in Debug Debug window - c #DateTime parsing complex C # strings - c #DynamicDataDisplay ChartPlotter deletes all charts - c #where is the streams window in vs2008 - visual-studio-2008Is there a way to set the default font and font size in CKEditor? - ckeditorAll Articles