I'm trying to write a shell script that will automatically set-up a LAMP stack for me. One of the lines I have in the script is:

add-apt-repository -y ppa:ondrej/php5-oldstable >> /tmp/output.txt

But try as I may it always outputs the following content:

gpg: keyring `/tmp/tmpf0k2tr/secring.gpg' created

I would like there to be no output to be displayed to the screen when I run this command to add this ppa to my repository.


Use output redirection to /dev/null and include stderr output.

add-apt-repository -y ppa:ondrej/php5-oldstable > /dev/null 2>&1
  • The 2>&1 will tell Bash to redirect stderr to stdout.
  • The command > file stanza will redirect stdout to a file, in this case /dev/null.
  • /dev/null is the black hole of Linux - you won't be able to recovery anything from there.

Result: full silent execution of your command.

In your updated question you seem to log all output to a file. In that case you can just append the 2>&1 to your current line:

add-apt-repository -y ppa:ondrej/php5-oldstable >> /tmp/output.txt 2>&1

This is because you were looking at the stderr output being printed on the terminal, which you need to redirect to the log as well (otherwise you will miss out on all errors!).

  • 1
    @Braiam This is based on the command the OP provided in his question. I assume it works for him and his script is running as root here. The question is about suppression of output, not about a non-working command. – gertvdijk Sep 4 '13 at 22:39
  • "stderr to stdout" ah! That was the trick. I though all output to the console was the same. Thanks for highlighting that not all output is actually the same. – John Crawford Sep 4 '13 at 23:00
  • @gertvdijk remember that people tend to do copy-paste without knowing how, what, when, where, etc ;). – Braiam Sep 6 '13 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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