1

For example, if I have a statement:

/home/1/test.sh > /home/1/test.log 2>&1 

What does the last part of this do effectively?

Thanks.

1
  • @Freddy Yes, I didn't realize google had added symbols as meaningful search terms, that's my bad. Makes looking these things up a lot easier. Someone can close this question. Thanks! Commented Mar 11, 2021 at 23:50

1 Answer 1

2

Greater than or 1 greater than means redirect stdout (standard output, what's usually written to the terminal. 2 greater than means redirect stderr (standard error).

In 2>&1, you are redirecting stderr AND (ampersand) stdout.

5
  • In this case, where are you redirecting it to? Thanks! Commented Mar 11, 2021 at 23:45
  • 1
    In the example you gave, you'd be redirecting it to the filename following >, so /home/1/test.log. Note that there is a more readable but less portable version of the above: /home/1/test.sh &> /home/1/test.log. Commented Mar 11, 2021 at 23:46
  • Oh okay, I think I understand. So it's redirecting stdout to the file, then redirecting stderr to stdout, which is being redirected to the file, so both stdout and stderr are redirected to the log file. Is that correct? Commented Mar 11, 2021 at 23:49
  • 1
    Yes, that's right. Commented Mar 11, 2021 at 23:51
  • 2
    2>&1 as such doesn't redirect stderr and stdout, though (that's what &> does). It redirects stderr to wherever stdout is pointing at that moment. Commented Mar 12, 2021 at 10:26

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.