Shell介绍
- shell是一个命令解释器,提供用户和机器之间的交互
- 支持特定语法,比如逻辑判断、循环
- 每个用户都可以有自己特定的shell
- CentOS7默认shell为bash
- 还有zsh、ksh等
命令历史
历史命令保存在用户家目录下的 .bash_history
[root@chy002 ~]# cat -n /root/.bash_history
1 init 0
2 dhclient
... ...
987 ps aux| grep httpd
988 cat /etc/selinux/config
989 init 0
[root@chy002 ~]# echo $HISTSIZE #命令最大保存数量
1000
#可以通过环境变量 $HISTSIZE 改变最大保存数,在配置文件/etc/profile中修改,source /etc/profile 生效
#history -c 可以清空内存当中的命令历史清空
#不能清空命令历史文件里的记录
[root@chy002 ~]# history -c
#刚输入的命令不会马上记录到命令历史文件中,只有退出终端后才会录入
#修改history命令格式,显示时间。在配置文件中添加。#HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"
1. 快捷显示上一条命令 !!
2. 运行history列表里某一条命令 !n
3. 倒序以XXX开头的第一个命令 !XXX
4. 永久保存命令文件,只能添加不能删除 chattr +a ~/.bash_history
命令补全及别名
tab键,补全命令及文件路径。
自动补全命令参数补全,需要安装 yum install -y bash-completion ,然后再重启系统才可以生效。
[root@chy002 ~]# systemctl re reboot reload-or-restart reset-failed reenable reload-or-try-restart restart reload rescue
自定义的alias放到用户家目录下的 ~/.bashrc,还有一些 /etc/profile.d/中脚本定义,unalias取消自定义别名。
[root@localhost ~]# cat /root/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
[root@localhost ~]# 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-tilde'
通配符及重定向
| 通配符 |
|
| 输入输出重定向 |
|