SPUG: Inspired, broken.

Gardner Cohen beldar at pobox.com
Wed Feb 9 13:49:21 PST 2005

Atom Powers wrote:

> Is sudo dropping privileges back to 'apowers' when it sees the '>'?

No. sudo has nothing to do with the ">".

the shell sees "command" redirect file

command happens to be sudo something, but the shell is running as 
you and does the redirect as you.

There are several ugly and not so ugly workarounds.  One is:

yourcommand | sudo dd of=thatoutfile.txt

(assuming yourcommand didn't need to run as root)

another is to investigate sh -c "shell command with special 


sudo /bin/sh -c "yourcommand > yourfile.txt"

which will make the redirection happen in a shell running as root.

Ah too late, someone already said mostly the same thing.

More information about the spug-list mailing list