shell 重定向

•Unix/Linux中,shell(命令解释器)默认的输入设备是键盘,输出设备是终端屏幕

 –输入重定向:  < 

cat  <  test.txt

显示文件test.txt的内容

wc  <  test.txt

统计文件test.txt中的行数,单词数和字符数

-c, --bytes     print the byte counts 
-m, --chars     print the character counts 
-l, --lines         print the newline counts 
-w, --words     print the word counts 

eg.

wc -c < test.txt

wc -l < test.txt

–输出重定向:  > 和 >>

输出重定向>     –将命令执行后的结果输出/保存到文件中

ls  > conten.txt          查看文件content.txt的内容,就是ls命令的执行结果

使用输出重定向后,命令的执行结果就不会显示在终端屏幕上了

 

通配符wildcard

  1. *                                #匹配任意字符串,包括空串
  2. ?                              #匹配单个字符
  3. [ list ]                        #匹配任意list中指定的字符
  4. [ ! list ]                      #匹配任意不在list中指定的字符
  5. [c1-c2]                      匹配c1-c2中的任意单个字符
  6. {string1,string2,…} 匹配其中一个字符串

命令

1. df  disk free

 

2.du  disk usage

du /etc 会显示etc目录下面每个文件的所占空间大小 ,再输出总和

创建一个只有一个字符的文件,输出其空间大小

cat a.txt
du -sh a.txt
ls -l a.txt