![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Redirection of output to a log file | JohnCrump | UNIX for Dummies Questions & Answers | 8 | 08-22-2008 01:25 AM |
| who truncates the output? redirection? tty? Bug? | fredy | UNIX for Advanced & Expert Users | 7 | 12-09-2006 11:21 PM |
| Redirection of output (for logging) | _Spare_Ribs_ | Shell Programming and Scripting | 3 | 12-04-2006 11:17 AM |
| redirection of ladebug output | yakari | UNIX for Advanced & Expert Users | 2 | 10-05-2006 11:23 PM |
| Standard output and redirection | jerardfjay | Shell Programming and Scripting | 2 | 06-27-2005 08:03 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Elevated privilege output redirection
If one wants to create a file with some content, one might use:
Code:
echo 'my content' > new.conf Code:
sudo echo 'my content' > new.conf |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Create the file as a regular user, then move it on top of the old conf using sudo.
|
|
#3
|
|||
|
|||
|
OR sudo a chmod command that will allow writing -- plus, all of this sounds very much like a security breach in the making. Why are you writing to some type of conf file as a plain user? Do you want all unprivileged users to be able to change files that used to be protected?
|
|
#4
|
|||
|
|||
|
I wouldn't take things so seriously. Ubuntu for example basically suggests you do all administration through sudo, and creating the config as the normal you is just good hygiene. Just make sure the file you commit is only writable by root!
|
|
#5
|
||||
|
||||
|
Quote:
Try this: Code:
% sudo touch /tmp/f % sudo > /tmp/f zsh: permission denied: /tmp/f % sudo sh -c '> /tmp/f' % Code:
sudo sh -c 'echo "my content" > new.conf' |
|
#6
|
|||
|
|||
|
Ah, nice one. I see you are invoking a new shell to perform the command. It's good that doing so only involves a few extra key presses. I'll have to add "sh -c" to my local memory banks ;)
|
|
#7
|
||||
|
||||
|
Quote:
Yes, you might also learn about the 'tee' command. This outputs to a every file you name on the command-line AND to stdout. So: Code:
do_some_work | sudo tee outfile.dat |
||||
| Google The UNIX and Linux Forums |