2018-03-07 Linux学习

本文详细介绍CentOS 7中的shell命令解释器bash的功能与使用方法,包括命令历史、补全与别名设置、通配符用法及输入输出重定向等实用技巧。

8.1 shell介绍

shell 是一个命令解释器,提供用户和机器之间的交互
支持特定语法,比如逻辑判断、循环
每个用户都可以有自己特定的shell
CentOS7默认shell为bash(Bourne Agin Shell)

还有zsh、ksh等

8.2 命令历史

history
.bash_history
默认1000条
变量HISTSIZE
/etc/profile 中修改
HISTTIMEFORMAT="%Y%m%d %H:%M:%S "   指定历史记录的格式
永久保存 chattr +a ~/.bash_history
!!       //上次执行的命令
!n       //执行第几条命令
!word    //word 最近执行命令的前几个字符

    [root@aming-01 ~]# echo $HISTSIZE
    1000
    [root@aming-01 ~]# vim /etc/profile    //更改HISTSIZE=2000
    [root@aming-01 ~]# echo $HISTSIZE
    1000
    [root@aming-01 ~]# source /etc/profile
    [root@aming-01 ~]# echo $HISTSIZE
    2000

history -c  清空内存中的命令记录

    [root@aming-01 ~]# vim /etc/profile
            HISTSIZE=2000
            HISTTIMEFORMAT="%Y%m%d %H:%M:%S "   //添加的
    [root@aming-01 ~]# source /etc/profile
    [root@aming-01 ~]# history

8.3 命令补全和别名

    [root@aming-01 d6z]# rpm -q bash-completion
    bash-completion-2.1-6.el7.noarch
    [root@aming-01 d6z]# yum install -y bash-completion
    安装完成后需要重启才能支持

tab键,敲一下,敲两下
参数补全,安装 bash-completion
alias 别名给命令重新起个名字
各用户都有自己配置别名的文件 ~/.bashrc
ls /etc/profile.d/
自定义的 alias 放到 ~/.bashrc

8.4 通配符

ls *.txt
ls ?.txt
ls [0-9].txt
ls {1,2}.txt
cat 1.txt > 2.txt
cat 1.txt >> 2.txt
ls aaa.txt 2> err
ls aaa.txt 2>> err
wc -l < 1.txt
command > 1.txt 2> &1

*    任意字符
?   一个任意字符
[]   方括号中的字符任选一个
{}   花括号中的字符任选一个

8.5 输入输出重定向

>   输出
>>  追加
2>  错误输出
2>> 错误输出追加
<   输入

    [root@aming-01 ~]# ls > 1.txt
    [root@aming-01 ~]# w >> 1.txt
    [root@aming-01 ~]# lsaa 2>> 1.txt
    [root@aming-01 ~]# cat 1.txt
    1.txt
    anaconda-ks.cfg
     23:08:03 up  1:04,  1 user,  load average: 0.00, 0.01, 0.05
    USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/0    192.168.104.1    22:04    3.00s  0.18s  0.01s w
    -bash: lsaa: 未找到命令

    [root@aming-01 ~]# wc -l < 1.txt
    6

转载于:https://blog.51cto.com/9298822/2083940

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值