>与>>重定向

1.在linux中,使用> 和 >> 可以使数据流重定向。

如:

ll / > ~/files;

在终端中并不显示所有的文件,而是会将查到的目录写入到 ~/files中。

> 是替换, >> 是向后累加。

使用 cat ~/files 可以查看数据。

当没有 files 文件,会自动创建文件并写入。

2. 标准输出 stdout (standard output):代码为 1

    标准错误输出 stderr (standard error output):代码为 2 .

在执行命令时,可以将正确和错误的代码分别写入到不同的文件中

如:

find /home -name .bashrc > list_right 2> list_error

3.数据不进行写入操作,定向到/dev/null

find /home -name .bashrc > /dev/null 2> list_error

4.将正确和错误的写入到同一个文件

find /home -name .bashrc > list 2>&1

原文地址:https://www.cnblogs.com/wsh-ning/p/8184530.html