可以理解为linux跟踪打开文件,而分配的一个数字,这个数字有点类似c语言操作文件时候的句柄,通过句柄就可以实现文件的读写操作查看系统文件描述符最大值
用户可以自定义文件描述符范围是:3-num,这个最大数字,跟用户的:ulimit –n 定义数字有关系,不能超过最大值
[root@localhost ~]# ulimit -n1024linux系统默认文件描述符| 文件描述符 | 用途 | POSIX名称 | stdio流 | 说明 |
|---|---|---|---|---|
| 0 | 标准输入 | STDIN_FILENO | stdin | 默认的设备是键盘 命令将从标准输入文件中读取 在执行过程中的需要的输入数据 数据来源于文件 |
| 1 | 标准输出 | STDOUT_FILENO | stdout | 默认的设备是显示器 命令执行后的输出结果发送到标准输出文件 结果输出到文件 |
| 2 | 标准错误 | STDERR_FILENO | stderr | 默认的设备是显示器 命令将执行期间的各种错误信息发送到标准错误文件 错误信息发送到文件 |
[root@WWW.LINUXIDC.COM ~]# lstest.txt查看当前目录下的test.txt文件和一个不存在的test1.txt文件[root@WWW.LINUXIDC.COM ~]# ls test.txt test1.txtls: cannot access test1.txt: No such file or directorytest.txt将正确的输出重定向到文件success.txt中[root@WWW.LINUXIDC.COM ~]# ls test.txt test1.txt 1>success.txtls: cannot access test1.txt: No such file or directory[root@WWW.LINUXIDC.COM ~]# cat success.txttest.txt将错误的输出重定向到文件error.txt中[root@WWW.LINUXIDC.COM ~]# ls test.txttest1.txt 2>error.txttest.txt[root@WWW.LINUXIDC.COM ~]# cat error.txtls: cannot access test1.txt: No such file or directory&1:代绑定到表标准输出[root@WWW.LINUXIDC.COM ~]# ls test.txttest1.txt >success.txt 2>&-[root@WWW.LINUXIDC.COM ~]# cat success.txttest.txt将标准错误输出绑定到标准输出[root@WWW.LINUXIDC.COM ~]# ls test.txttest1.txt > all.txt 2>&1[root@WWW.LINUXIDC.COM ~]# cat all.txtls: cannot access test1.txt: No such file or directorytest.txt将标准错误输出重定向到黑洞设备[root@WWW.LINUXIDC.COM ~]# ls test.txttest1.txt 2>/dev/nulltest.txt&>:混合输出(不分对错)[root@WWW.LINUXIDC.COM ~]# ls test.txttest1.txt &> all.txt[root@WWW.LINUXIDC.COM ~]# cat all.txtls: cannot access test1.txt: No such file or directorytest.txt注意事项:将命令中接收输入的途径由默认的键盘改为其他文件而不是等待从键盘输入操作符: <
通过重定向输入可以使一些交互式操作过程能够通过读取文件来完成
[root@WWW.LINUXIDC.COM ~]# touch passwd.txt[root@WWW.LINUXIDC.COM ~]# echo 123456 > passwd.txt[root@WWW.LINUXIDC.COM ~]# passwd test --stdin < passwd.txtChanging password for user test.passwd: all authentication tokens updated successfully.管道命令操作符是:”|”,它仅??处理经由前面一个指令传出的正确输出信息
也就是 standard output 的信息,对于 stdandard error 信息没有直接处理能力
然后,传递给下一个命令,作为标准的输入 standard input
[root@WWW.LINUXIDC.COM ~]# ls -f | grep allall.txt