How to redirect standard error to standard output in bash shell
Any UNIX process, by default, will have three file I/O streams open. Each opened file of the UNIX process is denoted with a number called file number. The default opened three files streams are called stdin, stdout and sterr. Their file numbers are 0, 1 and 2 respectively. Of these stdin stands for standard input and meant for reading input from user or from another file. The stdout stands for standard output and any messages printed by the process get written to this file. Typically this file is console, so the user can use the messages printed by the process. The stderr stands for standard error and any error messages printed by the process get written to this file.
Some times when you redirect output of a command to a file, you still see some messages printed on the screen while the file captures only a portion all messages. This is because stderr is not redirected.
To redirect stderr only:
[liz@techpulp ~]# mycommand 2>mylog.txt
To redirect stdout and stderr:
[liz@techpulp ~]# mycommand >mylog.txt 2>&1
In the above example, stdout of the command is redirected to a file “mylog.txt” and then the file number 2 (i.e stderr) is appended to file number 1 (i.e stdout).