启动虚拟机以后,第一件要作的事情就是登陆系统,只有在输入正确的用户名/密码成功登陆以后才能在系统上进行相关的操做。html
图形界面下的CentOS6.10和CentOS7.6的登陆界面不尽相同,以下图所示展现了CentOS6.10的登陆界面。
默认是推荐使用普通用户(例如这里的guanglei)登陆系统,若是想要使用其余用户登陆,能够点击Other...
而后输入密码,点击登陆按钮便可
由于root用户的权限强大到几乎能够进行任何操做,在以root用户登陆系统时,系统会给出提示,以下图所示关闭了root登陆的提示
root登陆成功以后的界面
node
不过生产环境下通常不推荐直接使用root用户,点击右上角的root,而后点击switch user切换用户
mysql
而后以普通用户guanglei登陆系统
输入密码,点击Login In便可登陆系统
linux
登陆成功以后将会看到以下所示的系统界面
nginx
那么系统如何区分登陆的用户是普通用户仍是管理员(超级)用户呢?
CentOS7.6系统中可使用 id -u命令查看用户的id,其中root用户的id为0,普通用户id从1000开始编号,以下命令所示git
[root@centos7 ~]# id -u 0 [root@centos7 ~]# su guanglei [guanglei@centos7 root]$ id -u 1000 [guanglei@centos7 root]$
而centOS6.10中的root用户id为0,可是普通用户的id是从500开始编号,以下命令所示sql
[root@centOS6 ~]# id -u 0 [root@centOS6 ~]# id -u guanglei 500
CentOS7.6系统的登陆和CentOS6.10的系统界面不一样,可是功能是相似的,都默认是以普通用户登陆系统,而后想要切换其余用户,能够点击Not Listed?
而后输入想要登陆的用户名(这里以root为例),而后点击Next
接下来输入密码,点击Sign in即可以登陆系统
系统登陆成功以后会出现以前安装CentOS7.6系统时须要完成对应的初始化操做,这里再也不赘述。
登陆成功以后会看到以下所示的系统界面
shell
为了安全性考虑,仍是注销以后切换回普通用户后登陆
数据库
而后选择普通用户guanglei
输入密码点击Sign in后登陆系统
登陆成功以后会看到以下图所示的系统界面
apache
在学习环境使用CentOS图形界面时,须要输入用户名/密码登陆系统,那样有时候不是太便捷,这里提供一种方式,经过修改配置文件添加root用户自动登陆。
首先鼠标右键打开终端,而后切换成root用户(须要输入密码),再使用gedit命令修改/etc/gdm/custom.conf文件,以下图所示是CentOS7.6的修改
只要在[daemon]下添加AutomaticLoginEnabled=true和AutomaticLogin=root,而后按Ctrl+s保存后重启(使用reboot命令)系统便可。
以下图所示是CentOS6.10的修改
若是想要在系统登陆成功后给用户相关的提示(例如植入点广告),能够修改/etc目录下的mtcd文件,该文件的默认内容为空,能够参考以下命令实现
[root@centos7 ~]#echo "欢迎跟光磊一块儿学习Linux系统运维与架构设计" > /etc/motd
而后使用exit命令退出当前会话,再次登陆系统后,会看到以下提示内容(广告植入)
Last login: Sun Jan 13 03:31:16 2019 from 192.168.190.1 欢迎跟光磊一块儿学习Linux系统运维与架构设计 [root@centos7 ~]#
咱们(开发者,普通用户)日常使用的操做系统绝大多数都是Windows(Windows7或者Windows10) ,主要用它来完成聊天,购物,听音乐,看电影等平常需求,并且Windows之因此广受欢迎的缘由就是其图形化界面简单易懂,可以快速上手。
可是Linux(CentOS)通常都是运行在服务器端,提供后台的各类服务(HTTP,SFTP,分布式存储,分布式计算),一般都是没有图形化界面进行相关操做,并且以前提到过安装系统时,生产环境通常都是选择最小化安装,这样有利于系统瘦身,也可以减小问题的发生,提升系统运行性能。
并且通常特大型互联网公司(谷歌,苹果,亚马逊)生产环境的服务器都是放置在世界各地的机房,如今国内的大部分中小型互联网公司也已经将服务部署在阿里云、腾讯云,通常不会再单独购买服务器。
那么咱们(开发者、运维工程师)如何操做Linux呢?
这时候就能够借助终端来进行相关的操做了,以前在CentOS6.10上安装过VMareTools,使用鼠标右键Open In Terminal,这时候就启动了一个终端。
若是要将终端进行分类,经常使用的终端类型能够分为以下几大类:
在运维应用场景中最常使用的就是虚拟终端,在安装CentOS系统以后,通常会自带1个桌面终端和5个字符终端(字符终端也就意味着不能使用鼠标),在进入系统以后可使用Ctrl+Alt+F1切换图形界面终端,Ctrl+Alt+[F2-F6]来切换不一样的字符界面终端。
以下图所示是使用Ctrl+Alt+F2切换的CentOS7.6的字符界面
能够经过输入用户名和密码来登陆终端
若是想要切回图形界面终端,只须要按Ctrl+Alt+F1便可。
若是在切换Ctrl+Alt+F2-Ctrl+Alt+F6之间的五个字符界面窗口时忘记是哪一个窗口,则可使用ttty命令查看,以下图所示,若是是tty6则表示为Ctrl+Alt+F6对应的字符界面。
在字符界面中同时还可使用chvt加上数字实现字符界面的切换,以下命令所示
[root@centos6 ~]# chvt 5
在SecureCRT中登陆CentOS7.6系统以后,可使用who命令查看当前登陆的终端信息,以下命令输出显示tty为本机终端登陆,而pts表示远程终端登陆。
[root@centos7 ~]# who root :0 2019-01-11 07:53 (:0) guanglei tty4 2019-01-11 08:08 guanglei tty2 2019-01-11 08:11 root pts/0 2019-01-11 08:15 (192.168.190.1)
若是想要查看终端设备信息,可使用tty命令,以下命令输出结果显示终端的路径
[root@centos7 ~]# tty /dev/pts/0
还能够经过whoami 查看当前登陆系统的用户身份(命令)
[root@centos7 ~]# whoami root
经过who am i 查看当前登陆用户以及终端信息
root@centos7 ~]# who am i root pts/0 2019-01-11 08:15 (192.168.190.1)
经过w命令能够查看到更多信息输出,包含当前登陆的用户及其正在运行的程序
[root@centos7 ~]# w 08:20:21 up 26 min, 4 users, load average: 0.00, 0.01, 0.02 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root :0 :0 07:53 ?xdm? 36.60s 0.30s /usr/libexec/gnome-session-bi guanglei tty4 08:08 11:57 0.02s 0.02s -bash guanglei tty2 08:11 8:21 0.02s 0.02s -bash root pts/0 192.168.190.1 08:15 5.00s 0.06s 0.03s w
平常运维工做中为了提升系统运行性能,一般不会使用到图形界面,若是想要关闭图形界面,可使用init 3来切换系统的运行模式为字符界面模式。
[root@centOS6 ~]# init 3
若是想要查看当前系统的运行模式,可使用runlevel查看,以下命令输出
的结果展现从5切换到3,即init 5表示切换到图形界面运行模式,init 3表示切换到字符界面运行模式
[root@centOS6 ~]# runlevel 5 3
还可使用who -r查看
[guanglei@centos7 ~]$who -r run-level 5 2019-02-11 10:26 last=3
图形界面和字符界面的区别是,字符界面的平常操做都是经过键盘来完成的,并且能够实现自动化,批量化,自能化,相比图形界面更加高效便捷,而图形界面能够借助鼠标加键盘完成平常任务。
而Linux的图形界面和Windows不一样,Linux的图形界面只是运行在内核之上的应用程序,能够经过运行startx命令启动图形界面程序,固然前提条件是系统安装时已经安装了图形界面,例如KDE,GNOME。
[root@centOS6 ~]# startx
当再次输入runlevel(SecureCRT须要新开个会话)查看系统运行模式时,发现系统的运行模式依然是字符界面模式,只是额外开启了一个图形界面的程序而已,并且init 5和startx不一样的是,它还会启动一些额外的服务。
[root@centOS6 ~]# runlevel 5 3
若是想要关闭startx启动的图形界面,只须要按键盘ctrl+x便可退出图形界面。
若是想要退出当前会话,可使用exit或者logout命令退出,退出以后会看到以下的效果
在平常运维的工做场景中一般都不会直接接触机房的机器,都是使用SSH 客户端经过网络链接远程的服务器。
在使用SecureCRT链接CentOS以前,须要首先获取CentOS6.10的ip地址,在登录系统以后,经过右键Open in Terminal,打开CentOS系统的终端。
而后经过ifconfig命令来查看系统的ip地址,以下图所示
ip地址是192.168.0.107
而后在windows的dos窗口下使用ping命令检测是否可以ping通,若是ping通就会看到以下图所示的效果
首先在CentOS7.6的桌面鼠标右键,打开终端后输入ifconfig命令查看CentOS7.6的ip地址
而后将SecureCRT原来链接CentOS6.10的会话配置复制一份并重命名为192.168.0.106@CentOS7.6,并将原来的会话改成192.168.0.107@CentOS6.10。
固然若是想要登陆CentOS7.6,还须要在192.168.0.106@CentOS7.6的属性中修改SSH2通信的主机IP地址以及登陆的用户名(这里是以root用户登陆),以下图所示
登陆成功以后会看到以下图所示的结果
首先在SecureCRT的菜单栏中找到Options->Session Options,而后作相关的设置。
随着计算机的发展,其人机交互方式也是在不断地演进,从最先出现的基于字符界面交互的Unix系统到后来的基于图形界面交互的Windows,macOS系统以及借助语音手势,声音触控的交互方式的Android和IOS。
而绝大部分Linux都是做为后台服务器的系统,绝大部分操做都是由字符界面的命令行完成。
当用户输入命令时,Shell程序会负责将用户输入的命令提交给内核,并接收内核的执行结果返回给用户,sHell仍是一种高级程序设计语言,能够编写Shell脚本完成复杂的任务,以下图所示展现了Shell在系统中的结构图。
Linux下的可用Shell有许多实现,能够经过cat命令查看/etc/shells文件的输出结果得知
[root@centOS6 ~]# cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/dash /bin/tcsh /bin/csh
而系统启动以后,默认启动的shell是bash shell,可使用echo $SHELL查看当前使用的shell程序是什么?以下命令输出结果显示默认的就是/bin目下的bash shell。
[root@centOS6 ~]# echo $SHELL /bin/bash
那么如何切换不一样的shell呢?从以前的cat /etc/shells文件中能够获取各类shell程序的路径,只要输入它们的路径即可以实现切换,以下命令所示
[root@centOS6 ~]# /bin/csh
而后再使用echo $SHELL查看当前使用的shell程序
[root@centOS6 ~]# echo $SHELL /bin/bash
并且每种shell所支持的命令是不尽相同的,例如咱们能够在bash shell中使用重定向 > liuguanglei.txt建立一个文件
[root@centOS6 ~]# > guanglei.txt
而后使用ls -al |grep guanglei.txt查看以前建立的文件信息,以下命令执行输出结果显示
[root@centOS6 ~]# ls -al|grep guanglei.txt -rw-r--r--. 1 root root 0 Jan 12 10:40 guanglei.txt
可是若是切换到csh shell以后会发现重定向>变成了无效的命令,以下命令执行输出结果显示
[root@centOS6 ~]# cat /etc/shells # 查看可用的shell列表 /bin/sh /bin/bash /sbin/nologin /bin/dash /bin/tcsh /bin/csh [root@centOS6 ~]# /bin/csh [root@centOS6 ~]# > guanglei.txt Invalid null command.
若是想要从csh shell切换到bash shell,可使用exit命令实现,以下命令执行输出结果显示
[root@centOS6 ~]# exit exit
若是想要查看命令的系统调用状况,可使用strace查看,
[root@centos7 ~]# strace ls
当登陆系统以后,系统会提供一个命令提示符,用于展现一些系统的相关信息,例如使用普通用户guanglei登陆CentOS6.10后会看到以下格式的命令提示符
[guanglei@centOS6 ~]$
使用管理员用户root登陆CentOS6.10后会看到以下的格式命令提示符
[root@centOS6 ~]#
它们的不一样之处在于普通用户使用$表示,管理员用户(root)使用#表示,并且命令提示符的固定格式为[用户名@主机名 路径],主机名也只显示部分,能够经过hostname查看完整的主机名
[guanglei@centOS6 ~]$ hostname centOS6.ittimeline.net
路径只显示最后一个目录,经过pwd命令查看当前所处的目录对比得出结论,~表示home目录。
[root@centOS6 ~]# pwd #root用户的目录 /root [guanglei@centOS6 ~]$ pwd #普通用户的目录 /home/guanglei
这里咱们能够定制命令提示符的格式,工做中能够用来区分测试环境和生产环境,防止误操做。
命令提示符的格式定义保存在$PS1变量中,可使用echo $PS1查看命令提示符的格式
[guanglei@centOS6 ~]$ echo $PS1 [\u@\h \W]\$
首先咱们使用vim编辑器在/etc/profile.d目录下建立一个prompt.sh文件,
[root@centOS6 ~]# vim /etc/profile.d/prompt.sh
回车之后默认进入的是命令模式,此时咱们须要输入i键进入插入模式,而后添加以下内容(建议直接复制该内容)
PS1="\[\e[1;32m\][\u@\h \W]\\$\[\e[0m\]"
添加完成后按键esc后按shift和冒号(:),再按wq保存退出。
再从新开启一个会话后会看到以下格式的命令提示符
CentOS7.6系统可使用一样的方式实现修改,首先使用vim编辑器建立一个prompt.sh文件
[root@centos7 ~]# vim /etc/profile.d/prompt.sh
而后在该文件中添加以下内容
PS1="\[\e[1;36m\][\u@\h \W]\\$\[\e[0m\]"
再关闭会话后,从新开启一个会话窗口后会看到以下图所示的效果
运维人员使用CentOS时,一般都是使用命令来完成平常任务,例如以前使用过的vim,cat,pwd等等。
当Bash Shell随着系统启动后,负责监听用户从键盘输入的命令,而用户输入命令并回车之后,Bash Shell会判断它是内部命令仍是外部命令,若是是内部命令,则直接从内存中缓存的内部命令列表查找后提交给内核执行,而后将返回结果返回给用户,若是是外部命令,首先从$PATH环境变量中查找命令所对应的二进制程序,若是没有找到则直接输出 command not found...,若是找到会将命令的二进制程序提交给内核执行,而后将执行的结果返回给用户,并会将外部命令缓存在内存中,下次执行时可以直接从内存中的缓存获取,提升执行效率。
在Linux Shell中能够执行的命令分为两类,内部命令和外部命令,若是想要查看运行的命令是内部命令或者是外部命令,可使用type命令查看,以下命令输出显示cd和pwd是内置命令,init是外部命令,若是是内部命令。输出 comand is a shell builtin,若是是外部命令输出命令对应的执行路径。
[root@centos7 ~]#type cd cd is a shell builtin [root@centos7 ~]#type pwd pwd is a shell builtin [root@centos7 ~]#type init init is /usr/sbin/init
内部命令是Shell(默认是bash shell)自带的,内部命令在系统启动后随Shell加载到内存,所以相对于外部命令执行效率高,若是想要查看哪些可使用的内部命令,可使用enable命令实现,以下命令输出显示bash shell的内置命令。
[root@centos7 ~]#enable enable . enable : enable [ enable alias enable bg enable bind enable break enable builtin enable caller enable cd enable command enable compgen enable complete enable compopt enable continue enable declare enable dirs enable disown enable echo enable enable enable eval enable exec enable exit enable export enable false enable fc enable fg enable getopts enable hash enable help enable history enable jobs enable kill enable let enable local enable logout enable mapfile enable popd enable printf enable pushd enable pwd enable read enable readarray enable readonly enable return enable set enable shift enable shopt enable source enable suspend enable test enable times enable trap enable true enable type enable typeset enable ulimit enable umask enable unalias enable unset enable wait
若是想要禁用或者启用某个内部命令可使用enable -n command命令实现。
当禁用以后再使用禁用的命令则会输出command not found,使用enable命令也查不到对应的命令,若是命令输出显示禁用了type命令
[root@centos7 ~]#enable -n type [root@centos7 ~]#type bash: type: command not found...
若是想要再次启用以前被禁用的内部命令,只须要使用enable command便可。
[root@centos7 ~]#enable type [root@centos7 ~]#type mkdir #使用type查看mkdri的命令类型 mkdir is /usr/bin/mkdir
而外部命令是存放在磁盘路径的可执行的二进制程序,Shell在首次执行外部命令时须要查找的目录是根据$PATH环境变量的路径顺序去查找,而后将外部命令的路径缓存在内存中,以下命令输出显示环境变量对应的路径,Linux下多个路径之间使用:分割。
[root@centos7 ~]#echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
若是在$PATH中查找不到命令对应的路径,则会输出 command not found...,以下命令输出显示
[root@centos7 ~]#xxx bash: xxx: command not found...
若是想要查看内存中缓存的外部命令,可使用hash查看,以下命令输出显示。
[root@centos7 ~]#hash hits command 2 /usr/bin/who 3 /usr/bin/clear
若是想要删除某个hash的缓存,可使用hash -d command实现,以下命令输出显示。其中hits表示缓存命中的次数。
[root@centos7 ~]#hash -d who [root@centos7 ~]#hash hits command 3 /usr/bin/clear
当退出会话以后hash的缓存会被清空,若是想要手动清除缓存,可使用hash -r实现,以下命令输出显示。
[root@centos7 ~]#hash -r [root@centos7 ~]#hash hash: hash table empty
若是想要查看执行外部命令的路径,可使用which实现,以下命令输出显示。
[root@centos7 ~]#which pwd /usr/bin/pwd
而whereis 命令不只能够显示外部命令的路径,还能够显示命令对应的帮助文件,以下命令输出显示。
[root@centos7 ~]#whereis pwd pwd: /usr/bin/pwd /usr/share/man/man1/pwd.1.gz /usr/share/man/man1p/pwd.1p.gz
在后续使用命令操做时,能够经过命令的别名机制来简化命令,例如在网络管理中常常要进入到/etc/sysconfig/network-scripts/目录下,若是未使用别名,经过以下命令实现
[root@centos7 ~]#cd /etc/sysconfig/network-scripts/ [root,就要使用alias 别名=命令 的格式实现 ,以下命令所示 ``` shell alias cdns='cd /etc/sysconfig/network-scripts/
而后即可以使用cdns命令实现cd /etc/sysconfig/network-scripts/的功能了,以下命令输出显示
[root@centos7 network-scripts]#cdns [root@centos7 network-scripts]#pwd /etc/sysconfig/network-scripts
当咱们使用which查看ls的路径时,根据命令的输出实际上也能够得知ls也建立了别名,即 ls='ls --color=auto',以下命令输出显示
[root@centos7 network-scripts]#which ls alias ls='ls --color=auto' /usr/bin/ls
若是想要查看当前系统的内置别名列表,能够直接使用alias命令查看,以下命令输出显示
[root@centos7 network-scripts]#alias alias cdns='cd /etc/sysconfig/network-scripts/' 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 rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
须要注意的是使用alias命令建立的别名只能在当前会话有效,若是退出会话(一般使用exit命令退出会话)后便没法使用。
[root@centos7 network-scripts]#exit
退出以后可使用SecureCRT提供的重连菜单,从新创建一个会话。
当再次输入alias命令查看别名时发现以前建立的别名cdns已经不存在
[root@centos7 ~]#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 rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
那么系统内置的那些别名存储在哪里呢?
若是想要别名永远生效,须要将别名配置在文件中,若是是普通用户通常配置在/home/{user.name}/.bashrc文件中,咱们可使用ls -al |grep .bashrc查看,由于Linux系统中以.开头的文件都是隐藏文件,而ls 命令的-a选项能够查看隐藏文件,而后使用grep命令实现文件过滤,只看.bashrc的详细信息。
[guanglei@centos7 ~]$ls -al|grep .bashrc -rw-r--r--. 1 guanglei guanglei 124 Mar 23 2017 .bashrc
而后使用vim .bashrc编辑文件,将以前的别名添加到.bashrc中
[guanglei@centos7 ~]$alias alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias vi='vim' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
这时咱们须要使用source .bashrc命令将修改的配置刷新到内存中
[guanglei@centos7 ~]$source .bashrc
当再次使用alias命令查看,就会看到cdns别名已经加入到命令的别名列表中
[guanglei@centos7 ~]$alias alias cdns='cd /etc/sysconfig/network-scripts/' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias vi='vim' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
而后即可以使用cdns别名直接切换到/etc/sysconfig/network-scripts目录中了,即便关闭会话或者重启系统也不会失效。
[guanglei@centos7 ~]$cdns [guanglei@centos7 network-scripts]$pwd /etc/sysconfig/network-scripts
而别名和内部命令以及外部命令的优先级顺序从高到低的优先级顺序是
别名>内部命令>外部命令。
后期在学习其余相关的命令时,能够根据本身的喜爱添加别名到.bashrc文件中,以达到快速输入命令的,实现快捷操做。
须要指出的是以前修改的/home/guanglei/.bashrc文件只会针对普通用户guanglei生效,若是此时切换到root用户,再运行cdns别名,系统会提示command not found
[root@centos7 ~]#cdns -bash: cdns: command not found
若是想要普通用户和管理员用户均可以使用cdns这个别名,可使用root用户登陆系统后,修改/etc目录下的bashrc文件
[root@centos7 ~]#vim /etc/bashrc
在bashrc文件的最后一行添加alias cdns ='/etc/sysconfig/network-scripts',以下图所示
而后使用source命令将刚才添加的命令刷新到内存中
[root@centos7 ~]#source /etc/bashrc
接下来就可使用cdns实现快速切换到/etc/sysconfig/network-scripts目录下了
[root@centos7 ~]#cdns [root@centos7 network-scripts]#pwd /etc/sysconfig/network-scripts
若是别名和Linux命令相同,例如ls的别名就是ls,可使用alias ls查看
[root@centos7 network-scripts]#alias ls alias ls='ls --color=auto'
那么根据优先级,默认执行的是别名,那么咱们想要执行ls的原始命令咋办呢?
首先咱们能够根据which --skip-alias ls 命令查看ls命令所在的路径
[root@centos7 network-scripts]#which --skip-alias ls /bin/ls
根据which命令的输出结果得知ls命令位于/bin/ls路径下,即咱们能够输入/bin/ls就能够执行ls的原始命令,以下所示
[root@centOS6 network-scripts]#/bin/ls ifcfg-eth0 ifdown-ippp ifdown-sit ifup-ib ifup-post init.ipv6-global ifcfg-lo ifdown-ipv6 ifdown-tunnel ifup-ippp ifup-ppp net.hotplug ifdown ifdown-isdn ifup ifup-ipv6 ifup-routes network-functions ifdown-bnep ifdown-post ifup-aliases ifup-isdn ifup-sit network-functions-ipv6 ifdown-eth ifdown-ppp ifup-bnep ifup-plip ifup-tunnel ifdown-ib ifdown-routes ifup-eth ifup-plusb ifup-wireless
可是这种方式对于内部命令来讲是无法使用的,还有另一种通用的方式,就是使用一对单引号('')将命令括起来,以下命令所示,便可使用ls的原始命令。
[root@centOS6 network-scripts]#'ls' ifcfg-eth0 ifdown-ippp ifdown-sit ifup-ib ifup-post init.ipv6-global ifcfg-lo ifdown-ipv6 ifdown-tunnel ifup-ippp ifup-ppp net.hotplug ifdown ifdown-isdn ifup ifup-ipv6 ifup-routes network-functions ifdown-bnep ifdown-post ifup-aliases ifup-isdn ifup-sit network-functions-ipv6 ifdown-eth ifdown-ppp ifup-bnep ifup-plip ifup-tunnel ifdown-ib ifdown-routes ifup-eth ifup-plusb ifup-wireless
若是想要取消别名可使用unalias alias_name实现,取消以后别名就没法使用,固然该命令只在当前会话生效,由于从新开启会话后系统会读取以前在/etc/bashrc的配置文件中配置的别名。
[root@centOS6 network-scripts]#unalias cdns [root@centOS6 network-scripts]#alias alias cp='cp -i' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
若是想要禁用全部的别名,可使用unalias -a实现。
[root@centOS6 network-scripts]#unalias -a [root@centOS6 network-scripts]#alias
一般状况下一个完整的Linux命令是由command [options] [arguments]三部分组成的,选项和参数都是可选的
在使用命令时还须要注意如下注意事项
在运维工做场景中,常常会使用大量的命令以及操做文件系统的某些目录,这时可使用TAB键来补全命令或者目录的路径。
TAB补全路径:以下所示输入cd /e而后按TAB键,会自动补全为cd /etc,而后再输入cd sys按TAB键,没有任何结果由于以sys开头的目录不止一个,TAB没法补全路径,
若是此时再按TAB,则会输出sys开头的目录列表。
[root@centos7 ~]#cd /etc [root@centos7 etc]#cd sys sysconfig/ sysctl.d/ systemd/
所以若是想要使用TAB补全目录,输入的目录字符串通过TAB不全以后必须是惟一一个文件夹名,不然再次TAB会给出列表。
不管是系统命令仍是外部命令,均可以使用TAB键补全,和路径补全同样,前提条件是输入的字符串只有惟一一条对应的命令,不然再次TAB会给出命令列表,以下命令输出显示
[root@centos7 etc]#w ##TAB TAB 效果以下所示 w wc which wnck-urgency-monitor wvdialconf wait wdctl while wodim wvgain wall weak-modules whiptail wpa_cli wvunpack watch wftopfa who wpa_passphrase watchgnupg wget whoami wpa_supplicant/ wavpack whatis wipefs write wayland-scanner whereis withsctp wvdial
[root@centos7 etc]#/ bin/ data/ etc/ lib/ media/ opt/ root/ sbin/ sys/ usr/ boot/ dev/ home/ lib64/ mnt/ proc/ run/ srv/ tmp/ var/
[root@centOS6 ~]#$
$_ $CVS_RSH $LINES $QTLIB
$BASH $DIRSTACK $LOGNAME $RANDOM
$BASH_ALIASES $EUID $LS_COLORS $SECONDS
$BASH_ARGC $G_BROKEN_FILENAMES $MACHTYPE $SELINUX_LEVEL_REQUESTED
$BASH_ARGV $GROUPS $MAIL $SELINUX_ROLE_REQUESTED
$BASH_CMDS $HISTCMD $MAILCHECK $SELINUX_USE_CURRENT_RANGE
$BASH_COMMAND $HISTCONTROL $OPTERR $SHELL
$BASH_LINENO $HISTFILE $OPTIND $SHELLOPTS
$BASHOPTS $HISTFILESIZE $OSTYPE $SHLVL
$BASHPID $HISTSIZE $PATH $SSH_ASKPASS
$BASH_SOURCE $HOME $PIPESTATUS $SSH_CLIENT
$BASH_SUBSHELL $HOSTNAME $PPID $SSH_CONNECTION
$BASH_VERSINFO $HOSTTYPE $PS1 $SSH_TTY
$BASH_VERSION $ID $PS2 $TERM
$colors $IFS $PS4 $UID
$COLORS $LANG $PWD $USER
$COLUMNS $LESSOPEN $QTDIR
$COMP_WORDBREAKS $LINENO $QTINC
[root@centOS6 ~]#~ ~abrt/ ~daemon/ ~gopher ~mail/ ~postfix/ ~rtkit/ ~tcpdump/ ~adm ~dbus/ ~guanglei/ ~nfsnobody/ ~pulse ~saslauth ~usbmuxd/ ~apache/ ~ftp ~haldaemon/ ~nobody/ ~root/ ~shutdown/ ~uucp ~avahi-autoipd ~games/ ~halt/ ~ntp/ ~rpc ~sshd/ ~vcsa/ ~bin/ ~gdm/ ~lp/ ~operator/ ~rpcuser/ ~sync/
[root@centOS6 ~]#./ .abrt/ .config/ Desktop/ Downloads/ .gnome2/ .gnupg/ .local/ .nautilus/ Public/ .ssh/ Videos/ .cache/ .dbus/ Documents/ .gconf/ .gnote/ .gvfs/ Music/ Pictures/ .pulse/ Templates/ [root@centOS6 ~]#./ .abrt/ .config/ Desktop/ Downloads/ .gnome2/ .gnupg/ .local/ .nautilus/ Public/ .ssh/ Videos/ .cache/ .dbus/ Documents/ .gconf/ .gnote/ .gvfs/ Music/ Pictures/ .pulse/ Templates/
[root@centOS6 ~]#*/ Desktop/ Documents/ Downloads/ Music/ Pictures/ Public/ Templates/ Videos/
在Linux系统中,系统会保存你输入命令的历史记录,能够用它来重复执行命令,而在登陆bash shell时,系统会读取命令历史文件.bash_history中记录下来的命令,登陆进bash shell后新执行的命令只会缓存在内存中,这些命令在退出以后会追缴到历史命令文件中。
若是想要查看命令历史,可使用history命令实现
[root@centOS6 ~]#history #历史命令输出结果只截取了部分 1 reboot 2 tar -xvf VMwareTools-10.3.2-9925305.tar.gz 3 CLEAR 4 CLS 5 EXIT 6 ./vmware-tools-distrib/vmware-install.pl 7 gedit /etc/gdm/custom.conf 8 reboot 9 ifconfig 10 tty 11 tty 12 whoami 13 who am i 14 pts
若是想要执行命令历史中的命令,只须要使用!加上命令历史的编号便可,以下命令所示
[root@centOS6 ~]#!9 #执行ifconfig命令 ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:18:1B:DE inet addr:192.168.190.128 Bcast:192.168.190.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe18:1bde/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:3053 errors:0 dropped:0 overruns:0 frame:0 TX packets:7588 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:313791 (306.4 KiB) TX bytes:795539 (776.8 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:640 errors:0 dropped:0 overruns:0 frame:0 TX packets:640 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:32120 (31.3 KiB) TX bytes:32120 (31.3 KiB)
固然若是想要倒着执行history中的命令,只须要使用!加上负号开头加上编号便可,以下命令所示
225 history 226 clear 227 vim /etc/profile 228 source /etc/profile 229 clear 230 history 231 ifconfig 232 clear 233 history 234 clear 235 history 236 vim .bash_history 237 history [root@centOS6 ~]#!-7 ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:18:1B:DE inet addr:192.168.190.128 Bcast:192.168.190.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe18:1bde/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5452 errors:0 dropped:0 overruns:0 frame:0 TX packets:19401 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:540056 (527.3 KiB) TX bytes:1878467 (1.7 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:1808 errors:0 dropped:0 overruns:0 frame:0 TX packets:1808 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:90524 (88.4 KiB) TX bytes:90524 (88.4 KiB)
还能够经过键盘上的上下方向键快速切换以前输入过的命令。
若是想要调用前一个命令的最后一个参数,可使用!$表示,以下命令输出显示
[root@centOS6 ~]#ll /etc/profile -rw-r--r--. 1 root root 1841 Jan 12 22:21 /etc/profile [root@centOS6 ~]#cat !$ #这里会实现查看profile文件的内容
若是想要搜索历史命令中的命令,可使用Ctrl+r实现模糊搜索,以下图所示,当使用Ctrl+r搜索sys,系统会将sys关联的命令显示出来,而后回车便可执行。
若是想退出搜索,可使用Ctrl+g。
系统默认只会缓存最近的1000条历史命令,而若是想要记录更多的历史命令,能够经过修改系统配置文件/etc/profile文件中HISTSIZE的值,以下图所示
若是想要清除history中存储在内存中的命令历史,可使用history -c实现,以下命令输出所示
[root@centOS6 ~]#history -c #清除内存中存储的命令历史 [root@centOS6 ~]#history 1 history
若是想要完全的删除命令历史,正确的姿式应该是首先删除.bash_history文件,而后再使用history -c实现删除内存中的命令历史,以下命令所示
[root@centOS6 ~]#rm -rf .bash_history [root@centOS6 ~]#history -c
若是想要实现将history默认存储在内存中的命令历史存储到.bash_history文件中,而不是等到退出会话后存储到.bash_history文件,可使用history -a实现,以下命令所示
[root@centOS6 ~]#history -a [root@centOS6 ~]#cat .bash_history
若是不想要系统记录历史命令,可使用history -p command
实现,以下命令输出显示
[root@centOS6 ~]#history -c [root@centOS6 ~]#history 1 history [root@centOS6 ~]#history -p `ls` anaconda-ks.cfg Desktop Documents Downloads guanglei.new guanglei.txt install.log install.log.syslog Music Pictures Public Templates Videos [root@centOS6 ~]#history 1 history
在系统安装完成之后,能够经过命令查看硬件(CPU,内存,磁盘信息)相关配置。
命令名称:lscpu
命令功能:查看CPU配置信息
执行以下命令输出结果显示CentOS6.10系统的CPU配置信息
[root@centOS6 ~]#lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 12 On-line CPU(s) list: 0-11 Thread(s) per core: 1 Core(s) per socket: 6 Socket(s): 2 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 158 Model name: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz Stepping: 10 CPU MHz: 2904.004 BogoMIPS: 5808.00 Hypervisor vendor: VMware Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 12288K NUMA node0 CPU(s): 0-11
执行以下命令输出结果显示CentOS7.6系统的CPU配置信息
[root@centos7 ~]#lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 12 On-line CPU(s) list: 0-11 Thread(s) per core: 1 Core(s) per socket: 6 Socket(s): 2 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 158 Model name: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz Stepping: 10 CPU MHz: 2904.000 BogoMIPS: 5808.00 Hypervisor vendor: VMware Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 12288K NUMA node0 CPU(s): 0-11 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec arat spec_ctrl intel_stibp flush_l1d arch_capabilities
命令名称:free
命令功能:查看内存,默认单位是字节
经常使用选项:
[root@centos7 ~]#free -m total used free shared buff/cache available Mem: 7964 738 6294 42 930 6867 Swap: 4095 0 4095
更详细的内存信息可使用cat /proc/meminfo查看,以下命令执行结果输出显示
[root@centos7 ~]#cat /proc/meminfo MemTotal: 8155144 kB MemFree: 6443356 kB MemAvailable: 7030460 kB Buffers: 2124 kB Cached: 827496 kB SwapCached: 0 kB Active: 790976 kB Inactive: 603604 kB Active(anon): 566180 kB Inactive(anon): 42576 kB Active(file): 224796 kB Inactive(file): 561028 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 4194300 kB SwapFree: 4194300 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 565000 kB Mapped: 166484 kB Shmem: 43796 kB Slab: 123504 kB SReclaimable: 45424 kB SUnreclaim: 78080 kB KernelStack: 11504 kB PageTables: 34984 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 8271872 kB Committed_AS: 4242784 kB VmallocTotal: 34359738367 kB VmallocUsed: 191876 kB VmallocChunk: 34359310332 kB HardwareCorrupted: 0 kB AnonHugePages: 258048 kB CmaTotal: 0 kB CmaFree: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 190272 kB DirectMap2M: 2955264 kB DirectMap1G: 7340032 kB
命令名称:lsblk
命令功能:列出系统上全部的磁盘
执行以下命令输出结果显示CentOS7.6系统的磁盘配置信息
当前只有一块硬盘(sda)以及一个镜像CentOS 7 x86_64
[root@centos7 ~]#lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 500M 0 part /boot ├─sda2 8:2 0 50G 0 part / ├─sda3 8:3 0 30G 0 part /data ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP] sr0 11:0 1 10G 0 rom /run/media/root/CentOS 7 x86_64
CentOS中可使用ifconfig或者ip add查看网络的ip信息,在CentOS7.6中,ens33表示默认的网卡名称,其ip地址是192.168.0.106。
[root@centos7 ~]#ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.106 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::483f:14a3:763e:2f4b prefixlen 64 scopeid 0x20<link> ether 00:0c:29:cd:a5:0a txqueuelen 1000 (Ethernet) RX packets 3813 bytes 1449499 (1.3 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1587 bytes 219797 (214.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 216 bytes 22416 (21.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 216 bytes 22416 (21.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:28:7e:9d txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ip add查看ip
[root@centOS6 ~]#ip add 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:9f:c5:52 brd ff:ff:ff:ff:ff:ff inet 192.168.0.107/24 brd 192.168.0.255 scope global eth0 inet6 fe80::20c:29ff:fe9f:c552/64 scope link valid_lft forever preferred_lft forever
一般咱们所说的Linux都是指的Linux内核,目前CentOS7.6使用的Linux 3.10版本的内核,而CentOS6.10使用的是Linux2.6的内核。
CenOS6.10内核版本查看
[root@centOS6 ~]#uname -r 2.6.32-754.el6.x86_64
CentOS7.6内核版本查看
[root@centos7 ~]#uname -r 3.10.0-957.el7.x86_64
而若是想要查看Linux的发行版CentOS,可使用cat命令查看/etc/redhat-release文件便可。
CentOS7版本信息查看
[root@centos7 ~]#cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
CentOS6.10版本信息查看
[root@centOS6 ~]#cat /etc/redhat-release CentOS release 6.10 (Final)
在CentOS6.10中还可使用lsb_release -a查看系统版本信息
[root@centOS6 ~]#lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 6.10 (Final) Release: 6.10 Codename: Final
在Linux中有硬件时钟与系统时钟等两种时钟。硬件时钟是指主机板上的时钟设备,也就是一般可在BIOS画面设定的时钟。系统时钟则是指kernel中的时钟。当Linux启动时,系统时钟会去读取硬件时钟的设定,以后系统时钟即独立运做。全部Linux相关指令与函数都是读取系统时钟的设定,并且硬件时钟和系统时钟可能不同。
咱们可使用date命令查看当前系统时间,以下命令输出显示。
[root@centOS6 ~]#date --date=now Sun Jan 13 16:11:18 CST 2019 [root@centOS6 ~]#date Sun Jan 13 16:11:46 CST 2019
还能够经过clock命令查看当前硬件时钟,以下命令输出显示
[root@centOS6 ~]#clock Sat 12 Jan 2019 01:50:07 PM CST -0.688997 seconds
在有些状况下硬件时钟和系统时钟可能不一致,例如这里使用date命令来修改系统时间,修改的日期格式为月日小时分年.秒,以下命令所示
[root@centOS6 ~]#date 123112302019.45 Tue Dec 31 12:30:45 CST 2019 [root@centOS6 ~]#date #修改以后再次使用date命令查看当前系统日期 Tue Dec 31 12:30:45 CST 2019 [root@centOS6 ~]#clock #查看硬件时钟 Sat 12 Jan 2019 01:57:21 PM CST -1.298448 seconds
修改以后此时系统时钟和硬件时钟就会不一致,那么如何让系统时间和硬件保持一致呢?可使用clock -s实现将系统时间同步硬件时间,而后再使用date查看系统时间,发现系统时间和硬件时间已经保持一致了。
[root@centOS6 ~]#clock -s [root@centOS6 ~]#date Sat Jan 12 14:01:47 CST 2019 [root@centOS6 ~]#clock Sat 12 Jan 2019 02:01:51 PM CST -1.187966 seconds
若是想要硬件时间同步系统时间,可使用clock -w实现,以下所示
[root@centOS6 ~]#clock -w
date命令主要用来显示或者修改系统日期时间,而一般只有超级用户可以修改时间,普通用户只可以查看系统时间,date的命令语法以下所示
date [选项] 显示时间的格式(以加号开头,后面接对应的时间格式)
date命令的选项及其说明以下所示
经常使用时间格式以下表格所示
格式 | 表示含义 |
---|---|
%Z | 显示时区 |
%Y | 显示完全年份 |
%m | 显示月份,表示格式从0~12 |
%d | 显示一个月的第几天 |
%H | 显示小时,表示范围00~23 |
%M | 显示分钟,表示格式从00~59 |
%S | 显示秒钟,显示格式为00~59 |
%A | 显示星期几,例如Sunday表示星期日 |
%F | 等同于%Y-%m-%d |
%T | 等同于%H:%M:%S |
%s | 计算自1970-01-01 00:00:00到当前时间的秒数 |
关于date命令的完整日期格式说明,可使用date --help查看对应的帮助文档获取,以下命令所示
[root@centOS6 ~]#date --help
在没有网络链接的工做环境中,学习查帮助是获取知识的最佳方式。
date经常使用案例1:显示当前日期,使用年-月-日表示,例如2019-01-15,以下命令输出显示
[root@centos7 ~]#date +%F 2019-01-15
date经常使用案案例2:显示当前日期时间,使用年月日 时分秒表示,例如2019-01-15 14:05:26
[root@centOS6 ~]#date +'%F %T' 2019-01-15 14:05:26
date经常使用案例3:计算自1970-01-01 00:00:00到当前时间的秒数
[root@centos7 ~]#date +%s 1547534021
date案例4:计算指定的秒数对应的日期时间
[root@centOS6 ~]#date -d @1547534021 Sat Jan 12 14:04:24 CST 2019
date经常使用案例5:显示昨天的时间日期
[root@centos7 ~]#date -d "-1 day" +"%F %T" 2019-01-14 14:41:13
date经常使用案例6:显示两天前是星期几
[root@centos7 ~]#date -d "-2 day" +%A Sunday
CentOS7.6系统中提供了timedatectl用来查看时区,以下命令输出结果所示
Local time显示当前的时间日期,Universal time显示的是格林威治时间,Time zone显示当前的时区是亚洲/上海。而UTC时间和本地时间相比恰好相差八个小时。
[root@centos7 ~]#timedatectl Local time: Sat 2019-01-12 14:20:23 CST Universal time: Sat 2019-01-12 06:20:23 UTC RTC time: Sat 2019-01-12 14:20:22 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: no NTP synchronized: no RTC in local TZ: no DST active: n/a
若是想要获取当前系统可用的时区,可使用timedatectl list-timezones命令列出
系统失去列表
[root@centos7 ~]#timedatectl list-timezones
若是想要修改系统的时区,可使用timedatectl set-timezone实现,以下命令所示,将当前的系统时区改成欧洲/柏林,而后使用timedatectl能够查看修改后的结果
[root@centos7 ~]#timedatectl set-timezone Europe/Berlin [root@centos7 ~]#timedatectl Local time: Sat 2019-01-12 07:32:03 CET Universal time: Sat 2019-01-12 06:32:03 UTC RTC time: Sat 2019-01-12 14:32:02 Time zone: Europe/Berlin (CET, +0100) NTP enabled: no NTP synchronized: no RTC in local TZ: no DST active: no Last DST change: DST ended at Sun 2018-10-28 02:59:59 CEST Sun 2018-10-28 02:00:00 CET Next DST change: DST begins (the clock jumps one hour forward) at Sun 2019-03-31 01:59:59 CET Sun 2019-03-31 03:00:00 CEST
时区修改完成之后,当再次使用date命令查看当前系统日期时,会发现系统日期也会随着改变。并且命令输出的结果显示柏林时间比北京时间晚七个小时
[root@centos7 ~]#date Sat Jan 12 07:34:54 CET 2019
由于本人目前所处的位置正是亚洲/上海,因此再次将系统的时区修改成亚洲/上海
[root@centos7 ~]#timedatectl set-timezone Asia/Shanghai [root@centos7 ~]#timedatectl Local time: Sat 2019-01-12 14:37:30 CST Universal time: Sat 2019-01-12 06:37:30 UTC RTC time: Sat 2019-01-12 14:37:29 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: no NTP synchronized: no RTC in local TZ: no DST active: n/a [root@centos7 ~]#
若是想要查看日历,可使用cal命令实现,该命令默认只显示当月的命令,以下输出结果显示
[guanglei@centOS6 network-scripts]$cal January 2019 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
若是想要显示一全年的日历,能够加上- y选项实现以下命令输出结果。
[guanglei@centOS6 network-scripts]$cal -y 2019 January February March Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 1 2 1 2 6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9 13 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16 20 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23 27 28 29 30 31 24 25 26 27 28 24 25 26 27 28 29 30 31 April May June Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 1 2 3 4 1 7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8 14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15 21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22 28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29 30 July August September Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7 7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14 14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21 21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28 28 29 30 31 25 26 27 28 29 30 31 29 30 October November December Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 1 2 1 2 3 4 5 6 7 6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14 13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21 20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28 27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
服务器通常都是要保证7*24
小时服务高可用,若是关机,会致使服务不可用,
一般只有在测试环境会使用关机来关闭系统,关机通常用于,迁移,停服,硬件升级。
若是想要关机,可使用halt或者poweroff命令来实现,以下命令是使用poweroff命令实现关机的输出效果,使用poweroff关机时它会发送一个关闭电源的信号。
[guanglei@centOS6 ~]$poweroff Broadcast message from guanglei@centOS6.ittimeline.net (/dev/pts/1) at 14:42 ... The system is going down for power off NOW!
VMware WorkStation中也能够查看到CentOS6.10是处于关机状态,以下图所示
当关机以后,SecureCRT须要从新链接CentOS6.10才能正常访问。
若是想要正常开启系统,须要点击开启虚拟机菜单。
而halt命令也能够实现关机,可是和poweroff执行的结果是不同的,halt只是关闭系统,而不会切断电源,能够从VMware WorkStation中看出
当尝试关闭虚拟机时,VMWare WorkStation会提示系统仍然处于开启状态
若是想要再次启动CentOS7.6,能够选择以下图所示的菜单
Linux下关于关机的操做还提供了一个showdown的命令,它提供了一些经常使用的选项,能够实现一些特定的功能,以下表格所示
选项名称 | 选项功能 |
---|---|
-r | 重启系统 |
-h | 关机 |
-c | 取消正在执行的shutdown指令 |
应用案例1:在指定的时间下关机,例如我想要在十分钟以后关机,可使用以下命令实现
[root@centOS6 ~]#shutdown -h +10
应用案例2:若是想要取消关机可使用Ctrl+c中断程序或者使用shutdown -c实现取消关机
[root@centOS6 ~]#shutdown -c
应用案例3:若是想要使用重启系统,可使用shutdown -r now 实现,以下命令执行结果所示
[root@centOS6 ~]#shutdown -r now Broadcast message from root@centOS6.ittimeline.net (/dev/pts/0) at 10:59 ... The system is going down for reboot NOW!
当咱们在使用Linux系统的过程当中,可能会遇到某些问题没法解决,这时候重启系统变成了一个解决办法,固然服务器系统不能随便重启,由于重启会致使服务器上的服务不可用,影响用户体验,因此重启最好在半夜或者访问用户量少的时候进行。
Linux系统的重启可使用reboot命令实现,以下所示
[root@centOS6 ~]#reboot Broadcast message from root@centOS6.ittimeline.net (/dev/pts/2) at 15:05 ... The system is going down for reboot NOW!
重启以后当前会话也会自动关闭,当重启完成之后,可使用SecureCRT提供的重连功能快速链接,而后进行后续操做
在工做或者学习的过程当中,可能会遇到一些本身没法解决的问题,而迫切须要寻求别别人的帮助,而有些问题没法用语言描述清楚,这时候就须要使用到桌面共享的功能了,经过远程链接,让大神看到你的屏幕来解决问题。
Windows下能够经过Teamviewer或者QQ能够实现远程桌面共享
Linux下经过screen命令来实现桌面共享,当在系统中执行screen命令时发现Shell告诉咱们该命令找不到,所以咱们须要安装screen。
[guanglei@centos7 ~]$screen bash: screen: command not found...
那么CentOS下如何安装软件呢?
首先咱们在VMware WorkStation中找到CentOS7.6的虚拟机设置,确保CD/DVD的设置项中配置了使用ISO镜像文件,以下图所示
而且光盘已是链接状态
而后在SecureCRT终端中使用df命令查看该ISO文件挂在的路径
[root@centos7 ~]#df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 52403200 3671724 48731476 8% / devtmpfs 3979308 0 3979308 0% /dev tmpfs 3995144 0 3995144 0% /dev/shm tmpfs 3995144 12888 3982256 1% /run tmpfs 3995144 0 3995144 0% /sys/fs/cgroup /dev/sda3 31441920 32992 31408928 1% /data /dev/sda1 1038336 178052 860284 18% /boot tmpfs 799032 20 799012 1% /run/user/0 /dev/sr0 10491772 10491772 0 100% /run/media/root/CentOS 7 x86_64 tmpfs 799032 0 799032 0% /run/user/1000
根据命令输出结果显示ISO镜像文件的挂载目录是/run/media/root/CentOS\ 7\ x86_64/,而后使用rpm -ivh命令即可安装screen
[root@centos7 ~]#rpm -ivh /run/media/root/CentOS\ 7\ x86_64/Packages/screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm warning: /run/media/root/CentOS 7 x86_64/Packages/screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:screen-4.1.0-0.25.20120314git3c29################################# [100%]
CentOS6.10和CentOS7.6同样,首先要保证虚拟机的设置中的CD/DVD的设置项中配置了使用ISO镜像文件,而且是已经链接的状态,而后使用以下命令即可安装。
[root@centOS6 ~]#rpm -ivh /media/CentOS_6.10_Final/Packages/screen-4.0.3-19.el6.x86_64.rpm warning: /media/CentOS_6.10_Final/Packages/screen-4.0.3-19.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:screen ########################################### [100%]
首先必须保持有同一用户(例如root)的两个SecureCRT客户端已经链接上了同一台CentOS,这里以CentOS6.10为例。
而后在左边(小白)的窗口中输入screen -S helpme回车后开启一个会话
[root@centOS6 ~]#screen -S helpme
而后再右边的窗口(大神)输入screen -x helpme加入一个会话,其中helpme是会话名称。
[root@centOS6 ~]#screen -x helpme
而后左右两边的操做就能够同步了,这时就实现了桌面共享,以下图所示
[root@centOS6 ~]#screen -r helpme
echo默认是显示字符串并完成换行,以前使用过echo查看环境变量,以下命令所示
[root@centos7 ~]#echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
也使用过echo查看命令提示符的格式
[root@centos7 ~]#echo $PS1 \[\e[1;36m\][\u@\h \W]\$\[\e[0m\]
而后可使用-e选项控制输出内容的格式,以下命令所示输出字符串并在换行的基础之上再换行一次
[root@centos7 ~]#echo -e "hello\n" hello
若是想要取消echo的默认换行,可使用-e选项,而后在输出的内容后面加\c,以下命令输出显示
[root@centos7 ~]#echo -e "hello\c" hello[root@centos7 ~]#
若是想要输出的内容实现tab的效果,可使用-e选项,而后在输出的内容中间加上\t,以下命令所示
[root@centos7 ~]#echo -e "hello\tworld" hello world
若是想要实现声音提示(前提是系统的声音已经打开),可使用-e选项后加上'\a'实现,以下命令所示
[root@centos7 ~]#echo -e "\a"
若是想要在输出的内容中插入\,须要使用\,以下命令所示
[root@centos7 ~]#echo -e 'hello\\world' hello\world
计算机中的数据(文本、图片,音频、视频)都是以二进制的格式存储数据的,那么如何来验证这一点呢?
首先使用touch命令建立一个文件hello,和Windows不一样的是Linux的文件不须要后缀名来判断格式。
[root@centos7 ~]#touch hello
而后使用echo 结合重定向将a字符输入到hello.txt中。
[root@centos7 ~]#echo "a" > hello
再使用cat命令查看hello的内容
[root@centos7 ~]#cat hello a
而后使用hexdump -C命令查看hello文件中的a存储对应的十六进制的值
[root@centos7 ~]#hexdump -C hello 00000000 61 0a |a.| 00000002
输出结果恰好是十六进制的61,换算成十进制就是97,字符和数字的对应关系由ASC||码规定。
而97转换为8进制为141,可使用echo -e输出8进制141对应的字符,命令以下所示
[root@centos7 ~]#echo -e '\0141' a
在使用echo命令输出文本内容是,能够借助``(反向单引号,数字1左边的那个键) 实现命令扩展:把一个命令的输出当成另一个命令参数,以下命令所示
[root@centos7 ~]#echo my host name is `hostname` my host name is centos7.ittimeline.net [root@centos7 ~]#echo my name is `whoami` my name is root
``的应用场景1:以下命令输出显示,使用当前日期建立日志文件
[root@centos7 ~]#touch `date +%F`.log [root@centos7 ~]#ll total 12 -rw-r--r--. 1 root root 0 Jan 13 04:08 2019-01-13.log
``的应用场景2:以下命令实现将ls命令对应的文件复制到/data目录下
[root@centos7 ~]#which --skip-alias ls #查看ls命令的路径 /usr/bin/ls [root@centos7 ~]#cp `which --skip-alis ls` /data [root@centos7 ~]#ls -la /data #查看复制的文件 total 116 drwxr-xr-x. 2 root root 16 Jan 13 04:14 . dr-xr-xr-x. 18 root root 236 Jan 10 10:08 .. -rwxr-xr-x. 1 root root 117680 Jan 13 04:14 ls
echo默认会将命令后面的内容以字符串("包含起来的内容")的形式输出,若是输出的内容中包含了变量(例如这里的$PATH),会顺便将变量的值输出,以下命令输出结果所示。
[root@centos7 ~]#echo env path is $PATH env path is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
即便输出的内容加上双引号(""),也不会影响输出的结果,以下命令输出结果所示。
[root@centos7 ~]#echo "env path is $PATH" env path is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
若是不想echo在执行时输出变量的值,可使用单引号(''),以下命令所示
[root@centos7 ~]#echo 'env path is $PATH' env path is $PATH
echo还能够结合{}实现打印重复字符串的简化形式,以下命令所示
[root@centos7 ~]#echo {1..10} #输出1-10 1 2 3 4 5 6 7 8 9 10 [root@centos7 ~]#echo {a..z} #输出a-z的26个小写字母 a b c d e f g h i j k l m n o p q r s t u v w x y z [root@centos7 ~]#echo {A..Z} #输出A-Z的26个大写字母 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [root@centos7 ~]#echo file{1..10}.log #输出10个文件名 file1.log file2.log file3.log file4.log file5.log file6.log file7.log file8.log file9.log file10.log
在平常学习和生产环境使用Linux的过程当中,可能须要使用到的命令以及相关的服务有几百个之多,咱们不可能记得住全部的命令以及选项的对应的功能,这时咱们就须要经过查看帮助来了解他们的使用,以下列表所示,列出了可能用到的查看帮助的方法,平时也不用刻意去记,使用熟练以后天然就记住了。
whatis命令是用来查看命令简要的功能说明,其应用场景就是首次使用一个陌生的命令时,可使用它来了解命令的功能,以下命令输入显示
[root@centOS6 ~]#whatis ls #查看ls命令的说明 ls (1) - list directory contents ls (1p) - list directory contents [root@centOS6 ~]#whatis rm rm (1p) - remove directory entries rm (1) - remove files or directories
须要注意的是whatis命令可能在刚刚装完系统以后不能当即使用,whatis是从数据库中获取命令的功能说明,咱们能够手动使用相关的命令来建立whatis的数据库,CentOS6.10可使用makewhatis命令建立,
[root@centOS6 ~]#makewhatis
而CentOS7.6可使用mandb命令建立。
[root@centos7 etc]#mandb
若是是想要查看内部命令,能够直接使用help command便可查看,以下命令输出所示。
[root@centOS6 ~]#help cd cd: cd [-L|-P] [dir] Change the shell working directory. Change the current directory to DIR. The default DIR is the value of the HOME shell variable. The variable CDPATH defines the search path for the directory containing DIR. Alternative directory names in CDPATH are separated by a colon (:). A null directory name is the same as the current directory. If DIR begins with a slash (/), then CDPATH is not used. If the directory is not found, and the shell option `cdable_vars' is set, the word is assumed to be a variable name. If that variable has a value, its value is used for DIR. Options: -L force symbolic links to be followed -P use the physical directory structure without following symbolic links The default is to follow symbolic links, as if `-L' were specified. Exit Status: Returns 0 if the directory is changed; non-zero otherwise.
外部命令可使用--help或者-h选项查看帮助,例如以前使用过的date --help就是典型的例子。
以下命令显示,使用date --help查看date命令的帮助信息
[root@centOS6 ~]#date --help
须要注意的是否是每一个外部命令都支持--help或者-h选项,以下命令输出显示date不支持-h选项
[root@centOS6 ~]#date -h date: invalid option -- 'h' Try `date --help' for more information.
在平常运维场景中,一般都是使用man命令(对应的是manual手册)查看外部命令的帮助手册,其使用格式为man 参数选项 命令/文件
在安装软件时,系统会将软件的帮助手册存放在/usr/share/man路径下,以下命令输出显示能够查看帮助手册列表
[root@centos7 man]#ls -al /usr/share/man total 616 drwxr-xr-x. 48 root root 4096 Jan 10 10:06 . drwxr-xr-x. 235 root root 8192 Jan 13 01:16 .. drwxr-xr-x. 3 root root 18 Jan 10 10:05 ca drwxr-xr-x. 7 root root 66 Jan 10 10:05 cs drwxr-xr-x. 5 root root 42 Jan 10 10:03 da drwxr-xr-x. 6 root root 54 Jan 10 10:03 de drwxr-xr-x. 7 root root 66 Jan 10 10:06 en drwxr-xr-x. 5 root root 42 Jan 10 10:05 es drwxr-xr-x. 6 root root 54 Jan 10 10:03 fr drwxr-xr-x. 5 root root 42 Jan 10 10:03 hu drwxr-xr-x. 5 root root 42 Jan 10 10:05 id drwxr-xr-x. 6 root root 54 Jan 10 10:03 it drwxr-xr-x. 5 root root 42 Jan 10 10:03 ja drwxr-xr-x. 3 root root 18 Jan 10 10:03 ko drwxr-xr-x. 2 root root 4096 Jan 10 10:06 man0p drwxr-xr-x. 2 root root 53248 Jan 13 01:16 man1 drwxr-xr-x. 2 root root 8192 Jan 10 10:06 man1p drwxr-xr-x. 2 root root 6 Apr 11 2018 man1x drwxr-xr-x. 2 root root 16384 Jan 10 10:06 man2 drwxr-xr-x. 2 root root 6 Apr 11 2018 man2x drwxr-xr-x. 2 root root 237568 Jan 10 10:06 man3 drwxr-xr-x. 2 root root 40960 Jan 10 10:06 man3p drwxr-xr-x. 2 root root 6 Apr 11 2018 man3x drwxr-xr-x. 2 root root 4096 Jan 10 10:06 man4 drwxr-xr-x. 2 root root 6 Apr 11 2018 man4x drwxr-xr-x. 2 root root 20480 Jan 10 10:06 man5 drwxr-xr-x. 2 root root 6 Apr 11 2018 man5x drwxr-xr-x. 2 root root 24 Jan 10 10:06 man6 drwxr-xr-x. 2 root root 6 Apr 11 2018 man6x drwxr-xr-x. 2 root root 8192 Jan 10 10:06 man7 drwxr-xr-x. 2 root root 6 Apr 11 2018 man7x drwxr-xr-x. 2 root root 40960 Jan 10 10:06 man8 drwxr-xr-x. 2 root root 6 Apr 11 2018 man8x drwxr-xr-x. 2 root root 6 Apr 11 2018 man9 drwxr-xr-x. 2 root root 6 Apr 11 2018 man9x drwxr-xr-x. 2 root root 6 Apr 11 2018 mann drwxr-xr-x. 5 root root 42 Jan 10 10:05 nl drwxr-xr-x. 17 root root 173 Jan 10 10:06 overrides drwxr-xr-x. 6 root root 54 Jan 10 10:05 pl drwxr-xr-x. 3 root root 18 Jan 10 10:05 pt drwxr-xr-x. 5 root root 42 Jan 10 10:03 pt_BR drwxr-xr-x. 6 root root 54 Jan 10 10:03 ru drwxr-xr-x. 3 root root 18 Jan 10 10:03 sk drwxr-xr-x. 6 root root 54 Jan 10 10:03 sv drwxr-xr-x. 5 root root 42 Jan 10 10:03 tr drwxr-xr-x. 3 root root 18 Jan 10 10:05 uk drwxr-xr-x. 6 root root 54 Jan 10 10:03 zh_CN drwxr-xr-x. 4 root root 30 Jan 10 10:03 zh_TW
这里可使用whereis命令查看命令对应的帮助文件的路径,以ls为例,以下命令输出显示,即ls命令的帮助文件对应的是/usr/share/man/man1/ls.1.gz,以.gz为后缀的一般是压缩文件,可是咱们在查看命令帮助时不须要去解压该文件
[root@centos7 man]#whereis ls ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
只须要使用man 1 ls便可,以下命令所示,其中1表示查看第一章节(即用户命令)
的帮助手册。
[root@centos7 man]#man 1 ls
几乎每一个命令都有man的"页面",以便使用man命令查看帮助手册,并且不一样的命令,函数的帮助手册是按照不一样的章节存放的,以下列表所示
章节名称 | 章节功能 |
---|---|
章节1 | 用户命令 |
章节2 | 系统调用 |
章节3 | C库调用 |
章节4 | 设备文件以及特殊文件 |
章节5 | 配置文件格式 |
章节6 | 游戏 |
章节7 | 杂项 |
章节8 | 管理类命令 |
章节9 | Linux内核API |
一般运维人员只须要关注章节1,章节4,章节5和章节8便可,而开发人员须要关注章节2,章节3和章节9。
在使用man命令查看帮助时,须要加上对应的章节,用于区分查看帮助的类型,由于同一个命令可能对应的既是用户命令,又是配置文件格式,例如passwd
咱们可使用whatis passwd命令查看对应的章节,以下命令输出显示
[root@centos7 man]#whatis passwd passwd (1) - update user's authentication tokens sslpasswd (1ssl) - compute password hashes passwd (5) - password file
passwd(1) 表示用户命令,用于更新用户的密码
passwd(5)表示配置文件格式,用于存储密码。
所以若是咱们若是要查看passwd命令的帮助,须要使用以下命令
[root@centos7 man]#man 1 passwd
咱们若是要查看passwd配配置文件帮助,须要使用以下命令
[root@centos7 man]#man 5 passwd
当咱们在使用man command查看对应命令的帮助时,帮助内容中的标题格式对应的含义以下表格所示
man帮助中的标题 | 功能说明 |
---|---|
NAME | 命令说明及介绍 |
SYNOPSIS | 命令的基本用法 []表示可选,<>表示必选内容,a |
DESCRIPTION | 命令使用详细描述,以及相关参数选项说明 |
OPTIONS | 命令相关参数选项说明(有的命令帮助没有此选项) |
EXAMPLES | 示例 |
FILES | 相关文件 |
AUTHOR | 做者 |
COPYRIGHT | 版本信息 |
REPORTING BUGS | bug信息 |
SEE ALSO | 和命令相关的说明 |
执行man command查看命令的帮助信息时,实际上就是至关于浏览一个文件,能够利用以下列表所示的快捷键查阅相关功能。
功能键 | 功能说明 |
---|---|
PgDn | 向下翻页(可使用空格代替) |
PgUp | 向上翻页 |
Home | 调到第一页 |
End | 调到最后一页 |
/keyword | 向下依次查找关键字 |
?keyword | 向上依次查找关键字 |
n/N | n: 向下查找下一个关键字 N:向上查找上一个关键字 |
q | 退出man帮助 |
若是想要了解更多man命令使用的信息,可使用man man来查看,以下命令所示
[root@centos7 man]#man man
使用man查看bash帮助
[root@centos7 man]#man bash
在使用bash shell访问linux时,它提供了一些快捷键,用于实现特定的功能,在工做和学习的过程当中可使用这些快捷键提升效率,以下列表所示展现了最经常使用的快捷键。
快捷键 | 功能 |
---|---|
Ctrl+l | 清屏 |
Ctrl+o | 执行当前命令,而且从新显示当前命令 |
Ctrl+s | 阻止屏幕输出,锁定 |
Ctrl+q | 解除屏幕锁定 |
Ctrl+c | 终止命令,强行退出 |
Ctrl+z | 挂起命令 |
Ctrl+a | 光标移到命令行首 |
Ctrl+e | 光标移动到命令行尾 |
Ctrl+u | 从光标处删除至命令行首 |
Ctrl+k | 从光标删除至命令行尾 |
Alt+r | 删除当前整行 |
1.使用ctrl+l清除屏幕,以下图所示
2.使用ctrl+o执行当前命令而且显示当前命令,效果以下命令输出所示
[root@centos7 man]#hostname centos7.ittimeline.net [root@centos7 man]#hostname
3.使用ctrl+s阻止屏幕输出,保持锁定
当屏幕锁定以后,再次输入其余内容没有显示
5.使用Alt+r删除整行内容时须要在SecureCRT中设置以下快捷键