通配符及输入输出重定向

通配符

  • 通配符 * 代表零个或多个任意字符
  • 通配符‘? 代表一个任意字符
  • 中括号 [] “ls [0-9a-zA-Z].txt”表示 0-9,a-z,A-Z 区间内的任意.txt 文件
  • 大括号 {} “ls {1,2,3}.txt”表示括号内任意.txt 文件

输入输出重定向

  • 输出重定向 > (使用时的作用:把 > 左边的内容重写给 > 右边的内容里面)
  • 追加重定向 >> (使用时的作用:把 >> 左边的内容追加给 >> 右边的内容里面)
  • 错误重定向 2> (使用时的作用:把 2> 左边的错误信息指定输入到 2> 右边的文件里)
  • 错误追加重定向 2>>
  • 输入重定向 <
[root@localhost ~]# ls
1_heard.txt  1_sorft.txt  1.txt  222  2.txt  anaconda-ks.cfg  dd  dir
[root@localhost ~]# vim 1.txt
[root@localhost ~]# ddddddddd 2>1.txt
[root@localhost ~]# cat 1.txt
-bash: ddddddddd: 未找到命令
[root@localhost ~]# ddddddddd 2>> 1.txt
[root@localhost ~]# cat 1.txt
-bash: ddddddddd: 未找到命令
-bash: ddddddddd: 未找到命令
[root@localhost ~]# ls [12].txt aaa.txt &> a.txt
[root@localhost ~]# cat a.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
1.txt
2.txt
[root@localhost ~]# ls [12].txt aaa.txt &>> a.txt
[root@localhost ~]# cat a.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
1.txt
2.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
1.txt
2.txt
[root@localhost ~]# ls [12].txt aaa.txt > 1.txt 2>a.txt
[root@localhost ~]# cat 1.txt
1.txt
2.txt
[root@localhost ~]# cat a.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
[root@localhost ~]# wc -l < 1.txt    //查看行数
2