Tech News
← Back to articles

What does " 2>&1 " mean?

read original related products more articles

Some tricks about redirection

Some syntax particularity about this may have important behaviours. There is some little samples about redirections, STDERR , STDOUT , and arguments ordering.

1 - Overwriting or appending?

Symbol > means redirection.

> means send to as a whole completed file, overwriting target if exist (see noclobber bash feature at #3 later).

means send to as a whole completed file, overwriting target if exist (see bash feature at #3 later). >> means send in addition to would append to target if exist.

In any case, the file would be created if they not exist.

2 - The shell command line is order dependent!!

For testing this, we need a simple command which will send something on both outputs:

$ ls -ld /tmp /tnt ls: cannot access /tnt: No such file or directory drwxrwxrwt 118 root root 196608 Jan 7 11:49 /tmp $ ls -ld /tmp /tnt >/dev/null ls: cannot access /tnt: No such file or directory $ ls -ld /tmp /tnt 2>/dev/null drwxrwxrwt 118 root root 196608 Jan 7 11:49 /tmp

... continue reading