How to hide all command output with zsh and bash
How can I hide all output that is written and outputted in a terminal?
In other words, I am looking to add the string
>/dev/null 2&>1
to every command I write.
- How would you do it with bash?
- How would you do it with zsh?
- Ideally how to have a configuration that take into account any terminal.
zsh
:
You can redirect stdout and stderr of any following command to /dev/null
by running these two command:
exec >/dev/null
exec 2>/dev/null
Note: This will still show the prompt and anything you type on the command line, but not much else.
bash
:
You can redirect stdout and stderr with the following command
exec >/dev/null 2>&1
Note
-
This may suppress any output, including the prompt and what you type on the command line. (This was the case for me with
zsh
5.2 andbash
4.4, when I first created this answer in 2016. While it seems to still be the case withbash
5.1.8, it looks like withzsh
this is no longer the case since at least version 5.8) -
To enable the output again, run
exec >/dev/tty exec 2>/dev/tty