Bash grep stderr and stdout

Grep stderr by redirecting stderr to stdout.

my_command 2>&1 | grep --color my_keyword

Grep only stderr by redirecting stderr to stdout and redirecting stdout to /dev/null.

my_command 2>&1 > /dev/null | grep --color my_keyword
php -r 'fwrite(STDOUT, "stdout\n");fwrite(STDERR, "stderr\n");' | grep --color std
php -r 'fwrite(STDOUT, "stdout\n");fwrite(STDERR, "stderr\n");' 2>&1 | grep --color std
php -r 'fwrite(STDOUT, "stdout\n");fwrite(STDERR, "stderr\n");' 2>&1 > /dev/null | grep --color std
View this page on GitHub.
Posted .

Comments

Leave a Reply