Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
Redirecting stdout to a file you don't have write permission on

I'm trying to create an md5sum for an ISO image created with the Ubuntu Customization Kit tools. The ISO is created by the tools, which have to be run with sudo, in

~/tmp/remaster-new-files/ 

which has permissions:

drwxr-xr-x 2 root root remaster-new-files

So I cd to that directory and run

sudo md5sum my.iso > my.iso.md5

and I get the following error:

bash: my.iso.md5: Permission denied

I can create the md5 sum somewhere else and use sudo mv to move it into place, exactly where it would be if the sudo md5sum command succeeded. Also, if I change user to root with sudo su root, I can run the md5sum command successfully. Why can't I use sudo to create files in this directory, given that I can use sudo to move files to it?

share|improve this question

marked as duplicate by Gilles, enzotib, Michael Mrozek Dec 22 '11 at 23:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 11 down vote accepted

The problem is that the redirection is done from the shell before running the command, as the current user, so sudo do not come into play.

Use instead

md5sum my.iso | sudo tee my.iso.md5
share|improve this answer
    
Thanks - that's exactly the nugget of information I was missing! –  Tim Beattie Dec 21 '11 at 11:05
    
That's an interesting way of doing it. Most of the time suggestions just wrap the command and redirection in a sudo bash -c "" command... +1 –  Izkata Dec 21 '11 at 15:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.