Giter Site home page Giter Site logo

Comments (1)

yanlele avatar yanlele commented on May 13, 2024

补充:

Shell重定向 &>file、2>&1、1>&2 、/dev/null的区别

Shell 重定向是一种将命令的输入或输出重定向到不同位置的技术。下面是几种常见的 Shell 重定向方式及其区别:

  1. >&>> 用于将命令的标准输出重定向到指定文件中,而 &> 则将标准输出和标准错误输出合并后重定向到指定文件中。例如,command > file 将命令的标准输出重定向到 file 文件中,而 command &> file 则将标准输出和标准错误输出一起重定向到 file 文件中。

  2. 2>&11>&22>&1 表示将标准错误输出重定向到标准输出,1>&2 表示将标准输出重定向到标准错误输出。这样做的目的是将标准错误输出和标准输出合并为一个流,方便统一处理。例如,command 2>&1 将标准错误输出重定向到标准输出上。

  3. /dev/null/dev/null 是一个特殊的文件,也被称为黑洞文件,它可以将所有重定向到它的输入都丢弃掉。可以将其用于不需要关心命令的输出或错误输出的情况。例如,command > /dev/null 将命令的标准输出丢弃掉,而 command 2> /dev/null 则将命令的标准错误输出丢弃掉。

总结:

  • > 用于将标准输出重定向到文件。
  • &> 用于将标准输出和标准错误输出合并后重定向到文件。
  • 2>&1 将标准错误输出重定向到标准输出。
  • 1>&2 将标准输出重定向到标准错误输出。
  • /dev/null 是一个特殊文件,用于丢弃输入,可以用于丢弃标准输出或标准错误输出。

from node-index.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.