例 date > time.txt
FD 文件描述符 软链接 类似外号标签
程序的fd(链接文件)是为了省去长的绝对路径
0 键盘只读 0 标准输入
1,2 是终端可以理解是屏幕 1 标准输出
3+ 是文件 可读可写 2 标准错误输出
>一个大于号是覆盖 3+ 普通文件
>>两个大于号是追加
程序在有输出时才能引导到文件中
mkdir xxx >1.txt 不可以输出
mkdir -v xxx >1.txt 可以输出
命令运行错误信息可以用2>引导到文件中
&> /dev/null
输入重定向 将内容代替认为输入
程序<文件
进程管道 piping cat /etc/passwd | grep root | tail -3
tee管道 即交给另一个程序处理,又保存一份副本
cat /etc/passwd | tail -1 没保存副本
cat /etc/passwd | tee file88.txt | tail -1
参数传递 xargs 特殊指令使用 例如 rm,cp等
cat file.txt | xargs rm -rvf
removed ‘/home/file1’
removed ‘/home/file2’
file.txt 文件包含
/home/file1
/home/file2
[user01@localhost ~]$ cat /etc/passwd | grep ntp
ntp:x:38:38::/etc/ntp:/sbin/nologin
[user01@localhost ~]$ cat /etc/passwd | grep ntp |cut -d: -f1
ntp
[user01@localhost ~]$ cat /etc/passwd | grep ntp |cut -d: -f2
x
[user01@localhost ~]$ cat /etc/passwd | grep ntp |cut -d: -f3
38
重定向
输出重定向 >
进程产生的信息。存放在文件中。
标准正确输出: ls /home > 1.txt
标准错误输出: ls /aaaa 2> 2.txt
标准混合 : &> 3.txt
输入重定向 <
以文本内容,作为进程的标准输入
通常在编程时会用。
mail -s “ssss” alice < word.txt
