elixiat 发表于 2018-8-28 11:14:24

Linux_note shell中特殊符号

  * 代表0个或多个任意字符
  ? 只代表一个任意字符
  # 注释符号
  \ 脱意符号
  # ls #1.txt   #将后面内容注释 只运行了ls
  111      1.tar3.txt            install.log         yasuo.zip
  111.tar1.txtanaconda-ks.cfginstall.log.syslog
  123.txt2.txta.txt            yasuo
  # ls \#1.txt   \脱意字符将#原本意义去掉
  ls: 无法访问#1.txt: 没有那个文件或目录   此时将#1.txt作为文件名
  # touch \#1.txt|ls
  111      123.txt#1.txt2.txtanaconda-ks.cfginstall.log         yasuo
  111.tar1.tar    1.txt   3.txta.txt            install.log.syslogyasuo.zip
  | 管道符
  $ 变量的前缀,获得或使用变量时在其前加上$
  !$表示将上条命令中最后一个变量
  # echo $PATH
  /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/tmp/:/data/bin/:/root/bin
  # !$
  $PATH
  -bash: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/tmp/:/data/bin/:/root/bin:
  没有那个文件或目录
  ;用于两条命令的中间(两条命令写在一行)
  # ls 1.txt ;ls 1.tar
  1.txt
  1.tar
  ~用户家目录
  # ls ~
  111      123.txt#1.txt2.txtanaconda-ks.cfginstall.log         yasuo
  111.tar1.tar    1.txt   3.txta.txt            install.log.syslogyasuo.zip
  & 将命令放到后台执行(在一条命令后加&)
  # sleep 10 &
   1647
  # jobs
  +Running               sleep 10 &
  # jobs
  +Done                  sleep 10
  重定向符号:>,>>,2<,2<<,<
  #echo "123">1.txt> 覆盖原文件1.txt的内容
  # echo "123">1.txt
  # cat 1.txt
  123
  若不想覆盖用追加重定向 >>
  # echo "456">>1.txt
  # echo "789">>1.txt
  # cat 1.txt
  123
  456
  789
  反向重定向 < 把一个文件内容丢给一个命令
  如:# wc -l < 1.txt
  3
  错误重定向:2>,2>>
  # ls 11111
  ls: 无法访问11111: 没有那个文件或目录
  # ls 11111 > 1.txt 同样会覆盖原文件内容
  ls: 无法访问11111: 没有那个文件或目录# ls 11111 2> 1.txt
  # cat 1.txt
  ls: 无法访问11111: 没有那个文件或目录
  不覆盖原文件内容:2>>
  # ls 11111 2>> 1.txt
  # cat 1.txt
  ls: 无法访问11111: 没有那个文件或目录
  ls: 无法访问11111: 没有那个文件或目录
  [] 括号里为字符组合,代表字符中的任意一个
  # ls .txt
  1.txt2.txt3.txt
  # ls .txt
  1.txt2.txt3.txta.txt

页: [1]
查看完整版本: Linux_note shell中特殊符号