What Does the 2> Mean on the Unix Command-Line

What does 2&1 mean?

File descriptor 1 is the standard output (stdout).

File descriptor 2 is the standard error (stderr).

At first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as "redirect stderr to a file named 1".

& indicates that what follows and precedes is a file descriptor, and not a filename. Thus, we use 2>&1. Consider >& to be a redirect merger operator.

What does 1 and 2 mean in command line input/output redirection?

0,1 and 2 are standard file descriptors in *NIX systems.

2>&1 # Redirects stderr to stdout.

0 | Standard input |STDIN_FILENO | stdin

1 | Standard output | STDOUT_FILENO | stdout

2 | Standard error | STDERR_FILENO |stderr

echo &2 some text what does it mean in shell scripting

To quickly explain what the others missed:

echo "hey" >&2

> redirect standard output (implicit 1>)

& what comes next is a file descriptor, not a file (only for right hand side of >)

2 stderr file descriptor number

Redirect stdout from echo command to stderr. (If you were to useecho "hey" >2 you would output hey to a file called 2)

what do multiple pipe symbols mean in unix?

The pipe symbol | always means "use the output of the previous command as the input for the following command". When multiple pipes are strung along in sequence, the piping occurs from left to right (A | B | C means: take the output of A, and put it into B. Then, take the output of B, and put it into C). It may help to visualize parentheses around usages of pipes, starting from the left ((A | B) | C has a clearer order of operations).

In your specific case, the command says

  1. Tell me what files have the word "and" in them in the current directory.
  2. Only show me the first 10 matches you find.
  3. Only show me the last 5 of the first 10 matches.

In other words, it's asking to see the fifth through tenth files it finds that have the word "and" in the current directory.

what do multiple pipe symbols mean in unix?

The pipe symbol | always means "use the output of the previous command as the input for the following command". When multiple pipes are strung along in sequence, the piping occurs from left to right (A | B | C means: take the output of A, and put it into B. Then, take the output of B, and put it into C). It may help to visualize parentheses around usages of pipes, starting from the left ((A | B) | C has a clearer order of operations).

In your specific case, the command says

  1. Tell me what files have the word "and" in them in the current directory.
  2. Only show me the first 10 matches you find.
  3. Only show me the last 5 of the first 10 matches.

In other words, it's asking to see the fifth through tenth files it finds that have the word "and" in the current directory.

What does -- and - mean on any Unix Shell?

By POSIX standard, options are letters preceded by a single dash. They can be combined; e.g. ls -l -a is equivalent to ls -la.

By GNU convention, long options are preceded by two dashes. Obviously, you can't combine them like normal options, but they are more readable.

Most options will have both forms; for example, most programs recognise -h and --help as equivalents.

What does `hash -r 2` do?

The command isn't

hash -r 2

but rather

hash -r

The 2 is part of a standard error redirect to /dev/null, which essentially throws away error output.

You can read about Bash version of the hash builtin in man bash. Here's a relevant snippet:

Any previously-remembered pathname is discarded. If the -p option is supplied, no path search is performed, and filename is used as the full filename of the command. The -r option causes the shell to forget all remembered locations.

what means $ (ampersand) in a command?

In Bash the '$' sign means that a normal user logged into the system can execute a command. If you're logged in as the root user, the prompt is '#' (hash or number symbol).

For further reading about the use and history of the prompt, please have a look at https://superuser.com/questions/57575/what-is-the-origin-of-the-unix-dollar-prompt



Related Topics



Leave a reply



Submit