Linux command line : What does it mean 2>&1

For example  #ls 2>&1 > ls.log

What is actually mean by 2>&1??
Since every shell process has there own descriptor :: 0 (stdin), 1 (stdout) and 2 (stderr) :: and & in the front of &1 indicated that 1 is not a file or folder, it is a descriptor. The > mean redirect the out put to another descriptors or  files. in this case 2>&1 > ls.log means that stderr(2) and stdout(1) put is redirected to the ls.log file.

normally, for example #ls > ls.log without 2>&1, means stdout(1) is redirect to ls.log and stderr(2) will show in the console.

I hope this will help you to understand more about the descriptor redirection.

Leave a comment

You must be logged in to post a comment.

Member Area