you can use these:
- On all shells:
docker logs nginx 2>&1 | grep "127."
- Only on newer versions of bash works:
docker logs nginx | &> grep "127"
What is this syntax?
- Standard input (
0
)
- Standard output (
1
)
- Standard error (
2
)
The >
operator actually defaults to using 1
as the
file descriptor number, which is why we don't need
to specify 1>
to redirect standard output: (date 1> now.txt
= date > now.txt
)
all together
We can redirect multiple streams at once! In this example, we are
concatenating two files, redirecting standard output to a file called
insects.txt, and redirecting standard error to a file called error.txt.
cat bees.txt ants.txt > insects.txt 2> error.txt
getting fancy
If we wanted to redirect both standard output and
standard error to the same file, we could do ls docs > output.txt 2> output.txt
Or we could instead use 2>&1
which is a fancy syntax
for saying "redirect standard error to the same
location as standard output.
ls docs > output.txt 2>&1
getting fancier
Newer versions of bash also support a fancier syntax
for redirecting both standard output and standard
error to the same file: the &>
notation
ls docs &> output.txt