个人计划

linux入门基础

1. linux登录和远程连接

1.1用户类型

  • root 用户

    1
    2
    3
    4
    特殊的管理账号
    超级用户
    root能够完整的系统控制
    非必要,不要登录root
  • 普通用户

    1
    2
    权限有限
    造成损害的能力较小

1.2终端类型

1
2
3
4
5
6
7
8
控制台终端:/dev/console
串行终端:/dev/ssyS#
虚拟终端:tty:teletypewriters, /dev/tty#,tty可有n个,Ctrl+Alt+F
伪终端:pty:pseudo-tty,/dev/pts/#
图形终端:startx,xwindows
--------------------------------------------------
Centos6:ctrl+Alt+F7
Centos7:在哪个终端启用,即位于哪个虚拟终端
1
2
[root@localhost ~]# tty
/dev/pts/2

2. 命令行扩展

  • 比较“” ,’’,``三者区别

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    [root@localhost ~]# echo "echo $HOSTNAME"
    echo localhost.localdomain
    [root@localhost ~]# echo 'echo $HOSTNAME'
    echo $HOSTNAME
    [root@localhost ~]# echo `echo $HOSTNAME`
    localhost.localdomain

    #结论
    双引号:若引号,不能识别命令,但可以识别变量
    单引号:强引号,不能识别命令和变量
    反向单引号:里面的内容必须是可执行的命令,并且有输出信息

    [root@localhost ~]# echo ` echo $PATH`.log
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin.log
    [root@localhost ~]# echo `$PATH`.log
    -bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin: 没有那个文件或目录
    .log
    [root@localhost ~]# `echo $PATH`.log
    -bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin.log: 没有那个文件或目录
    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
    [root@localhost ~]# echo {1..10}
    1 2 3 4 5 6 7 8 9 10
    [root@localhost ~]# echo {1..10..2}
    1 3 5 7 9
    [root@localhost ~]# echo {2..10..2}
    2 4 6 8 10
    [root@localhost ~]# echo {20..10..2}
    20 18 16 14 12 10
    [root@localhost ~]# echo {a..z..2}
    a c e g i k m o q s u w y
    [root@localhost ~]# echo {a b c}
    {a b c}
    [root@localhost ~]# echo {a, b, c}
    {a, b, c}
    [root@localhost ~]# echo {a,b,c}
    a b c
    [root@localhost ~]# echo {abc}
    {abc}
    [root@localhost ~]# echo {a,b,c}.{txt,log}
    a.txt a.log b.txt b.log c.txt c.log
    [root@localhost ~]# echo {1..5}.{txt,log}
    1.txt 1.log 2.txt 2.log 3.txt 3.log 4.txt 4.log 5.txt 5.log
    [root@localhost ~]# echo ./test/{data,log,pid}
    ./test/data ./test/log ./test/pid
    [root@localhost ~]# echo file{,.bak}
    file file.bak

2. linux的终端基本操作

  • 查看CUP配置

    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
    1、lscpu
    [23:07:39 root@localhost ~]#lscpu
    架构: x86_64
    CPU 运行模式: 32-bit, 64-bit
    字节序: Little Endian
    CPU: 4
    在线 CPU 列表: 0-3
    每个核的线程数: 1
    每个座的核数: 4
    座: 1
    NUMA 节点: 1
    厂商 ID: GenuineIntel
    BIOS Vendor ID: GenuineIntel
    CPU 系列: 6
    型号: 140
    型号名称: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    BIOS Model name: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    步进: 1
    CPU MHz: 2419.202
    BogoMIPS: 4838.40
    超管理器厂商: VMware
    虚拟化类型: 完全
    L1d 缓存: 48K
    L1i 缓存: 32K
    L2 缓存: 1280K
    L3 缓存: 8192K
    NUMA 节点0 CPU: 0-3
    标记: 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 cpuid 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 cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xsaves arat pku ospke md_clear flush_l1d arch_capabilities

    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    2、/proc/cpuinfo
    [23:07:43 root@localhost ~]#cat /proc/cpuinfo
    processor : 0
    vendor_id : GenuineIntel
    cpu family : 6
    model : 140
    model name : 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    stepping : 1
    microcode : 0x66
    cpu MHz : 2419.202
    cache size : 8192 KB
    physical id : 0
    siblings : 4
    core id : 0
    cpu cores : 4
    apicid : 0
    initial apicid : 0
    fpu : yes
    fpu_exception : yes
    cpuid level : 27
    wp : yes
    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 cpuid 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 cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xsaves arat pku ospke md_clear flush_l1d arch_capabilities
    bugs : spectre_v1 spectre_v2 spec_store_bypass swapgs itlb_multihit
    bogomips : 4838.40
    clflush size : 64
    cache_alignment : 64
    address sizes : 43 bits physical, 48 bits virtual
    power management:

    processor : 1
    vendor_id : GenuineIntel
    cpu family : 6
    model : 140
    model name : 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    stepping : 1
    microcode : 0x66
    cpu MHz : 2419.202
    cache size : 8192 KB
    physical id : 0
    siblings : 4
    core id : 1
    cpu cores : 4
    apicid : 1
    initial apicid : 1
    fpu : yes
    fpu_exception : yes
    cpuid level : 27
    wp : yes
    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 cpuid 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 cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xsaves arat pku ospke md_clear flush_l1d arch_capabilities
    bugs : spectre_v1 spectre_v2 spec_store_bypass swapgs itlb_multihit
    bogomips : 4838.40
    clflush size : 64
    cache_alignment : 64
    address sizes : 43 bits physical, 48 bits virtual
    power management:

    processor : 2
    vendor_id : GenuineIntel
    cpu family : 6
    model : 140
    model name : 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    stepping : 1
    microcode : 0x66
    cpu MHz : 2419.202
    cache size : 8192 KB
    physical id : 0
    siblings : 4
    core id : 2
    cpu cores : 4
    apicid : 2
    initial apicid : 2
    fpu : yes
    fpu_exception : yes
    cpuid level : 27
    wp : yes
    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 cpuid 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 cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xsaves arat pku ospke md_clear flush_l1d arch_capabilities
    bugs : spectre_v1 spectre_v2 spec_store_bypass swapgs itlb_multihit
    bogomips : 4838.40
    clflush size : 64
    cache_alignment : 64
    address sizes : 43 bits physical, 48 bits virtual
    power management:

    processor : 3
    vendor_id : GenuineIntel
    cpu family : 6
    model : 140
    model name : 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    stepping : 1
    microcode : 0x66
    cpu MHz : 2419.202
    cache size : 8192 KB
    physical id : 0
    siblings : 4
    core id : 3
    cpu cores : 4
    apicid : 3
    initial apicid : 3
    fpu : yes
    fpu_exception : yes
    cpuid level : 27
    wp : yes
    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 cpuid 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 cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xsaves arat pku ospke md_clear flush_l1d arch_capabilities
    bugs : spectre_v1 spectre_v2 spec_store_bypass swapgs itlb_multihit
    bogomips : 4838.40
    clflush size : 64
    cache_alignment : 64
    address sizes : 43 bits physical, 48 bits virtual
    power management:

  • 查看内存

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    1、free
    [23:57:59 root@localhost ~]#free
    total used free shared buff/cache available
    Mem: 3798596 663792 2516444 10892 618360 2886888
    Swap: 4194300 0 4194300

    1.1、free -h 转换内存单位格式
    [00:05:39 root@localhost ~]#free -h
    total used free shared buff/cache available
    Mem: 3.6Gi 647Mi 2.4Gi 10Mi 604Mi 2.8Gi
    Swap: 4.0Gi 0B 4.0Gi

    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    2、cat /proc/meminfo
    [00:01:38 root@localhost ~]#cat /proc/meminfo
    MemTotal: 3798596 kB
    MemFree: 2516672 kB
    MemAvailable: 2887200 kB
    Buffers: 3276 kB
    Cached: 549296 kB
    SwapCached: 0 kB
    Active: 151912 kB
    Inactive: 780616 kB
    Active(anon): 2356 kB
    Inactive(anon): 388492 kB
    Active(file): 149556 kB
    Inactive(file): 392124 kB
    Unevictable: 0 kB
    Mlocked: 0 kB
    SwapTotal: 4194300 kB
    SwapFree: 4194300 kB
    Dirty: 0 kB
    Writeback: 0 kB
    AnonPages: 380008 kB
    Mapped: 220528 kB
    Shmem: 10892 kB
    KReclaimable: 65932 kB
    Slab: 138624 kB
    SReclaimable: 65932 kB
    SUnreclaim: 72692 kB
    KernelStack: 8400 kB
    PageTables: 23256 kB
    NFS_Unstable: 0 kB
    Bounce: 0 kB
    WritebackTmp: 0 kB
    CommitLimit: 6093596 kB
    Committed_AS: 2062856 kB
    VmallocTotal: 34359738367 kB
    VmallocUsed: 0 kB
    VmallocChunk: 0 kB
    Percpu: 96768 kB
    HardwareCorrupted: 0 kB
    AnonHugePages: 182272 kB
    ShmemHugePages: 0 kB
    ShmemPmdMapped: 0 kB
    FileHugePages: 0 kB
    FilePmdMapped: 0 kB
    HugePages_Total: 0
    HugePages_Free: 0
    HugePages_Rsvd: 0
    HugePages_Surp: 0
    Hugepagesize: 2048 kB
    Hugetlb: 0 kB
    DirectMap4k: 186176 kB
    DirectMap2M: 4007936 kB
    DirectMap1G: 2097152 kB

  • 查看硬盘

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    1、lsblk
    [00:03:30 root@localhost ~]#lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 0 200G 0 disk
    ├─sda1 8:1 0 1G 0 part /boot
    ├─sda2 8:2 0 100G 0 part /
    ├─sda3 8:3 0 4G 0 part [SWAP]
    ├─sda4 8:4 0 1K 0 part
    └─sda5 8:5 0 95G 0 part /data
    sr0 11:0 1 10.1G 0 rom
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    2、/proc/partitions 
    [00:10:37 root@localhost ~]#cat /proc/partitions
    major minor #blocks name

    8 0 209715200 sda
    8 1 1048576 sda1
    8 2 104857600 sda2
    8 3 4194304 sda3
    8 4 1 sda4
    8 5 99612672 sda5
    11 0 10541056 sr0

  • 查看系统架构(64位还是32位)

    1
    2
    3
    4
    arch
    [00:12:16 root@localhost ~]#arch
    x86_64

  • 查看系统内核版本

    1
    2
    3
    4
    1、uname -r
    [00:13:12 root@localhost ~]#uname -r
    4.18.0-348.el8.x86_64

  • 查看Linux系统发行版本

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    1、cat /etc/os-release
    [00:16:59 root@localhost ~]#cat /etc/os-release
    NAME="CentOS Linux"
    VERSION="8"
    ID="centos"
    ID_LIKE="rhel fedora"
    VERSION_ID="8"
    PLATFORM_ID="platform:el8"
    PRETTY_NAME="CentOS Linux 8"
    ANSI_COLOR="0;31"
    CPE_NAME="cpe:/o:centos:centos:8"
    HOME_URL="https://centos.org/"
    BUG_REPORT_URL="https://bugs.centos.org/"
    CENTOS_MANTISBT_PROJECT="CentOS-8"
    CENTOS_MANTISBT_PROJECT_VERSION="8"

  • 系统登陆提示

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    1、/etc/motd  登录后提示   
    vim /etc/motd
    ni hao ya zhang xue long

    [C:\~]$

    Connecting to 192.168.100.30:22...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.

    ni hao ya zhang xue long
    Activate the web console with: systemctl enable --now cockpit.socket

    Last login: Thu Jul 14 00:29:21 2022
    Session lifetime based on X11 requested, but X11 initialization failed.

    1
    2/etc/issue.net 登录前提示
  • 时间命令

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    1date 软件时钟
    1.1、查看数据
    [root@localhost ~]# date
    20220714日 星期四 00:50:48 CST
    [root@localhost ~]# date +"%F %T"
    2022-07-14 00:52:22
    [root@localhost ~]# date +"%Y-%m-%d %H:%M:%S"
    2022-07-14 00:53:20
    [root@localhost ~]# date -d -2day
    20220712日 星期二 00:55:22 CST
    [root@localhost ~]# date -d "-1year -3day"
    20210711日 星期日 00:56:09 CST

    1.2、设置时间
    [root@localhost ~]# date -s "2021-07-01"
    20210701日 星期四 00:00:00 CST
    [root@localhost ~]# date 071401022022.50
    20220714日 星期四 01:02:50 CST

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    2、clock 硬件时钟
    2.1、查看时钟
    [root@localhost ~]# clock
    2022-07-14 01:04:24.517933+08:00
    2.2、硬件时钟修正软件时钟
    [root@localhost ~]# date -s "2022-07-08"
    20220708日 星期五 00:00:00 CST
    [root@localhost ~]# clock -s
    [root@localhost ~]# date
    20220714日 星期四 01:06:55 CST
    2.3、软件时钟修正硬件时钟
    [root@localhost ~]# clock -w

  • 日历

    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    1、查看日历
    [root@localhost ~]# cal
    七月 2022
    日 一 二 三 四 五 六
    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
    [root@localhost ~]# cal 2022
    2022

    一月 二月 三月
    日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
    1 1 2 3 4 5 1 2 3 4 5
    2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12
    9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19
    16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26
    23 24 25 26 27 28 29 27 28 27 28 29 30 31
    30 31
    四月 五月 六月
    日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
    1 2 1 2 3 4 5 6 7 1 2 3 4
    3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
    10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
    17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
    24 25 26 27 28 29 30 29 30 31 26 27 28 29 30

    七月 八月 九月
    日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
    1 2 1 2 3 4 5 6 1 2 3
    3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
    10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
    17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
    24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
    31
    十月 十一月 十二月
    日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
    1 1 2 3 4 5 1 2 3
    2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
    9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
    16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
    23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
    30 31
    [root@localhost ~]#

  • 开关机命令

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    1、关机
    halt
    poweroff
    2、重启
    reboot
    reboot -f 强制重启
    reboot -p 切断电源
    ctrl+alt+delet
    2、关机或重启:shutdown [option]...[time][message]
    shutdown -h 等于 halt
    shutdown -r 等于 reboot
    shutdown -c 取消关机或重启命令
    [time]:无指定时间,默认相当于+1
    now:现在
    +#:相对于时间表示法,几分钟(+3)
    hh:mm :绝对时间表示,指定具体时间




  • 查看开关机时间多久

    1
    2
    3
    4
    uptime
    [root@rocky8 ~]# uptime
    01:31:26 up 50 min, 2 users, load average: 0.01, 0.11, 0.11

  • 查看命令是否在运行

    1
    2
    3
    4
    5
    6
    7
    ps -aux|grep sleep
    [root@localhost ~]# sleep 1000
    [root@rocky8 ~]# ps -aux|grep sleep
    root 3392 0.0 0.1 7316 888 ? S 01:42 0:00 sleep 60
    root 3394 0.0 0.1 12136 984 pts/0 S+ 01:43 0:00 grep --color=auto sleep
    [root@rocky8 ~]#

  • 后台运行命令

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    screen  需另外安装yum instal screen  -y
    [root@localhost ~]# screen
    [root@localhost ~]# sleep 999
    关闭当前命令窗口,打开新命令窗口
    [root@localhost ~]# ps -aux|grep sleep
    root 12883 0.0 0.0 7528 900 pts/2 S+ 01:46 0:00 sleep 1000
    root 13002 0.0 0.0 7528 892 pts/1 S+ 01:50 0:00 sleep 999
    root 13011 0.0 0.0 7528 896 ? S 01:51 0:00 sleep 60
    root 13051 0.0 0.0 12348 1100 pts/0 S+ 01:52 0:00 grep --color=auto sleep


  • tmux增加版:screen

    1
      

3. linux的命令执行过程和命令格式

  • 修改提示符格式
1
2
3
4
临时修改:
PS1="\[\e[1;5;41;33m\][\u@\h \W]\\$\[\e[0m\]"
PS1="\[\e[1;32m\][\t \[\e[1;33m\]\u\[\e[35m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$"

4.获取帮助命令

  • whatis

    1
    2
    3
    4
    5
    该命令刚安装系统后不能立即使用,需制作数据库后才可使用
    #Centos7之后
    mandb生成
    #Centos6版本之前
    makewhatis
  • man

    1
    外部命令使用指南
  • whereis

  • /usr/share/doc

    1
    命令自身提供的官方使用指南
    • yum源替换成阿里epel源

      1
      2
      3
      4
      rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo
      curl https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -o /etc/yum.repos.d/Centos-8.repo
      curl https://mirrors.aliyun.com/repo/epel-archive-8.repo -o /etc/yum.repos.d/epel-archive-8.repo
      yum clean all && yum makecache
    • 设置中文字符集

      1
      2
      3
      4
      5
      6
      7
      查看是否存在中文字符集:localectl list-locales

      安装中文字符集:yum -y install langpacks-zh_CN.noarch

      再查看字符集:localectl list-locales

      设置中文字符集:localectl set-locale LANG=zh_CN.utf8

    • 文件传输命令工具

      1
      2
      3
      yum install lrzsz
      下载:rz
      上传:sz 文件名

6.Linux的各种符号用法

  • hexdump

    • 简要描述

      1
      磁盘文件是以二进制形式保存字符,而展示给用户时是通过软件打开文件时软件通过编码转换为用户可识别字符
    1
    2
    3
    4
    5
    6
    7
    以16进制查看文档
    [root@localhost ~]# cat zhangsan_2022-07-14_01\:58\:49.log
    dsasda
    [root@localhost ~]# hexdump -C zhangsan_2022-07-14_01\:58\:49.log
    00000000 64 73 61 73 64 61 0a |dsasda.|
    00000007

  • 编码

    • GB2312:中国编码

    • ASCII:美国编码

    • UNICODE:国际编码

    • UTF-8:增强的国际编码(万国码)

    • 各系统默认编码

      1
      win7及以下系统默认

7、Linux的各种快捷键

  • tab键补全

    • 2tab键可以补全子命令或文件补全
    • string+2tab 以string开头命令补全
    • /+2tab 可以列出/目录下所有文件和目录
    1
    2
    3
    4
    5
    6
    7
    8
    默认centos/rocky系统最小化安装未安装补全命令,图形界面系统安装已含有该命令
    root@localhost ~]# yum -y install bash-completion
    上次元数据过期检查:1:28:58 前,执行于 2022年07月14日 星期四 09时55分55秒。
    软件包 bash-completion-1:2.7-5.el8.noarch 已安装。
    依赖关系解决。
    无需任何处理。
    完毕!

  • !+history命令数字

    1
    2
    3
    4
    5
    6
    7
    8
    [root@localhost ~]# cat zhangsan_2022-07-14_01\:58\:49.log 
    dsasda
    [root@localhost ~]# history
    1 cat zhangsan_2022-07-14_01\:58\:49.log
    2 history
    [root@localhost ~]# !1
    cat zhangsan_2022-07-14_01\:58\:49.log
    dsasda
  • !+?+string

    1
    2
    3
    4
    5
    6
    [root@localhost ~]# date +"%F_%T"
    2022-07-14_11:50:37
    [root@localhost ~]# !?date
    date +"%F_%T"
    2022-07-14_11:50:45
    [root@localhost ~]#
  • 快捷键

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    1、alt+. 返回上一条命令参数
    [root@localhost ~]# echo "aaaa"
    aaaa
    [root@localhost ~]# "aaaa"
    2、Ctrl+l 清屏
    3、ctrl+S 命令窗口屏蔽显示命令
    4、ctrl+q 清除命令窗口屏蔽显示命令
    5、ctrl+c 终止命令执行
    6、ctrl+d 删除当前光标字符
    7、ctrl+< 光标向右移动一个单词结尾,相当于alt+f
    8、ctrl+> 光标向左移动一个单纯首字母,相当于alt+b
    9、ctrl+r 删除当前整行
    10、ctrl+a 光标到命令行首,相当于Home
    11、ctrl+e 光标到命令行尾,相当于End

8、Linux的目录结构

  • /:根目录结构

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    [root@localhost ~]# ll /
    总用量 28
    lrwxrwxrwx. 1 root root 7 6月 22 2021 bin -> usr/bin
    dr-xr-xr-x. 5 root root 4096 7月 10 10:01 boot
    drwxr-xr-x. 2 root root 6 7月 10 09:45 data
    drwxr-xr-x. 18 root root 3080 7月 13 10:53 dev
    drwxr-xr-x. 142 root root 8192 7月 14 08:52 etc
    drwxr-xr-x. 3 root root 17 7月 10 10:08 home
    lrwxrwxrwx. 1 root root 7 6月 22 2021 lib -> usr/lib
    lrwxrwxrwx. 1 root root 9 6月 22 2021 lib64 -> usr/lib64
    drwxr-xr-x. 2 root root 6 6月 22 2021 media
    drwxr-xr-x. 3 root root 18 7月 10 09:50 mnt
    drwxr-xr-x. 2 root root 6 6月 22 2021 opt
    dr-xr-xr-x. 279 root root 0 7月 13 10:52 proc
    dr-xr-x---. 15 root root 4096 7月 14 14:37 root
    drwxr-xr-x. 43 root root 1240 7月 14 01:40 run
    lrwxrwxrwx. 1 root root 8 6月 22 2021 sbin -> usr/sbin
    drwxr-xr-x. 2 root root 6 6月 22 2021 srv
    dr-xr-xr-x. 13 root root 0 7月 13 10:53 sys
    drwxrwxrwt. 24 root root 4096 7月 14 13:43 tmp
    drwxr-xr-x. 13 root root 158 7月 10 09:49 usr
    drwxr-xr-x. 21 root root 4096 7月 10 10:01 var


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!