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.

I have a bash script that creates some file using dd. The problem is dd throws a great amount of output that is going to mess with the output of my script. Searching around I've found a solution:

dd if=boot1h of="/dev/r$temp1" >& /dev/null

Is there an alternative, or is redirecting to /dev/null the only way?

share|improve this question
I'm lost on your last sentence, "the script should not request for privileges". That doesn't seem to have anything to do with redirecting to /dev/null -- you're sudoing because dd needs write access to /dev/r$temp1 (I assume). You're going to need to do that no matter how you suppress dd's output; redirecting output to /dev/null doesn't require root –  Michael Mrozek Jan 31 '11 at 17:40
I'm an idiot. It was giving operation not permitted because of the use of /dev/r$temp1/. I'm really sorry. I'm editing a script that's not mine and didn't noticed it. Really sorry. –  dierre Jan 31 '11 at 17:54
so the problem is regular user cannot write to /dev/r$temp1 or to dev/null –  jet Jan 31 '11 at 18:05
Don't worry about it; I edited it a bit to remove the confusing part –  Michael Mrozek Jan 31 '11 at 18:59
If you're not using any of dd's advanced features, use cat, head or tail instead. –  Gilles Jan 31 '11 at 19:46

5 Answers 5

up vote 10 down vote accepted

From the dd(1) man page:

          suppress transfer statistics


dd if=boot1h of="/dev/r$temp1" status=noxfer

This still outputs the

0+1 records in
0+1 records out

garbage when dd exits, so redirecting to a data sink really is your only option.

share|improve this answer
that was I'm afraid of. –  dierre Jan 31 '11 at 16:59

Something like this should also work for you with recent versions of BASH and ZSH:

dd if=/path/to/file of=/path/to/another_file bs=1M count=1 &> /dev/null

P.S. This is just an example I ran...

share|improve this answer

With any Unix application or command, you can suppress all output with

cmd >/dev/null 2>&1

The first bit redirects the standard output (unit number 1) to /dev/null. But you need the second part to ALSO redirect the error output (unit number 2) to the same place as number 1.


share|improve this answer
Actually, stderr has the file descriptor 2. (I assume "STDERR=3" is just a typo.) –  n.st Jun 21 '14 at 13:29

If I understand correctly what you are trying to do, are you putting that sudo command into the script and expecting the script to prompt for your password when it runs there? In that case you are just doing things the complicated way.

A cleaner solution is to write the script in the usual way (i.e without sudo) and run it as the superuser. The reason behind this is, if the script needs superuser access, then just give it the access (why wait until a certain command?). In the script, to check if it is being run as root do something like this:

if [ "$(id -u)" != "0" ]; then
    echo "This script must be run as root" 1>&2
    exit 1
share|improve this answer
nope. That's exactly what I don't want to do. I don't want the script to be run as root only because I don't want dd to display the output. Your check would correct if I want the script to be run as superuser. –  dierre Jan 31 '11 at 16:59
@dierre So why did you need sudo in the first place? Normal users should be able to redirect things to /dev/null just fine. –  phunehehe Jan 31 '11 at 17:50
I'm using Ubuntu and it's giving me operation not permitted...uhm... –  dierre Jan 31 '11 at 17:52
I'm sorry. I didn't notice I was creating something under /dev/. The script is not mine, I was editing it. I'm really sorry. –  dierre Jan 31 '11 at 17:55

you can redirect the output to an regular file i.e.:

 dd if=boot1h of="/dev/r$temp1" >& /tmp/dd.log
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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