Shell Command Line 快捷键

元字符(meta character)

IFS(交换字段分隔符):由 三者之一组成(我们常用space)。
CR(回车键):由产生。
IFS是用来拆分command line的每一个词(word)用的,因为shell command line是按词来处理的。而CR则是用来结束command line用的,这也是为何我们敲命令就会执行的原因。除了IFS和CR外,常用的meta还有:

Basic Shell Control - 图1
参考链接:Shell 元字符

示例

换行

  1. $ echo "this is a long \
  2. > command line and" ; echo "shows that multiple commands \
  3. > may be strung out."
  4. this is a long command line and
  5. shows that multiple commands may be strung out.

Shell Pattern-Matching

元字符 作用 示例
* 匹配任意非空字符串
? 匹配任意1个字符 a?c.txt 匹配 a1c.txt, abc.txt, a-c.txt 等
[] 匹配范围里的任一字符 [abc] , [0-9] , [a-z] , [A-Z] , [0-9a-zA-Z]
\ 转义字符,使元字符失效 a\?c.txt 只匹配 a?c.txt

模式匹配 适用于搜索过滤文件名,而文本搜索则最好使用 正则表示式 并搭配类似 grep 的命令。

重定向

元字符
A >B 输出重定向,把A命令的输出重定向到B echo 'Hello world' >file.txt
A >>B 输出重定向,追加(append)数据 echo 'Hello world' >>file.txt
A < B 输入重定向,把B作为A命令的输入 cat < file.txt
A <<EOF here operator, 把键盘输入重定向到A,直到遇到EOF(可以自定义) cat <<XXX >file.txt
结果:键盘输入的内容保存到了 file.txt 里

任务控制

; 顺序

  1. w; free; df

&&

  1. cmd1 && cmd2 && cmd3

||

  1. cmd1 || cmd2

前后台

后台