star 之间 grep yum vim tar repo 时间 art
shell 是一个命令解释器,提供用户和机器之间交互
支持特定语法,逻辑判断,循环
每个用户都可以有自己特定的 shell
centos7 默认 shell 为 bash
还有 zsh,ksh
命令历史
yum list|grep zsh
yum list|grep ksh
history 命令
.bash_history
ls / 用户家目录 /.bash_history 查看历史记录,即历史记录存放位置
修改历史记录保存最大值
[root@aminglinux01 yum.repos.d]# echo $HISTSIZE #查看最大保存历史记录数
1000
[root@aminglinux01 yum.repos.d]# history -c #清楚历史记录
[root@aminglinux01 yum.repos.d]# history #再次验证,只有刚刚使用的一条
1 history
/etc/profile 中修改
soure /etc/profile 使修改的数字生效
修改历史命令显示时间
临时生效
[root@aminglinux01 ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"
[root@aminglinux01 ~]# echo $HISTTIMEFORMAT
%Y/%m/%d %H:%M:%S
永久生效
ot@aminglinux01 ~]# history
2018/01/11 05:47:08history
2018/01/11 05:47:58ls -l .bash_history
2018/01/11 05:48:01cd ..
2018/01/11 05:48:07cd .
2018/01/11 05:48:08pwd
2018/01/11 05:48:11cd /root/
2018/01/11 05:49:29cat /etc/profile
2018/01/11 05:49:44vim /etc/profile
2018/01/11 05:49:48vi /etc/profile
2018/01/11 05:54:50echo $HISTTIMEFORMAT="%y/%m/d% %H:%YM:%S"
2018/01/11 05:55:18HISTTIMEFORMAT="%Y/%m%d %H:%M:%S"
2018/01/11 05:55:29echo $HISTTIMEFORMAT
2018/01/11 05:55:44HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"
2018/01/11 05:55:45echo $HISTTIMEFORMAT
2018/01/11 05:56:25history
添加:HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"
vim /etc/profile
HISTSIZE=1000
重新登录 history 验证
正常退出后都可永久保存
2018/01/11 05:48:11cd /root/
2018/01/11 05:49:29cat /etc/profile
2018/01/11 05:49:44vim /etc/profile
2018/01/11 05:49:48vi /etc/profile
2018/01/11 05:54:50echo $HISTTIMEFORMAT="%y/%m/d% %H:%YM:%S"
2018/01/11 05:55:18HISTTIMEFORMAT="%Y/%m%d %H:%M:%S"
2018/01/11 05:55:29echo $HISTTIMEFORMAT
2018/01/11 05:55:44HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"
2018/01/11 05:55:45echo $HISTTIMEFORMAT
2018/01/11 05:56:25history
2018/01/11 05:56:56yum install vim
2018/01/11 06:00:06vim /etc/profile
2018/01/11 06:01:57source $HISTTIMEFORMAT
2018/01/11 06:02:56source $!
2018/01/11 06:03:51source /etc/profile
2018/01/11 06:04:12echo $HISTTIMEFORMAT
2018/01/11 06:04:17exit
2018/01/11 06:04:25history
2018/01/11 06:04:49vim /etc/profile
2018/01/11 06:05:31history
chattr +a ~/.bash_history
!! 上一条命令
!n 第 n 条命令
!echo 从下往上找最近一次 以 echo 开头的命令
命令补全及别名
tab 键 一下补全命令 两下补全所有内容
centos7 下参数补全 安装 bash-comletion,按 2 下除了可以补充命令本身,还能补全参数
alias 别名
定义别名
alias 位置
[root@aminglinux01 ~]# alias restartnet='systemctl restart network.service'
[root@aminglinux01 ~]# restartnet
Job for network.service failed. See 'systemctl status network.service' and 'journalctl -xn' for details.
[root@aminglinux01 ~]# 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
1,用户家目录 /.bashrc
取消自定义的别名
2,/etc/profile.d/
[root@aminglinux01 ~]# cd /etc/profile.d/
[root@aminglinux01 profile.d]# ls
256term.csh colorgrep.csh colorls.sh less.csh vim.sh
256term.sh colorgrep.sh lang.csh less.sh which2.csh
bash_completion.sh colorls.csh lang.sh vim.csh which2.sh
[root@aminglinux01 profile.d]#
unalias 别名
通配符
满足条件的任一个
? 满足条件的某一个
【】范围 范围内满足条件的范围 [0-9a-zA-Z]
{,,,} 范围内满足条件的某一个
重定向
输出重定向
正确输出到目标文件
cat 1.txt > 2.txt 把 1.txt 的内容输出到 2.txt 去,同时把 2.txt 原内容抹去
> 追加重定向
cat 2.txt >>2.txt 把 1.txt 的内容输出到 2.txt 去,同时把 2.txt 原内容保留
2> 错误重定向输出
输出重定向,错误输出重定向分开
ls: 无法访问 aaa.txt: 没有那个文件或目录
[root@aminglinux01 ~]# ls [12].txt aaa.txt > 1.txt 2>a.txt
[root@aminglinux01 ~]# cat 1.txt
1.txt
2.txt
[root@aminglinux01 ~]# cat a.txt
&> 错误重定向
ls: 无法访问 aaa.txt: 没有那个文件或目录
[root@aminglinux01 ~]# ls [12].txt aaa.txt &> a.txt
[root@aminglinux01 ~]# cat a.txt
1.txt
2.txt
2>> 错误追加重定向ls: 无法访问 aaa.txt: 没有那个文件或目录
[root@aminglinux01 ~]# ls aaa.txt 2>>a.txt
[root@aminglinux01 ~]# cat a.txt
1.txt
2.txt
ls: 无法访问 aaa.txt: 没有那个文件或目录< 输入重定向
只能文件到命令,不能文件到文件
[root@aminglinux01 ~]# wc -l 1.txt
2 1.txt
[root@aminglinux01 ~]# wc -l < 1.txt
2
shell 命令,别名,通配符,重定向
来源: http://www.bubuko.com/infodetail-2456831.html