RH124 第一章 Linux命令行使用技巧

RH124 第一章 Linux命令行使用技巧

1. 什么是Linux

  • Linux操作系统:
    • GNU / Linux
    • GUN是开源组织(开源:提供开发时的源代码,可被更改)
    • Linux是指Linux内核
    • 补充:软件以浏览器形式存储
    • 补充:V内存>V硬盘(机械>固态)
    • 补充:把硬盘内容存储到内存中,cache,缓存
    • 补充:网络优先级高,通过内核来控制
    • 补充:操作系统=内核+软件
  • 内核
    • 系统核心程序
    • 相当于人的人脑
    • 负责系统程序和硬件分配及调度

2.什么是shell

  • 对外提供操作和系统沟通接口
  • 对内实现对内核进行保护
  • RHEL8中默认使用的shell是bash

3. shell行提示符的含义

  • shell类型;rhel8中默认使用的shell为bash;bash=GNU Bourne-Again SHell
  • shell打开方式
    1.右键打开
    2.Application---->favorites---->terminal
    3.gnome-terminal
    4.当shell已经开启时需要开启一个新的shell,在shell中可以用ctrl+shift+N打开
    5.可以在设置中设定任意快捷键执行 gnome-terminal
  • shell命令行提示符
    [root@localhost Desktop]#
    [1] [2] [3] [4] [5]
    [1]:运行shell的用户
    [2]:分割符
    [3]:系统主机短名称当前主机去掉域名部分的短名称——现在在哪台主机上:名
    (IP地址和IP协议知识补充)
    [4]:当前目录名称
    [5]:身份提示符 #表示当前用户为超级用户(#super user,root密码是在系统安装时设定),$当前用户为普通用户(#common user)

4. shell中的快捷键

  • shell中的快捷键使用
    ctrl+shift+T ##在一个terminal中开启多个窗口
    ctrl+shift+N ##重新打开一个terminal
    ctrl+c ##取消命令执行
    ctrl+d ##关闭shell
    ctrl+shift+鼠标选中+c ##复制选中字符
    ctrl+shift+v ##粘贴
    ##鼠标选中为复制
    ##鼠标滚轮下按为粘贴
  • shell中如何执行命令
    1)命令执行格式:命令 参数 对象
    ·命令就是程序
    ·参数表示命令的特殊功能
    ·对象就是操作目标
    2)命令执行的方法
    有些命令可以单独执行
    参数可以加多个
    -a -b -c = -abc = -cba = -acb
    参数-s 表示单词缩写
    参数–size 表示单词全拼
    命令必须在行提示符之后输入否则命令无法执行
    当命令行被占用通常使用+结束占用命令行的程序来释放命令行

5.命令行获得帮助

  • whatis rm ##查看命令的基本用途
    ##查看过程中出现
    #rm: nothing appropriate.
    #1.表示要查看内容没有帮助
    #2.系统帮助数据未更新用mandb命令更新
    “注意:当执行whatis命令出现 nothing appropriate 时大多数情况是因为” “系统的帮助数据库未更新,如何解决此问题,需要在root用户下执行mandb”
    当你使用的用户为普通用户时请执行以下操作:
    su - root
    mandb
    [westos@localhost Desktop]$ whatis date
    date: nothing appropriate.
    [westos@localhost Desktop]$ su -
    Password: 
    [root@localhost ~]# mandb
    
    [root@localhost ~]# whatis date
    date (1)             - print or set the system date and time
    date (1p)            - write the date and time
    
  • rm --help ##查看命令的基本用法
    [] ##内容可加可不加
    … ##内容个数任意
    <> ##必须在命令执行时加入的元素
    [westos@localhost Desktop]$ rm date --help
    Usage: rm [OPTION]... [FILE]...
    Remove (unlink) the FILE(s).
    
      -f, --force           ignore nonexistent files and arguments, never prompt
      -i                    prompt before every removal
      -I                    prompt once before removing more than three files, or
                              when removing recursively; less intrusive than -i,
                              while still giving protection against most mistakes
          --interactive[=WHEN]  prompt according to WHEN: never, once (-I), or
                              always (-i); without WHEN, prompt always
          --one-file-system  when removing a hierarchy recursively, skip any
                              directory that is on a file system different from
                              that of the corresponding command line argument
          --no-preserve-root  do not treat '/' specially
          --preserve-root[=all]  do not remove '/' (default);
                                  with 'all', reject any command line argument
                                  on a separate device from its parent
      -r, -R, --recursive   remove directories and their contents recursively
      -d, --dir             remove empty directories
      -v, --verbose         explain what is being done
          --help     display this help and exit
          --version  output version information and exit
    
  • man rm ##命令用法详解 man是manual的缩写
  • man -k passwd ##passwd关键字有多少级别的man
    ##man的级别
    #1 命令
    #2 系统调用
    #3 函数库调用
    #4 特殊文件(设备文件等)
    #5 文件
    #6 游戏
    #7 特殊的包
    #8 系统管理命令
    #9 内核信息规则
[westos@localhost Desktop]$ man -k passwd
[westos@localhost Desktop]$ man 1 date

练习题——显示80天后的日期

[westos@localhost ~]$ date 
Thu Oct 15 01:46:19 EDT 2020
[westos@localhost ~]$ whatis date
date (1)             - print or set the system date and time
date (1p)            - write the date and time
[westos@localhost ~]$ date +%Y
2020
[westos@localhost ~]$ date +%M
46
[westos@localhost ~]$ date +%m
10
[westos@localhost ~]$ date +%d
15
[westos@localhost ~]$ date +%Y/%M/%d
2020/50/15
[westos@localhost ~]$ date +%Y/%m/%d
2020/10/15
[westos@localhost ~]$ date +%Y/%m/%e
2020/10/15
[westos@localhost ~]$ date +%Y/%M/%d
2020/48/15
[westos@localhost ~]$ date -d 80day +%Y/%m/%d
2021/01/03

练习题——显示1984年11月3日是当年的第几天

在这里插入图片描述

  • man rm ##进入到rm命令的帮助
  • q ##退出
  • /关键字 ##搜索关键字,n 向下匹配, N 向上匹配
  • G ##快速移动到man的最后
  • g ##表示快速移动到man的最前

6.Linux命令行历史调用

  • 我们当前使用的shell可以记录系统中执行过的历史命令

    • history ##查看历史命令
    [westos@localhost Desktop]$ history
    1  touch westos
    2  wsd 
    3  touch ../westos
    4  exit
    5  whatis date
    6  su -
    7  rm date --help
    8  man date
    9  man rm date
    10  history
    
    • history -c ##清空当前历史命令
      ##永久清空历史需要清空文件.bash_history(在隐藏文件里)
    [westos@localhost Desktop]$ history -c
    [westos@localhost Desktop]$ history
    1  history
    
  • 历史命令的调用

    • 上键|下键 ##逐行调用
    • !数字 ##调用指定行历史
    • !字符 ##调用以此字符开头的最近历史
    • ctrl+R ##开启历史搜索模式,命令行显示会变为:
      ##(reverse-i-search)`’:输入关键字
      ##会显示含有此关键字的最近一条历史

7.TAB

  • 作用:补齐系统中存在的命令,文件,和某些命令的参数
  • 用法:
    • 当按一次tab没有效果,表示以此字符开头的信息不唯一可连续按2次,那么会把以此字符开头的所有内容显示
    • 如果2此仍然不显示表示没有以此字符开头的指令
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值