认识bash shell 5


1.数据流重定向

Linux鸟哥视频学习笔记18

> /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
Linux鸟哥视频学习笔记18

3.为何要使用命令输出重导向


Linux鸟哥视频学习笔记18
4.命令执行的判断依据
; && || 
Linux鸟哥视频学习笔记18

实操

ls;ls -l
ls && ls -l
ls || ls -l

ls file || echo "file is exist“ && echo "file is not exist"

相关文章:

  • 2021-10-26
  • 2021-06-21
  • 2021-08-15
  • 2021-11-16
  • 2021-06-06
  • 2021-12-07
  • 2021-04-24
  • 2021-08-31
猜你喜欢
  • 2021-10-07
  • 2021-08-05
  • 2021-06-19
  • 2021-08-25
  • 2021-05-08
  • 2021-11-16
  • 2021-08-18
相关资源
相似解决方案