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
Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment