Linux centos7 shell 介绍、 命令历史、命令补全和别名、通配符、输入输出重定向
一、shell介绍
shell脚本是日常Linux系统管理工作中必不可少的,不会shell,就不是一个合格管理员。
shell是系统跟计算机硬件交互使用的中间介质,一个系统工具。实际上在shell和计算机硬件之间还有一层——系统内核。如果吧计算机比作人的躯体,那系统内核就是人的大脑,至于shell,把它比做人的五官更贴切。
其实,用户直接面对的不是计算机硬件而是shell,用户把指令告诉shell,然后shell再传给系统内核,接着内核再去支配计算机硬件去执行各种操作。
CentOS安装的shell版本是bash(Bourne Again Shell),是sh(Bourne Shell)的增强版。Bourne Shell是最早流行起来的版本,创始人是Steven Bourne,为了纪念他将其命名为Bourne Shell 简称sh
二、命令历史
我们执行过的命令都会记录,预设可记录1000条历史命令,这些命令保存在用户的家目录的.bash_history文件中。
只有当用户正常退出当前shell时,在当前shell中运行的命令才会保存至.bash_history
!是与命令历史有关的一个特殊字符
!!:连续连个表示执行上一条指令
!n:这里的n是数字,表示执行命令史中的第n条指令
!字符串(字符串大于等于1):!pw表示执行历史最近一次以pw开头的命令
[root@davery ~]# ls /root/.bash_history
/root/.bash_history
[root@davery ~]#
[root@davery ~]# cat !$ 可存1000条
cat /root/.bash_history
ping wwwbaiducom
vi /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network.service
ifconfig
route -n
ping www.baidu.com
if config
ifconfig
ping wwww.baudu.com
systemctl restsrt network.service
systemctl restart network.service
journactl -xe
systemctl status network.service
etc/profile
systemctl restart network.service
ssh 192.168.1.106
....
[root@davery ~]# echo $HISTSIZE 查看可保存多少
1000
[root@davery ~]#history -c 清除历史命令,但不会删除命令,依旧可以使用命令
[root@davery ~]# history 查看使用过的命令
[root@davery ~]# vi /etc/profile 查看文本
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000 最大存储量
改为500条
HISTSIZE=5000
[root@davery ~]# echo $HISTSIZE
1000
[root@davery ~]# source /etc/profile 刷新一下
[root@davery ~]# echo $HISTSIZE
5000
[root@davery ~]#
[root@davery ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S " 指定格式
[root@davery ~]# echo $HISTTIMEFORMAT
%Y/%m/%d %H:%M:%S
[root@davery ~]# vi /etc/profile
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=5000
HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S " 粘贴变量
[root@davery ~]#
[root@davery ~]# vi /etc/profile
[root@davery ~]# source /etc/profile
[root@davery ~]# echo $HISTTIMEFORMAT
%Y/%m/%d %H:%M:%S
[root@davery ~]#
chattr +a ~ /.bash_history 永久保存
[root@davery ~]# chattr +a ~/.bash_history
[root@davery ~]# init 0 正常关机才能保存
[root@davery ~]# pwd
/root
[root@davery ~]# !! 执行上一条命令
pwd
/root
[root@davery ~]# !555 执行第555条命令
fdisk -l
[root@davery ~]# !pw 执行最近一次以pw开头的命令
pwd
/root
[root@davery ~]#
三、命令补全和别名
1.命令补全:Tab,敲一下,可以帮我们补全一个指令、一个路径或者一个文件名;敲两下,系统会把所有的命令或者文件都列出来
参数补全,安装bash-completion
[root@davery ~]# yum install -y bash-completion
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 bash-completion.noarch.1.2.1-6.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=========================================================================================================================================
Package 架构 版本 源 大小
=========================================================================================================================================
正在安装:
bash-completion noarch 1:2.1-6.el7 base 85 k
事务概要
=========================================================================================================================================
安装 1 软件包
总下载量:85 k
安装大小:259 k
Downloading packages:
bash-completion-2.1-6.el7.noarch.rpm | 85 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 1:bash-completion-2.1-6.el7.noarch 1/1
验证中 : 1:bash-completion-2.1-6.el7.noarch 1/1
已安装:
bash-completion.noarch 1:2.1-6.el7
完毕!
[root@davery ~]# reboot
[root@davery ~]# system
systemctl systemd-coredumpctl systemd-inhibit systemd-run
systemd-analyze systemd-delta systemd-loginctl systemd-stdio-bridge
systemd-ask-password systemd-detect-virt systemd-machine-id-setup systemd-sysv-convert
systemd-cat systemd-escape systemd-notify systemd-tmpfiles
systemd-cgls systemd-firstboot systemd-nspawn systemd-tty-ask-password-agent
systemd-cgtop systemd-hwdb systemd-path
[root@davery ~]# systemctl res
rescue reset-failed restart
2.别名
alias给命令重新起名字
用户自己的配置别名文件 ~/.bashrc
或者在ls /etc/profile.d/
取消自定义别名
unalias
自定义alias放到~/.bashrc
[root@davery ~]# systemctl restart network.service
[root@davery ~]# alias restartsev='systemctl restart network.service'
[root@davery ~]# restartsev
[root@davery ~]# 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 restartsev='systemctl restart network.service'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@davery ~]#
用户自己的配置别名文件 ~/.bashrc
[root@davery ~]# vi .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@davery ~]# unalias restartsev 取消别名
[root@davery ~]#
[root@davery ~]# restartsev
-bash: restartsev: 未找到命令
[root@davery ~]#
四、通配符、、输入输出重定向
ls *.txt
ls ?.txt
ls [0-9].txt
ls {1,2}.txt
cat 1.txt > 2.txt 把1.txt指定输入到2.txt
cat 1.txt >> 2.txt 把1.txt追加到2.txt
ls aaa.txt 2 >err
ls aaa.txt 2 >>err
wc -| < 1.txt
command >1.txt 2>&1
[root@davery ~]# ls *.txt
[root@davery ~]# ls *
0.txt.gz 4913 5036 anaconda-ks.cfg.01 anaconda-ks.cfg.1 davery davery~ user1
1.txt:
make:
uear1:
[root@davery ~]#
[root@davery ~]# touch 1.txt
[root@davery ~]# touch 2.txt
[root@davery ~]# touch 3.txt
[root@davery ~]# ls ?.txt
2.txt 3.txt
1.txt:
[root@davery ~]#
[root@davery ~]# ls [0-3].txt
2.txt 3.txt
1.txt:
[root@davery ~]# ls [1].txt
[root@davery ~]# ls [123].txt
2.txt 3.txt
1.txt:
[root@davery ~]# ls [13].txt
3.txt
1.txt:
[root@davery ~]# ls [23].txt
2.txt 3.txt
[root@davery ~]#
[root@davery ~]# ls [0-9a-zA-Z].txt
2.txt 3.txt
1.txt:
[root@davery ~]#
[root@davery ~]# ls {1,2,3,}.txt
ls: 无法访问.txt: 没有那个文件或目录
2.txt 3.txt
1.txt:
[root@davery ~]#
输入、输出重定向
[root@davery ~]# cat 1.txt > 2.txt
[root@davery ~]# cat 1.txt >> 2.txt
[root@davery ~]# ls [12].txt aaa.txt &> 2.txt
[root@davery ~]# ls 2.txt
2.txt
[root@davery ~]# ls [12].txt aaa.txt &>> 2.txt
[root@davery ~]# wc -l < 1.txt
转自:https://www.cnblogs.com/davery/p/8721049.html
Linux centos7 shell 介绍、 命令历史、命令补全和别名、通配符、输入输出重定向的更多相关文章
- Linux在shell中输入历史命令
在Linux的shell中,经常输入的命令有很多雷同,甚至是一样的, 如果是长命令,再次敲一遍效率真的是很低, 不过可以通过Ctl+r, 查找history中以前输入的命令,很是好用. 按Ctrl+ ...
- 8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向
8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向 什么是shell? shell是一个命令解释器,提供用户和及其之间的交互 致辞特定语法,比如逻 ...
- shell介绍、命令历史、命令补全和别名、通配符、输入输出重定向
第5周第5次课(4月20日) 课程内容: 8.1 shell介绍8.2 命令历史8.3 命令补全和别名8.4 通配符8.5 输入输出重定向 8.1 shell介绍 使用yum+管道方式查看zsh和ks ...
- Linux笔记(shell基础,历史命令,命令补全/别名,通配符,输出重定向)
一.shell 基础 shell是个命令解释器,提供用户和机器之间的交互 每个用户都可以拥有自己特定的shell centos7默认Shell为bash(Bourne Agin shell) 除了ba ...
- 【Linux基础】history查看历史命令
1.history命令 “history”命令就是历史记录.它显示了在终端中所执行过的所有命令的历史. history //显示终端执行过的命令 history //显示最近10条终端执行过的命令 C ...
- Linux的简单介绍和常用命令的介绍
Linux的简单介绍和常用命令的介绍 本说明以Ubuntu系统为例 Ubuntu系统的安装自行百度,或者参考http://www.cnblogs.com/CoderJYF/p/6091068.html ...
- rlwrap: command not found和解决linux下sqlplus 提供浏览历史命令行的功能
rlwrap工具可以解决linux下sqlplus 提供浏览历史命令行的功能,和删除先前输入错误的字母等问题 1.安装 需要readline包 这个安装光盘就有 [root@asm RedHat]# ...
- .Neter玩转Linux系列之四:Linux下shell介绍以及TCP、IP基础
基础篇 .Neter玩转Linux系列之一:初识Linux .Neter玩转Linux系列之二:Linux下的文件目录及文件目录的权限 .Neter玩转Linux系列之三:Linux下的分区讲解 .N ...
- bash特性-命令历史命令行编辑
bash: GUI:Gnome,KDE,XFCE CLI:sh,csh,bash,ksh,tcsh,zsh shell,子shell tree:查看目录树 pstree:查看进程目录树 bash: 1 ...
随机推荐
- 温故知新的错题训练:Coin game
传送门:http://192.168.173.163/JudgeOnline/problem.php?cid=1244&pid=1 输赢规则:无法再放下硬币的人就输. 博弈论的基本假定:他俩都 ...
- 回形数字矩阵(Java)
将矩阵从里到外分为多层,每一层都是一个口字型数字序列,方向都是顺时针/逆时针,由此我们可以将问题分解为相同的子问题来解决 回形矩阵概述 ☃ 回形矩阵有n行n列 ☃ 数字按顺时针或者逆时针递增 **使用 ...
- 腾讯短链接url生成接口/腾讯短网址在线生成/新浪微博短链接生成器的分享
在通常情况下,URL是由系统生成的,通常包括URI路径,多个查询参数,可以对参数进行加密和解密. 当人们要分享某个URL,比如短信,邮件,社交媒体,这就需要短URL.而短网址,顾名思义就是在长度上比较 ...
- Python之路Day01
一.Python简介 Python的历史 Python 2.4 - November 30, 2004, 同年目前最流行的WEB框架Django 诞生 In November 2014, it was ...
- [NOI2010] 超级钢琴 - 贪心,堆,ST表
这也算是第K大问题的套路题了(虽然我一开始还想了个假算法),大体想法就是先弄出最优的一批解,然后每次从中提出一个最优解并转移到一个次优解,用优先队列维护这个过程即可. 类似的问题很多,放在序列上的,放 ...
- python3练习100题——027
又是一道迭代的题,没做好. 看了答案才试着写出来. 我一定要加油啊,为了尽快摆脱现在讨厌的生活! 原题链接:http://www.runoob.com/python/python-exercise-e ...
- 2018-2019-20175334实验四《Android程序设计》实验报告
2018-2019-20175334实验四<Android程序设计>实验报告 一.实验内容及步骤 实验四 Android程序设计-1 Android Stuidio的安装测试: 参考< ...
- JS高级---逆推继承看原型
逆推继承看原型 function F1(age) { this.age = age; } function F2(age) { this.age = age; } F2.prototype = new ...
- Mysql中判断是否存在
不能像sqlserver一样用if not exists或者exists,应该这样: DECLARE p_count int; set p_count=0; select 1 into p_count ...
- vuecli+axios的post请求传递参数异常
大多数的web服务器只能识别form的post的请求,即请求头Content-Type为’application/x-www-form-urlencoded‘ axios.defaults.heade ...