Linux基础之linux终端和shell命令(针对韩立刚老师的linux教学视频编写的笔记)...

一、终端
1、物理终端
#[root@centos6 ~]# tty
/dev/tty1
切换终端Ctrl+Alt+fn(n=1-6)
2、模拟终端

[root@centos6 ~]# tty

  /dev/pts/0

由mingetty程序产生
二、shell
1、shell的种类
GUI图形shell,包括:Gnome(C语言开发的)、KDE(C++开发的)、Xface(简单的轻量级图形界面)
CLI类型shell,包括:bsh、sh、csh、tcsh、ksh、bash、zsh。
如何查看系统里当前使用的shell

[root@centos6 ~]# echo $SHELL

/bin/bash

如何查看系统里支持哪些shell
#[root@centos6 ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
bash的功能
命令行编辑

光标快速移动快捷键

Ctar+a  快速跳转到行首
Ctar+e  快速跳转到行尾
    # 删除命令行中内容快捷键               
 Ctrl+w  删除光标前一个单词
 Ctrl+u  删除光标到行首的字符
     Ctrl+k  删除光标到行尾的字符
#清屏幕快捷键
    Ctrl+l    清空屏幕

bash的内部命令和外部命令
内部命令:系统自带命令
外部命令:在系统的某个路径下的可执行程序
外部命令查找依赖于path变量
如何查看系统默认path变量

[root@centos6 ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

如何知道使用的命令是内部命令还是外部命令

[root@centos6 ~]# type pwd

   pwd is a shell builtin

       #  [root@centos6 ~]# type ls
    ls is aliased to `ls --color=auto'
  #[root@centos6 ~]# type ping
 ping is /bin/ping

首次执行命令tab补全是从path路径中搜索,但如果每次都从path路径中去搜索会很慢,系统会自动把使用过的命令放入hash表中,之后再使用这个命令会直接从hash表中查找

[root@centos6 ~]# hash

    hits    command
     1    /usr/bin/tty
     1    /bin/cat
#[root@centos6 ~]# tty
       /dev/pts/0
#[root@centos6 ~]# hash
hits    command
2    /usr/bin/tty
1    /bin/cat

前面的hits下的数值代表命令使用过的次数
如果使用过的命令更换了path路径,这个命令将会无法使用,需要先清除hash表中这个的命令的记录后,才可再次使用。

[root@centos6 ~]# hash

   hits    command
   2    /usr/bin/tty
   1    /bin/cat
#[root@centos6 ~]# cat   /etc/shells
   /bin/sh
  /bin/bash
 /sbin/nologin
/bin/tcsh
/bin/csh
#[root@centos6 ~]# mv /bin/cat  /usr/bin/cat
     # [root@centos6 ~]# cat /etc/shells
-bash: /bin/cat: 没有那个文件或目录
     #[root@centos6 ~]# hash -d cat
     #[root@centos6 ~]# hash
     hits    command
     2    /usr/bin/tty
     1    /bin/mv
     #[root@centos6 ~]# cat /etc/shells
     /bin/sh
     /bin/bash
     /sbin/nologin
     /bin/tcsh
     /bin/csh

hash -d cat 删除hash表中cat命令
hash -r 清空hash表
Linux命令历史
#[root@centos6 ~]# history -c
#[root@centos6 ~]# history
1 history
#[root@centos6 ~]# tty
/dev/pts/0
#[root@centos6 ~]# history
1 history
2 tty
3 history
命令缓存默认可以保存1000条命令
#[root@centos6 ~]# echo $HISTSIZE
1000
命令历史文件默认可以保存1000条命令

[root@centos6 ~]# echo $HISTFILESIZE

          1000

如果查看命令历史文件

[root@centos6 ~]# echo $HISTFILE

     /root/.bash_history

命令历史文件个数要大于或等于命令缓存文件
history -w 覆盖历史命令
history -a 追加历史命令
history -c 清空历史命令
history -d 4 删除第4条历史命令(4也可以改成命令的名字)
多个终端同时使用同一个用户登录,先退出的终端缓存命令先写入命令缓存文件中。

[root@centos6 ~]# tail /root/.bash_history

 history
 tty
 history 
 echo $HISTSIZE
 echo $HISTFILESIZE
 echo $HISTFILE
 cat /root/.bash_history 
 history -w
 #[root@centos6 ~]# history -w
 #[root@centos6 ~]# tail /root/.bash_history 
       echo $HISTFILE
       cat /root/.bash_history 
       history -w
       cat /root/.bash_history 
       ls
      date
      history 
      vi /root/.bash_history 
      tail /root/.bash_history 
      history -w

历史命令可以设置三个变量
默认变量是ignoredups,表示不记录后面连续重复的命令
#[root@centos6 ~]# echo $HISTCONTROL
ignoredups
修改成ignorespace变量后,表示不记录以空格开始的命令
#[root@centos6 ~]# export HISTCONTROL=ignorespace
#[root@centos6 ~]# echo $HISTCONTROL
ignorespace
修改成ignoreboth变量后,表示即不记录以空格开始的命令,也不记录后面连续重复的命令
#[root@centos6 ~]# export HISTCONTROL=ignoreboth
#[root@centos6 ~]# echo $HISTCONTROL
ignoreboth
!!表示执行上一个历史命令
!3表示执行第三个命令
!-3表示执行倒数第三个命令
Ctrl+p向上翻
Ctrl+N向下翻
输入命令空格再按esc.会自动补全上一条命令最后一个参数
也可以输入!$调用上一条命令的最后一个参数

转载于:https://blog.51cto.com/bdfxiaoguai/2056202

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值