介绍(摘自百度百科):linux
Shell是系统的用户界面,提供了用户与内核进行交互操做的一种接口。它接收用户输入的命令并把它送入内核去执行 。
实际上Shell是一个命令解释器,它解释由用户输入的命令而且把它们送到内核。不只如此,Shell有本身的编程语言用于对命令的编辑,它容许用户编写由shell命令组成的程序。Shell编程语言具备普通编程语言的不少特色,好比它也有循环结构和分支控制结构等,用这种编程语言编写的Shell程序与其余应用程序具备一样的效果。
Linux提供了像MicrosoftWindows那样的可视的命令输入界面--X Window的图形用户界面(GUI)。它提供了不少桌面环境系统,其操做就像Windows同样,有窗口、图标和菜单,全部的管理都是经过鼠标控制。GNOME。
每一个Linux系统的用户能够拥有他本身的用户界面或Shell,用以知足他们本身专门的Shell须要。
同Linux自己同样,Shell也有多种不一样的版本。
主要有下列版本的Shell: Bourne Shell:是贝尔实验室开发的。 BASH:是GNU的Bourne Again Shell,是GNU操做系统上默认的shell。 Korn Shell:是对Bourne SHell的发展,在大部份内容上与Bourne Shell兼容。 C Shell:是SUN公司Shell的BSD版本。 Z Shell:The last shell you’ll ever need! Z是最后一个字母,也就是终极Shell。它集成了bash、ksh的重要特性,同时又增长了本身独有的特性。shell
history:显示使用过的全部命令;
history -c:清空当前内存中的历史命令,没法清空配置文件;
!!:执行上一条命令;
!n:执行命令历史中的第n条;
!字符串:执行最近一次使用这个字符串开头的命令编程
系统内置的环境变量,它决定了你所能保存的命令历史的条数vim
[root@centos001 ~]# echo $HISTSIZE 1000
在/etc/profile中修改;
用/HISTSIZE找到并修改;
source /etc/profile重启生效。centos
[root@centos001 ~]# vi /etc/profile [root@centos001 ~]# source /etc/profile [root@centos001 ~]# echo $HISTSIZE 5000
[root@centos001 ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S" [root@centos001 ~]# history 1 2017/11/15 23:35:22dhclient 2 2017/11/15 23:35:22ip addr 3 2017/11/15 23:35:22vi /etc/sysconfig/network-scripts/ifcfg-ens33 4 2017/11/15 23:35:22systemctl restart network.service
需更改配置文件;
打开配置文件/etc/profile; 找到HISTSIZE变量的位置并在下面添加HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"
保存退出后并重启服务bash
[root@centos001 ~]# vim /etc/profile [root@centos001 ~]# source !$ source /etc/profile
chattr +a ~/.bash_history追加权限(没法删除);
在没有正常退出的状况下,history保存的命令历史是不完整的。编程语言
以前屡次使用的 TAB键,能够帮咱们补全一个指令、路径或文件名。连续按两次,则会吧全部的相关文件名或指令列出来。注:centos7默认不支持补全命令须安装一个包bash-completion,且 重启后生效。centos7
语法:**alias【别名】=‘命令’ **, 当命令过长时咱们能够给它设置别名,方便咱们使用;
存放位置:第一个是存放在用户家目录下的 .bashrc 文件中,第二个是存放在 /etc/profile.d 目录下的 colorls.sh 和 colorgrep.sh 脚本中定义的。操作系统
在bash下,可使用***来匹配零个或多个字符。用?**来匹配一个字符rest
[root@centos001 ~]# ls 111 234 3.txt aminglinux dir3 ls2 123 2.txt aling anaconda-ks.cfg.1 dir3.tar test 22.txt 2.txt.zip aming d6z linux计划.txt yum.log [root@centos001 ~]# ls *.txt 22.txt 2.txt 3.txt linux计划.txt [root@centos001 ~]# ls *txt 22.txt 2.txt 3.txt linux计划.txt [root@centos001 ~]# ls *txt* 22.txt 2.txt 2.txt.zip 3.txt linux计划.txt [root@centos001 ~]# ls 1* 111: aming3 123: [root@centos001 ~]# ls ?.txt 2.txt 3.txt [root@centos001 ~]# ls [0-3].txt //可一用括号加数字显示范围 2.txt 3.txt [root@centos001 ~]# ls {1,2}.txt // 花括号也能够 可是里面用逗号 ,表或者的意思 ls: 没法访问1.txt: 没有那个文件或目录 2.txt
输入定向用于改变命令的输入,输出定向用与改变命令的输出。输出定向更经常使用,用于将命令的结果输入文件中,而不是屏幕上
输入是**<,且输入重定向,左边必须是命令,不支持文件输入重定向到文件中的;
输出是>** ;
错误重定向命令:2>:它会把命令产生的错误信息指定输入到一个文件中去;
追加剧定向命令:**>>**在原来基础上增长。
[root@centos001 ~]# lsaaa -bash: lsaaa: 未找到命令 [root@centos001 ~]# lsaaa 2> 2.txt -bash: 2.txt: 权限不够 [root@centos001 ~]# lsaaa 2> 1.txt [root@centos001 ~]# cat 1.txt -bash: lsaaa: 未找到命令 [root@centos001 ~]# lsaaa 2>> 1.txt [root@centos001 ~]# cat 1.txt -bash: lsaaa: 未找到命令 -bash: lsaaa: 未找到命令 [root@centos001 ~]# ls [12].txt aaa.txt & > a.txt //1.把正确错误一块儿输出到一个文件 [2] 27725 [root@centos001 ~]# ls: 没法访问aaa.txt: 没有那个文件或目录 1.txt 2.txt ^C [2]- 退出 2 ls --color=auto [12].txt aaa.txt [root@centos001 ~]# ls [12].txt aaa.txt > 1.txt 2>a.txt //第二种写法 [root@centos001 ~]# cat 1.txt 1.txt 2.txt [root@centos001 ~]# cat a.txt ls: 没法访问aaa.txt: 没有那个文件或目录 [root@centos001 ~]# cat a.txt ls: 没法访问aaa.txt: 没有那个文件或目录 [root@centos001 ~]# wc -l <1.txt //输入重定向 2 [root@centos001 ~]# 2.txt < 1.txt //语法错误 -bash: 2.txt: 未找到命令