阿牛 发表于 2018-8-19 06:33:51

shell 命令,别名,通配符,重定向

  shell 是一个命令解释器,提供用户和机器之间交互
  支持特定语法,逻辑判断、循环
  每个用户都可以有自己特定的shell
  centos7 默认shell为bash
  还有zsh、ksh
  yum list|grep zsh
  yum list|grep ksh
命令历史
  history命令
  .bash_history
  ls /用户家目录/.bash_history查看历史记录,即历史记录存放位置
  # echo $HISTSIZE   #查看最大保存历史记录数
  1000
  # history -c   #清楚历史记录
  # history   #再次验证,只有刚刚使用的一条
  1history
修改历史记录保存最大值
  /etc/profile中修改
  soure /etc/profile使修改的数字生效
修改历史命令显示时间
  # HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"
  # echo $HISTTIMEFORMAT
  %Y/%m/%d %H:%M:%S
  临时生效
  # history
  12018/01/11 05:47:08history
  22018/01/11 05:47:58ls -l .bash_history
  32018/01/11 05:48:01cd ..
  42018/01/11 05:48:07cd .
  52018/01/11 05:48:08pwd
  62018/01/11 05:48:11cd /root/
  72018/01/11 05:49:29cat /etc/profile
  82018/01/11 05:49:44vim /etc/profile
  92018/01/11 05:49:48vi /etc/profile
  102018/01/11 05:54:50echo $HISTTIMEFORMAT="%y/%m/d% %H:%YM:%S "
  112018/01/11 05:55:18HISTTIMEFORMAT="%Y/%m%d %H:%M:%S"
  122018/01/11 05:55:29echo $HISTTIMEFORMAT
  132018/01/11 05:55:44HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"
  142018/01/11 05:55:45echo $HISTTIMEFORMAT
  152018/01/11 05:56:25history
  永久生效
  vim /etc/profile
  HISTSIZE=1000
  添加:HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"
  重新登录 history验证
  3302018/01/11 05:48:11cd /root/
  3312018/01/11 05:49:29cat /etc/profile
  3322018/01/11 05:49:44vim /etc/profile
  3332018/01/11 05:49:48vi /etc/profile
  3342018/01/11 05:54:50echo $HISTTIMEFORMAT="%y/%m/d% %H:%YM:%S "
  3352018/01/11 05:55:18HISTTIMEFORMAT="%Y/%m%d %H:%M:%S"
  3362018/01/11 05:55:29echo $HISTTIMEFORMAT
  3372018/01/11 05:55:44HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"
  3382018/01/11 05:55:45echo $HISTTIMEFORMAT
  3392018/01/11 05:56:25history
  3402018/01/11 05:56:56yum install vim
  3412018/01/11 06:00:06vim /etc/profile
  3422018/01/11 06:01:57source $HISTTIMEFORMAT
  3432018/01/11 06:02:56source $!
  3442018/01/11 06:03:51source /etc/profile
  3452018/01/11 06:04:12echo $HISTTIMEFORMAT
  3462018/01/11 06:04:17exit
  3472018/01/11 06:04:25history
  3482018/01/11 06:04:49vim /etc/profile
  3492018/01/11 06:05:31history
  正常退出后都可永久保存
  chattr +a ~/.bash_history
  !! 上一条命令
  !n 第n条命令
  !echo从下往上找最近一次 以echo开头的命令
命令补全及别名
  tab键 一下补全命令    两下补全所有内容
  centos7下参数补全安装bash-comletion,按2下除了可以补充命令本身,还能补全参数
alias别名
  定义别名
  # alias restartnet='systemctl restart network.service'
  # restartnet
  Job for network.service failed. See 'systemctl status network.service' and 'journalctl -xn' for details.
  # alias
  alias cp='cp -i'
  alias egrep='egrep --color=auto'
  alias fgrep='fgrep --color=auto'
  alias grep='grep --color=auto'
  alias l.='ls -d .* --color=auto'
  alias ll='ls -l --color=auto'
  alias ls='ls --color=auto'
  alias mv='mv -i'
  alias restartnet='systemctl restart network.service'
  alias rm='rm -i'
  alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tild
  alias 位置
  1、用户家目录/.bashrc
  2、/etc/profile.d/
  # cd /etc/profile.d/
  # ls
  256term.csh         colorgrep.cshcolorls.shless.cshvim.sh
  256term.sh          colorgrep.sh   lang.csh    less.sh   which2.csh
  bash_completion.shcolorls.csh    lang.sh   vim.csh   which2.sh
  #
  取消自定义的别名
  unalias 别名
通配符

[*]满足条件的任一个
  ?满足条件的某一个
  【】范围 范围内满足条件的范围
  {,,,} 范围内满足条件的某一个

重定向
  输出重定向
  正确输出到目标文件
  cat 1.txt > 2.txt把1.txt的内容输出到2.txt去,同时把2.txt原内容抹去
  >追加重定向
  cat 2.txt >>2.txt把1.txt的内容输出到2.txt去,同时把2.txt原内容保留
  2>错误重定向输出
  输出重定向,错误输出重定向分开
  # ls .txt aaa.txt > 1.txt 2>a.txt
  # cat 1.txt
  1.txt
  2.txt
  # cat a.txt
  ls: 无法访问aaa.txt: 没有那个文件或目录
  &>错误重定向
  # ls .txt aaa.txt &> a.txt
  # cat a.txt
  ls: 无法访问aaa.txt: 没有那个文件或目录
  1.txt
  2.txt
  2>> 错误追加重定向
  # ls aaa.txt 2>>a.txt
  # cat a.txt
  ls: 无法访问aaa.txt: 没有那个文件或目录
  1.txt
  2.txt
  ls: 无法访问aaa.txt: 没有那个文件或目录
  < 输入重定向
  # wc -l 1.txt
  2 1.txt
  # wc -l < 1.txt
  2
  只能文件到命令,不能文件到文件

页: [1]
查看完整版本: shell 命令,别名,通配符,重定向