Linuxopsys
Linuxopsys

@linuxopsys

3 Tweets 3 reads Feb 16, 2023
Quick Linux tip💡 🐧
In Linux, the pipe(|) is very useful if you want to redirect the output of one command to serve as input to the next for further processing. However, this doen't redirect its errors.
What if you want to redirect and process both errors and normal output🤔
This is where this "|&" rediction operator comes in handy.
This operator sends both standard output (stdout) and standard error (stderr) of the first command over a pipe to standard input (stdin) of the second command:
$ ls nonexistent-dir |& grep "No such file or directory"
The "|&" redirection operator in bash is a shorthand for the "2>&1 |" operator.
$ command1 2>&1 | command2
Follow us (@linuxopsys) for more byte sized Linux tips and be a better informed Linux user 🐧😎

Loading suggestions...