redirecting out of a command invoked by sudo fails

Todd Zullinger tmz at pobox.com
Fri Jun 25 19:07:05 UTC 2010


JD wrote:
> cd /var/lib
> sudo tar cjf - rpm > rpm.tar.bz2
> sh: rpm.tar.bz2: cannot create [Permission denied]

Why use f - and then redirect stdout when you could just do:

sudo tar cjf rpm.tar.bz2 rpm

?

> Is this an established legacy behaviour of sudo?

This is the way it has always been and will always be.

If you do find other cases where you need this sort of thing, a common
idiom involves tee:

echo foo | sudo tee /path/to/some/root/owned/file > /dev/null

-- 
Todd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We are not to expect to be transported from despotism to liberty in a
featherbed.
    -- Thomas Jefferson

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 542 bytes
Desc: not available
Url : http://lists.fedoraproject.org/pipermail/users/attachments/20100625/6dfb2ed7/attachment.bin 


More information about the users mailing list