08 Dec 2014
通配符含义:
* 0个或多个任意字符? 1个任意字符# 命令中使用的话跟shell中一样,后面的东西不生效举例:
# "*"匹配任意个任何字符 # 匹配1开头的所有文件 ls 1* 1 12 124.log 13.log # "?"匹配1个任意字符 # 匹配"1"+"1任意字符"+".log"的文件 ls 1?.log 13.log # "#"注释掉其之后的命令 # "#"注释掉了第二条命令的1*匹配 ls 1? 1* 1 12 12 124.log 13.log ls 1? #1* 12
作用:把标准输出、标准输入、错误输出重定向至文件或设备
符号及其意义:
> 输出重定向>> 输出追加重定向< 输入重定向<< 输入追加重定向1 正确信息标准输出2 错误信息标准输出语法:
1>right.destination 2>error.destination 正确及错误信息分别存放1>right.destination 2>&1 正确及错误信息放在一起2>/dev/null 把错误信息输出到系统黑洞用法举例:
# 输出重定向">"、">>" # 输出重定向,然后用追加重定向增加内容 cat /etc/passwd > ./passwd echo "this is a new line" >> ./passwd # 用tail命令查看最后三行内容,找到新增内容 tail -3 ./passwd test:x:500:500::/home/test:/bin/bash su-test:x:501:501::/home/su-test:/bin/bash this is a new line # 追加重定向会覆盖文件原内容 echo "this is only content will leave" > ./passwd cat ./passwd this is only content will leave # 输入重定向"<"、"<<" # cat可以以此形式创建文件并输入内容,最后ctrl+d退出 cat > stdin yes , i can do the same thing like vim now exit by pushing ctrl and d together # 查看结果 cat stdin yes , i can do the same thing like vim now exit by pushing ctrl and d together # 用文件做标准输入到stdin cat > stdin < /etc/passwd # 查看两个文件的不同,发现是一致的 diff ./stdin-redirect /etc/passwd # 把正确和错误信息放在一个文件中记录 # 下面的语句有正确输出和错误输出 ll stdin-redirect i_am_not_exist ls: cannot access i_am_not_exist: No such file or directory -rw-r--r-- 1 root root 934 May 6 22:37 stdin-redirect # 将其重定向到1个文件中 ll stdin-redirect i_am_not_exist 1>list.log 2>&1 cat list.log ls: cannot access i_am_not_exist: No such file or directory -rw-r--r-- 1 root root 934 May 6 22:37 stdin-redirect # 把错误信息输出到系统黑洞 # 将错误信息或正确信息输入到黑洞 ls stdddd ls: cannot access stdddd: No such file or directory ls stdddd 2> /dev/null