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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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.

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
For those who haven't used tee, note that this will also print the contents to the console, and so shouldn't be used on binary or untrusted inputs. – shelvacu May 5 at 20:39

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