讀入數據:input
輸出數據:outputcentos
打開的文件都有一個fd:file descriptor 文件描述符
Linux給程序提供三種I/O設備bash
[root@centos7 proc]# echo $$ 2199 [root@centos7 proc]# ll /proc/$$/fd 總用量 0 lrwx------. 1 root root 64 10月 19 20:09 0 -> /dev/pts/0 lrwx------. 1 root root 64 10月 19 20:09 1 -> /dev/pts/0 lrwx------. 1 root root 64 10月 19 20:09 2 -> /dev/pts/0 lrwx------. 1 root root 64 10月 19 20:22 255 -> /dev/pts/0 [root@centos7 proc]#
[root@centos7 proc]# ll /proc/self/fd 總用量 0 lrwx------. 1 root root 64 10月 19 20:25 0 -> /dev/pts/0 lrwx------. 1 root root 64 10月 19 20:25 1 -> /dev/pts/0 lrwx------. 1 root root 64 10月 19 20:25 2 -> /dev/pts/0 lr-x------. 1 root root 64 10月 19 20:25 3 -> /proc/2222/fd
格式:命令 操做符號 文件名ide
支持的操做符號
1> or >:重定向標準輸出
2>:重定向標準錯誤centos7
[root@centos7 ~]# xxx 2> /data/f1.log [root@centos7 ~]# cat /data/f1.log -bash: xxx: 未找到命令
[root@centos7 ~]# rm /data/f1.log 2> /data/all.log y [root@centos7 ~]# cat /data/all.log rm:是否刪除普通文件 "/data/f1.log"?[root@centos7 ~]#
&>:同時重定向標準輸出和錯誤code
[root@centos7 ~]# ls /data/ /rr &> /data/all.log [root@centos7 ~]# cat /data/all.log ls: 沒法訪問/rr: 沒有那個文件或目錄 /data/: all.log
以上若是文件已經存在,文件內容會被覆蓋
set -c 禁止將內容覆蓋已有文件,但可追加;強制覆蓋 &|
set +c容許覆蓋ip
<input
[root@centos7 ~]# cat bc.log 2+3 [root@centos7 ~]# bc < bc.log 5 [root@centos7 ~]# seq -s+ 1 10 > bc.log [root@centos7 ~]# bc < bc.log 55