On Tue, Jun 21, 2011 at 8:22 AM, Webmaster <[email protected]> wrote:
>
> For example:
> ls -l /usr/bin | more > redirect_test.log 2>&1 (BLFS 6.3 Page 37)
> What does "2>&1" mean?

2 is stderr
> is a redirector
&1 is stdout

Without it, both normal output and errors will be printed in the file;
with it, normal output goes in the file and error is on the screen.
(unless standard output goes somewhere else)

Examples:

ls -al /usr > test.log 2>&1
* the content of /usr will goes in test.log

ls -al /usr > test.log
* the content of /usr will goes in test.log

So far, there are no errors, the behavior is the same in both
instances. The expression becomes meaningful only if there is an
error:

ls -al /non/existant/directory > test.log 2>&1
* will print "No such file or directory" on screen, leaving test.log empty

ls -al /non/existant/directory > test.log
* will print "No such file or directory" in test.log
-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page

Reply via email to