认识bash shell 5
1.数据流重定向
> /dev/null 如果将数据导向到该文件中,则所得数据将被抛弃
实操
将ls -l 重导向到新建的tmplist文件中
touch tmplist
ls -l
ls -l > tmplist
cat -n tmplist
ls -l tmplist
cat -n tmplist
ls /tmp >>tmplist
ls /tmp >>aaabbb 若不存在,则新建一个重导向文件
注:>>的用法,如果重导向的文件不存在,则新建一个,若有,则在原有的文件内容后面累加
例2
一般用户模式下
find /root -name 1.txt >right 2>error
cat right
cat error
这里error中会有权限不足的内容
find /root -name 1.txt >>right 2>>error 累加操作
find /home -name 1.txt >file1 2>file1 将正确的和错误的信息都存入file1中,但这种得到的错误信息是不全的
推荐使用如下
find /home -name 1.txt >file1 2>&1
例3
cat -n catfile
输入内容后按Ctrl+d 终止输入
cat -n catfile
cat > catfile << eof
输入内容
结束时用eof
cat catfile
2.双向重导向tee
3.为何要使用命令输出重导向

4.命令执行的判断依据
; && ||
实操
ls;ls -l
ls && ls -l
ls || ls -l
ls file || echo "file is exist“ && echo "file is not exist"