[linux] The meaning of 2>&1 &

The meaning of 2>&1 &

I recently wrote a shell script command and asked chatgpt. Chatgpt helped me output the relevant script. Although it was wrong, it felt okay. 2>&1 &This command was a bit incomprehensible. I asked chatgpt to help me answer it.

Under the mark here, chatgpt replies as follows:

2>&1 &is a command that redirects standard error output to standard output and puts the process in the background. The specific meaning is as follows:

>Indicates redirection, redirecting standard output to the specified file

2means standard error output, whereas 1means standard output. So 2>&1means to redirect standard error output to standard output.

&Indicates to put the process in the background to run.
To sum up, 2>&1 & means to redirect standard error output to standard output and put the process in the background. When this command starts a process, it can output the log to the specified file without blocking the current terminal.

Summarize

Many things can be placed in the background, the window is closed, but the progress is still going on, very useful, recommended! ! !

Guess you like

Origin blog.csdn.net/myt2000/article/details/129754449