Linux常见命令及用法

rpm包相关命令:
#查看二进制程序所依赖的库文件
# ldd /PATH/TO/BINARY_FILE
#管理及查看本机装载的库文件
# ldconfig --help

#rpm命令常见用法
# rpm -ivh -e -qi -ql -qf -qpi rpmfile  -qc -q --scripts -qa  --force --nodeps  
#注意:当包卸载时,对应的配置文件不会删除, 以FILENAME.rpmsave形式保留

#yum命令常见用法
# yum install | remove | list| provides | repolist | clean all | history undo,redo N  |search | info 

# rpm2cpio 包文件|cpio –itv 预览包内文件
# rpm2cpio 包文件|cpio –id “*.conf” 释放包内文件
分区相关命令:
#1、同步
#centos6加分区:
# partx -a /dev/sda
#centos6删除分区: 
# partx -d --nr 5-7 /dev/sda 
#centos5,7
# partprobe 

常见命令

1. 命令提示符

  • 查看当下提示符格式:echo $PS1
  • 修改提示符格式可参考以下:
    PS1="[\e[1;41;33m][\u@\h \W]$\e[0m]]"
    PS1="[\e[1;32m][[\e[0m]\t [\e[1;33m]\u[\e[36m]@\h[\e[1;31m] \W[\e[1;32m]][\e[0m]\$"
  • 格式中符号及对应含义:
符号含义
\ $提示符(#为root用户,$为普通用户)
\u当前用户
\h主机名简称
\H主机名
\w当前工作目录,家目录为~
\W当前工作目录基名
\t24小时时间格式:时:分:秒
\A24小时时间格式:时:分
\T12小时时间格式:时:分:秒
\!命令历史数
\ #开机后命令历史数
\d日期:星期 月 日
\vBASH的版本信息
\e设置颜色,也可用\033表示,格式为:[\e[F;B;Sm]](下为详解)

“\e”选项格式中,‘F’为字体颜色,编号为30-37 ;‘B’为背景色,编号为40-47;对应颜色如下表:

字体颜色F背景色B颜色
3040黑色
3141红色
3242绿色
3343黄色
3444蓝色
3545紫色
3646青色
3747白色

“\e”选项格式中,‘S’为显示的样式,常见使用如下:

符号含义
0关闭颜色设置
1粗体
4加下划线
5闪烁
7字体颜色与背景色互换
8隐藏

2. 显示系统及硬件相关信息

  • echo ${SHELL}:查看当前shell类型
  • cat /etc/shells:查看当前系统支持的shell类型
  • pstree:查看shell如何运行
  • tty:查看当前的终端设备
  • lsb_release -a:查看发行版本
  • cat /etc/os-release:显示操作系统发行版本
  • uname -r:显示内核版本
[root@CentOS7 ~]# uname --help
Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type or "unknown"
  -i, --hardware-platform  print the hardware platform or "unknown"
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit
[root@CentOS7 ~]# uname -a
Linux CentOS7.localdomain 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@CentOS7 ~]# uname
Linux
[root@CentOS7 ~]# uname -s
Linux
[root@CentOS7 ~]# uname -n
CentOS7.localdomain
[root@CentOS7 ~]# uname -r
3.10.0-1062.el7.x86_64
[root@CentOS7 ~]# uname -v
#1 SMP Wed Aug 7 18:08:02 UTC 2019
[root@CentOS7 ~]# uname -m
x86_64
[root@CentOS7 ~]# uname -p
x86_64
[root@CentOS7 ~]# uname -i
x86_64
[root@CentOS7 ~]# uname -o
GNU/Linux
[root@CentOS7 ~]# uname --version 
uname (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.
  • hostname:显示当前主机名
[root@CentOS7 ~]# hostname
CentOS7.localdomain
  • lscpu:显示CPU型号
[root@CentOS7 ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2
On-line CPU(s) list:   0,1
Thread(s) per core:    1
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 142
Model name:            Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Stepping:              10
CPU MHz:               1800.001
BogoMIPS:              3600.00
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              6144K
NUMA node0 CPU(s):     0,1
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 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat spec_ctrl intel_stibp flush_l1d arch_capabilities
  • free -h:显示内存大小
[root@CentOS7 ~]# free --help

Usage:
 free [options]

Options:
 -b, --bytes         show output in bytes
 -k, --kilo          show output in kilobytes
 -m, --mega          show output in megabytes
 -g, --giga          show output in gigabytes
     --tera          show output in terabytes
     --peta          show output in petabytes
 -h, --human         show human-readable output
     --si            use powers of 1000 not 1024
 -l, --lohi          show detailed low and high memory statistics
 -t, --total         show total for RAM + swap
 -s N, --seconds N   repeat printing every N seconds
 -c N, --count N     repeat printing N times, then exit
 -w, --wide          wide output

     --help     display this help and exit
 -V, --version  output version information and exit

For more details see free(1).
[root@CentOS7 ~]# free -b
              total        used        free      shared  buff/cache   available
Mem:     1907818496   779612160   167923712    16863232   960282624   936218624
Swap:    4294963200     1581056  4293382144
[root@CentOS7 ~]# free -k
              total        used        free      shared  buff/cache   available
Mem:        1863104      761372      163956       16468      937776      914244
Swap:       4194300        1544     4192756
[root@CentOS7 ~]# free 
              total        used        free      shared  buff/cache   available
Mem:        1863104      760992      164312       16480      937800      914612
Swap:       4194300        1544     4192756
[root@CentOS7 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1819         743         160          16         915         892
Swap:          4095           1        4094
[root@CentOS7 ~]# free -g
              total        used        free      shared  buff/cache   available
Mem:              1           0           0           0           0           0
Swap:             3           0           3
[root@CentOS7 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.8G        743M        160M         16M        915M        892M
Swap:          4.0G        1.5M        4.0G
[root@CentOS7 ~]# free -l
              total        used        free      shared  buff/cache   available
Mem:        1863104      761236      164080       16468      937788      914380
Low:        1863104     1699024      164080
High:             0           0           0
Swap:       4194300        1544     4192756
[root@CentOS7 ~]# free -t
              total        used        free      shared  buff/cache   available
Mem:        1863104      761488      163816       16480      937800      914116
Swap:       4194300        1544     4192756
Total:      6057404      763032     4356572
[root@CentOS7 ~]# free -s 1
              total        used        free      shared  buff/cache   available
Mem:        1863104      761472      163832       16480      937800      914132
Swap:       4194300        1544     4192756

              total        used        free      shared  buff/cache   available
Mem:        1863104      761464      163840       16480      937800      914140
Swap:       4194300        1544     4192756
[root@CentOS7 ~]# free -c 3
              total        used        free      shared  buff/cache   available
Mem:        1863104      761348      163956       16480      937800      914256
Swap:       4194300        1544     4192756

              total        used        free      shared  buff/cache   available
Mem:        1863104      761340      163964       16480      937800      914264
Swap:       4194300        1544     4192756

              total        used        free      shared  buff/cache   available
Mem:        1863104      761872      163432       16480      937800      913732
Swap:       4194300        1544     4192756
[root@CentOS7 ~]# 
[root@CentOS7 ~]# free -w
              total        used        free      shared     buffers       cache   available
Mem:        1863104      761996      163304       16484         192      937612      913604
Swap:       4194300        1544     4192756
[root@CentOS7 ~]# free -k
              total        used        free      shared  buff/cache   available
Mem:        1863104      761476      163816       16488      937812      914120
Swap:       4194300        1544     4192756
[root@CentOS7 ~]# free -V
free from procps-ng 3.3.10
  • psaux:查看当前运行的所有程序
  • source或.+参数:配置后重新读取文件
  • ifconfig:查看当前系统网卡IP地址(老旧)
[root@CentOS7 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.37.100  netmask 255.255.255.0  broadcast 192.168.37.255
        inet6 fe80::cf34:6dbe:91f7:54  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:6f:47:22  txqueuelen 1000  (Ethernet)
        RX packets 251943  bytes 344413359 (328.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 85332  bytes 7084864 (6.7 MiB)
        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 144  bytes 12240 (11.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 144  bytes 12240 (11.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 52:54:00:e4:a6:a4  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
[root@CentOS7 ~]# ifconfig --help
Usage:
  ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
  [add <address>[/<prefixlen>]]
  [del <address>[/<prefixlen>]]
  [[-]broadcast [<address>]]  [[-]pointopoint [<address>]]
  [netmask <address>]  [dstaddr <address>]  [tunnel <address>]
  [outfill <NN>] [keepalive <NN>]
  [hw <HW> <address>]  [mtu <NN>]
  [[-]trailers]  [[-]arp]  [[-]allmulti]
  [multicast]  [[-]promisc]
  [mem_start <NN>]  [io_addr <NN>]  [irq <NN>]  [media <type>]
  [txqueuelen <NN>]
  [[-]dynamic]
  [up|down] ...

  <HW>=Hardware Type.
  List of possible hardware types:
    loop (Local Loopback) slip (Serial Line IP) cslip (VJ Serial Line IP) 
    slip6 (6-bit Serial Line IP) cslip6 (VJ 6-bit Serial Line IP) adaptive (Adaptive Serial Line IP) 
    ash (Ash) ether (Ethernet) ax25 (AMPR AX.25) 
    netrom (AMPR NET/ROM) rose (AMPR ROSE) tunnel (IPIP Tunnel) 
    ppp (Point-to-Point Protocol) hdlc ((Cisco)-HDLC) lapb (LAPB) 
    arcnet (ARCnet) dlci (Frame Relay DLCI) frad (Frame Relay Access Device) 
    sit (IPv6-in-IPv4) fddi (Fiber Distributed Data Interface) hippi (HIPPI) 
    irda (IrLAP) ec (Econet) x25 (generic X.25) 
    infiniband (InfiniBand) eui64 (Generic EUI-64) 
  <AF>=Address family. Default: inet
  List of possible address families:
    unix (UNIX Domain) inet (DARPA Internet) inet6 (IPv6) 
    ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE) 
    ipx (Novell IPX) ddp (Appletalk DDP) ec (Econet) 
    ash (Ash) x25 (CCITT X.25) 
[root@CentOS7 ~]#

3. 用户登录信息

  • whoami:当前有效用户,确认当前身份
  • who:当前所有会话
  • w:当前所有会话及操作
[root@CentOS7 ~]# who
root     :0           2019-12-09 22:17 (:0)
root     pts/1        2019-12-09 23:04 (192.168.37.1)
root     pts/0        2019-12-09 22:12 (192.168.37.1)
[root@CentOS7 ~]# whoami
root
[root@CentOS7 ~]# w
 23:25:52 up  4:14,  3 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     :0       :0               22:17   ?xdm?   2:52   0.62s /usr/libexec/gnome-session-binary --session gnome-classic
root     pts/1    192.168.37.1     23:04    0.00s  0.33s  0.07s w
root     pts/0    192.168.37.1     22:12   22:56   0.68s  0.68s -bash

4. 常用简单命令及选项(ls,cd,mv,cp,rm等)

  • ls:列出目录内容
    用法:ls [options] [ files_or_dirs ]
选项含义
-a包含隐藏文件
-l显示额外的信息
-R目录递归
-ld目录和符号链接信息
-1文件分行显示
-S按从大到小排序
-t按mtime排序
-u配合-t选项,显示并按atime从新到旧排序
-U按目录存放顺序显示
-X按文件后缀排序
  • cd:切换目录(-P)
    cd 当前用户主目录
    cd … 父目录
    cd - 以前工作目录
    相关的环境变量:
    PWD:当前目录路径
    OLDPWD:上一次目录路径
  • mv:移动和重命名文件
    mv [OPTION]… [-T] SOURCE DEST
    mv [OPTION]… SOURCE… DIRECTORY
    mv [OPTION]… -t DIRECTORY SOURCE…
选项含义
-i交互式
-f强制
-b目标存在,覆盖前先备份
  • cp:复制文件和目录
    cp [OPTION]… [-T] SOURCE DEST
    cp [OPTION]… SOURCE… DIRECTORY
    cp [OPTION]… -t DIRECTORY SOURCE…
    cp SRC DEST
选项含义
-i覆盖前提示
-n不覆盖,注意两者顺序
-R,-r递归复制目录及内部的所有内容
-a归档,相当于-dR --preserv=all
-d–no-dereference --preserv=links 不复制原文件,只复制链接名
-p等同–preserv=mode,ownership,timestamp
-v–verbose
-f–force
-u–update 只复制源比目标更新文件或目标不存在的文件
-b目标存在,覆盖前先备份,形式为 filename~
–backup=numbered目标存在,覆盖前先备份加数字后缀
–preserv[=ATTR_LIST]mode: 权限;ownership: 属主属组;timestamp: links,xattr,context,all
  • rm:删除
    rm [OPTION]… FILE…
选项含义
-i交互式
-f强制删除
-r递归
–no-preserve-root删除/
  • touch:创建空文件和刷新时间
    格式:touch [OPTION]… FILE…
选项含义
-a仅改变 atime和ctime
-m仅改变 mtime和ctime
-t [[CC]YY]MMDDhhmm[.ss]指定atime和mtime的时间戳
-c如果文件不存在,则不予创建
  • file:确定文件内容
    file [options] < filename>…
选项含义
-b列出文件辨识结果时,不显示文件名称
-f filelist列出文件filelist中文件名的文件类型
-F使用指定分隔符号替换输出文件名后默认的”:”分隔符
-L查看对应软链接对应文件的文件类型
  • stat:查看文件状态
    文件:metadata, data
    三个时间戳:
    access time 访问时间,atime,读取文件内容
    modify time 修改时间, mtime,改变文件内容(数据)
    change time 改变时间, ctime,元数据发生改变
  • screen:远程共享
选项或操作含义
-S创建会话
-X加入会话
-r恢复会话
-ls显示当前所有会话
ctrl+a/ctal+d临时剥离会话
exit退出、关闭

5. 目录操作

  • tree:显示目录树
选项含义
-d只显示目录
-L指定显示的层级数目
-P只显示由指定pattern匹配到的路径
  • mkdir:创建目录
选项含义
-p存在于不报错,且可自动创建所需的各目录
-v显示详细信息
-m创建目录时直接指定权限
  • rmdir:删除空目录
选项含义
-p递归删除父空目录
-v显示详细信息
  • rm -r:递归删除目录树
    6. 关机重启

  • 关机:halt, poweroff

  • 重启:reboot
    -f: 强制,不调用shutdown
    -p: 切断电源

  • 关机或重启:shutdown
    shutdown [OPTION]… [TIME] [MESSAGE]
    OPTION:
    -r: reboot
    -h: halt
    -c:cancel
    TIME:
    默认+1(CentOS7)
    now: 立刻,相当于+0
    +m: 相对时间表示法,几分钟之后;例如 +3
    hh:mm: 绝对时间表示,指明具体时间
    (cmd:支持远程关机 shutdown /s /t + 时间;shutdown /a :取消)

7. 日期与时间

  • date:系统时间
  • clock:硬件时间
    -s 以硬件时钟为准,校正系统时钟
    -w 以系统时钟为准,校正硬件时钟
  • ntpdate +ip:与远程时间同步
  • 时区:/etc/localtime
  • cal -y :显示日历

8. 显示字符(echo

  • 格式:echo [-neE][字符串]
选项含义
-n不自动换行
-e启用 \ 字符的解释功能
-E(默认)不支持 \ 解释功能

“-e”选项时,若字符串中出现以下字符,则特别加以处理,而不会将它当成 一般文字输出

选项含义
\a发出警告声
\b退格键
\c单行
\e相当于\033
\n换行,光标移至行首
\r回车但不换行,光标移至行首
\t插入tab
\插入\字符
\onnn插入八进制(nnn)所代表的ASCII字符
\xHH插入十六进制(HH)所代表的ASCII字符
[root@CentOS7 ~]# echo -e '\033[43;31;5mmagedu\e[0m' 
  • 命令行扩展:$( ) 或`` :把一个命令的输出打印给另一个命令的参数
[root@CentOS7 ~]# echo "This system's name is $(hostname) " 
This system's name is CentOS7.localdomain 
[root@CentOS7 ~]# echo "i am `whoami` " i am root
i am root  i am root
  • 括号扩展:{ } 打印重复字符串的简化形式
[root@CentOS7 ~]# echo file{1,3,5}  
file1 file3 file5
[root@CentOS7 ~]# echo {a..z} 
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 {000..20..2} 
000 002 004 006 008 010 012 014 016 018 020
[root@CentOS7 ~]# echo {a,b,c}{2,7}
a2 a7 b2 b7 c2 c7

9. 命令分类:内部命令与外部命令

  • 内部命令:由shell自带的,而且通过某命令形式提供
    help:显示内部命令列表
    enable cmd 启用内部命令
    enable –n cmd 禁用内部命令
    enable –n 查看所有禁用的内部命令
  • 外部命令:在文件系统路径下有对应的可执行程序文件
    查看路径:which -a |–skip-alias ; whereis
  • 区别指定的命令是内部或外部命令:type
    type COMMAND
  • 命令执行顺序:别名>内部命令>外部命令(hash表>$path)

10. 显示缓存(hash

选项含义
hash显示hash缓存
hash -l显示hash缓存,可作为输入使用
hash -p path name将命令全路径path起别名为name
hash –t name打印缓存中name的路径
hash –d name清除name缓存
hash –r清除缓存

11. 别名(alias

  • 定义别名:alias NAME=‘VALUE’
  • 配置文件:
    仅对当前用户:~/.bashrc
    对所有用户有效:/etc/bashrc
  • 配置后重新读取文件:
    source /path/to/config_file
    . /path/to/config_file
  • 撤消别名:unalias
    unalias [-a] name [name …]
    -a 取消所有别名
  • 同名时执行原命令:
    \ALIASNAME
    “ALIASNAME”
    ‘ALIASNAME’
    command ALIASNAME
    /path/commmand

12. 获取帮助(whatis,help,man,info,其他途径)
内部命令:help COMMAND或man bash
外部命令:
(1) whatis COMMAND
(2) COMMAND --help 或 COMMAND -h
(3) man COMMAND
(4) info COMMAND
(5) 本地文档 README;INSTALL;ChangeLog
(6) 程序官方文档 官方站点:Documentation
(7) 发行版的官方文档
(8) Google

  • whatis 相当于 man -f:简短描述
  • help:显示用法总结和参数列表(大多数命令)
    示例: date --help
date --help      
Usage: 
date [OPTION]... [+FORMAT] 
or: date [-u|--utc|-universal] [MMDDhhmm[[CC]YY][.ss]]  
[] 表示可选项  
CAPS或 <> 表示变化的数据  
... 表示一个列表  
x |y| z 的意思是“ x 或 y 或 z “   
-abc的 意思是-a -b –c  
{ }  表示分组 
  • man:帮助手册(几乎所有命令)
  1. man页面分组为不同的“章节”,统称为Linux手册:
章节含义
1用户命令
2系统调用
3C库调用
4设备文件及特殊文件
5配置文件格式
6游戏
7杂项
8管理类的命令
9Linux 内核API
  1. man使用格式:man [章节][OPTION] keyword
选项含义
[章节数]查看对应章节
-a列出所有帮助
-k列出所有匹配的页面
-w打印man帮助文件的路径
-f相当于whatis
  1. man帮助手册中的段落说明:

    NAME  名称及简要说明 
    SYNOPSIS 用法格式说明 
    	• [] 可选内容  
    	• <>  必选内容 
    	• a|b 二选一 
    	• { } 分组 
    	• ... 同一内容可出现多次 
    DESCRIPTION 详细说明 
    OPTIONS  选项说明 
    EXAMPLES 示例 
    FILES  相关文件 
    AUTHOR 作者 
    COPYRIGHT 版本信息 
    REPORTING BUGS bug信息 
    SEE ALSO 其它帮助参考 
    
  2. man命令的操作方法:使用less命令实现

    操作方法含义
    pace, ^v, ^f, ^F向文件尾翻屏
    b, ^b向文件首部翻屏
    d, ^d向文件尾部翻半屏
    u, ^u向文件首部翻半屏
    ETURN, ^N, e, ^E or j or ^J向文件尾部翻一行
    y or ^Y or ^P or k or ^K向文件首部翻一行
    q退出
    #跳转至第#行
    G回到文件首部
    回到文件尾部
  3. man搜索

     /KEYWORD: 从当前位置向文件尾部搜索;不区分大小写;  
     	n: 下一个  
     	N:上一个 
     ?KEYWORD: 从当前位置向文件首部搜索;不区分大小写;       
     	n: 跟搜索命令同方向,下一个       
     	N:跟搜索命令反方向,上一个 
    
  4. 其他
    存放位置:/usr/share/man
    配置文件:/etc/man.config | man_db.conf
    MANPATH /PATH/TO/SOMEWHERE: 指明man文件搜索位置
    man -M /PATH/TO/SOMEWHERE COMMAND: 到指定位置下搜索 COMMAND命令的手册页并显示
    中文man需安装包man-pages-zh-CN

  • info:通用文档参考、信息页(使用较少)

    没有参数,列出所有的页面
    info 页面的结构就像一个网站,每一页分为“节点” ,链接节点之前 *
    info命令常见操作方法如下表:

操作方法含义
方向键,PgUp,PgDn导航
Tab键移动到下一个链接
d显示主题目录
Home显示主题首部
Enter进入选定链接
n/p/u/l进入下/前/上一层/最后一个链接
s文字 文本搜索
q退出 info
  • 本地文档
    1、System->help(centos6)
    2、 Applications -> documentation->help(centos7)
    3、/usr/share/doc目录:README;INSTALL;CHANGES

  • 在线文档
    1、 第三方应用官方文档
    http://httpd.apache.org
    http://www.nginx.org
    https://mariadb.com/kb/en
    https://dev.mysql.com/doc/
    http://tomcat.apache.org
    http://www.python.org
    2、红帽知识库和官方在线文档
    http://kbase.redhat.com
    http://www.redhat.com/docs
    http://access.redhat.com
    https://help.ubuntu.com/lts/serverguide/index.html
    3、网站和搜索
    http://tldp.org
    http://www.slideshare.net
    http://www.google.com:Openstack filetype:pdf ;rhca site:redhat.com/docs

13. 历史命令
退出时自动保存并追加至命令历史文件中(/etc/profile)(./.bash_history)

  • 执行历史命令
    up(向上)和down(向下)键:上下浏览历史命令,回车执行
    执行前一条命令的几种方法:向上键;!!;!-1;ctrl+p
    !n 执行history命令输出对应序号n的命令
    !-n 执行history历史中倒数第n个命令
    !string 重复前一个以“string”开头的命令
    !?string 重复前一个包含string的命令

  • 调用历史命令的某个参数
    调用上一条命令中最后一个参数的几种方法:!$ ;Esc, . ;Alt+ .
    COMMAND !^ 利用上一条命令的第一个参数做cmd的参数
    COMMAND !$ 利用上一条命令的最后一个参数做cmd的参数
    COMMAND !* 利用上一条命令的全部参数做cmd的参数
    COMMAND !:n 利用上一条命令的第n个参数做cmd的参数
    COMMAND !n:^ 调用第n条命令的第一个参数
    COMMAND !n:$ 调用第n条命令的最后一个参数
    COMMAND !n:m 调用第n条命令的第m个参数
    COMMAND !n:* 调用第n条命令的所有参数
    COMMAND !string:^ 搜索以 string 开头的命令,并调用它的第一个参数
    COMMAND !string:$ 搜索以 string 开头的命令,并调用它的最后一个参数
    COMMAND !string:n 搜索以 string 开头的命令,并调用它的第n个参数
    COMMAND !string:* 搜索以 string 开头的命令,并调用它的所有参数

  • 其他

    • 执行当前命令:Ctrl + j
    • 显示当前历史中的下一条命令,但不执行:Ctrl + n
    • 删除替换:
      ^string 删除上一条命令中的第一个string
      ^string1 ^string2 将上一条命令中的第一个string1替换为string2
      !:gs/string1/string2 将上一条命令中所有的string1都替换为 string2
    • 打印:
      !string:p 仅打印命令历史,而不执行
      !$ :p 打印输出 !$ (上一条命令的最后一个参数)的内容
      !* :p 打印输出 !*(上一条命令的所有参数)的内容
    • 搜索
      ctrl-r来在命令历史中搜索命令
      Ctrl+g:从历史搜索模式退出
  • 查看历史命令:history
    history [-c] [-d offset] [n]:清空、删除
    history -anrw [filename]:追加
    history -ps arg [arg…]:展开参数

选项或符号含义
-c清空命令历史
\d offset删除历史中指定的第offset个命令
n显示最近的n条历史
-a追加本次会话新执行的命令历史列表至历史文件
-r读历史文件附加到历史列表
-w保存历史列表到指定的历史文件
-p展开历史参数成多行,但不存在历史列表中
-s展开历史参数成一行,附加在历史列表后
  • 命令历史相关环境变量
    HISTFILE:指定历史文件,默认为~/.bash_history
    HISTFILESIZE:命令历史文件记录历史的条数
    HISTTIMEFORMAT=“%F %T “ 显示时间
    HISTIGNORE=“str1:str2*:… “ 忽略str1命令,str2开头的历史
    export 变量名="值“
    存放在 /etc/profile 或 ~/.bash_profile
    控制命令历史的记录方式(环境变量:HISTCONTROL):
选项含义
ignoredups默认,忽略重复的命令,连续且相同为“重复”
ignorespace忽略所有以空白开头的命令
ignoreboth相当于ignoredups, ignorespace的组合
erasedups删除重复命令

14. bash常见快捷键

Ctrl + l 清屏,相当于clear命令
Ctrl + o 执行当前命令,并重新显示本命令
Ctrl + s 阻止屏幕输出,锁定
Ctrl + q 允许屏幕输出
Ctrl + c 终止命令
Ctrl + z 挂起命令
Ctrl + a 光标移到命令行首,相当于Home
Ctrl + e 光标移到命令行尾,相当于End
Ctrl + f 光标向右移动一个字符
Ctrl + b 光标向左移动一个字符
Alt + f 光标向右移动一个单词尾
Alt + b 光标向左移动一个单词首
Ctrl + xx 光标在命令行首和光标之间移动
Ctrl + u 从光标处删除至命令行首
Ctrl + k 从光标处删除至命令行尾
Alt + r 删除当前整行
Ctrl + w 从光标处向左删除至单词首
Alt + d 从光标处向右删除至单词尾
Ctrl + d 删除光标处的一个字符
Ctrl + h 删除光标前的一个字符
Ctrl + y 将删除的字符粘贴至光标后
Alt + c 从光标处开始向右更改为首字母大写的单词
Alt + u 从光标处开始,将右边一个单词更改为大写
Alt + l 从光标处开始,将右边一个单词更改为小写
Ctrl + t 交换光标处和之前的字符位置
Alt + t 交换光标处和之前的单词位置
Alt + N 提示输入指定字符后,重复显示该字符N次
注意:Alt组合快捷键经常和其它软件冲突

15. 其他基础命令

  • nano:文本编辑
  • sleep:休眠
  • id
[root@CentOS7 ~]# id --help
Usage: id [OPTION]... [USER]
Print user and group information for the specified USER,
or (when USER omitted) for the current user.

  -a             ignore, for compatibility with other versions
  -Z, --context  print only the security context of the current user
  -g, --group    print only the effective group ID
  -G, --groups   print all group IDs
  -n, --name     print a name instead of a number, for -ugG
  -r, --real     print the real ID instead of the effective ID, with -ugG
  -u, --user     print only the effective user ID
  -z, --zero     delimit entries with NUL characters, not whitespace;
                   not permitted in default format
      --help     display this help and exit
      --version  output version information and exit

Without any OPTION, print some useful set of identified information.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'id invocation'
[root@CentOS7 ~]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@CentOS7 ~]# id -a
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@CentOS7 ~]# id -g
0
[root@CentOS7 ~]# id -u
0
[root@CentOS7 ~]# id -Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@CentOS7 ~]# id -G
0
[root@CentOS7 ~]# id -nu
root
[root@CentOS7 ~]# id -ng
root
[root@CentOS7 ~]# id -nG
root
[root@CentOS7 ~]# id -ru
0
[root@CentOS7 ~]# id -rg
0
[root@CentOS7 ~]# id -rG
0
[root@CentOS7 ~]# id -zu
0[root@CentOS7 ~]# id -zg
0[root@CentOS7 ~]# id -zG
0[root@CentOS7 ~]# id --version
id (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Arnold Robbins and David MacKenzie.
  • pstree:查看如何运行shell
[root@CentOS7 ~]# pstree --help
pstree: unrecognized option '--help'
Usage: pstree [ -a ] [ -c ] [ -h | -H PID ] [ -l ] [ -n ] [ -p ] [ -g ] [ -u ]
              [ -A | -G | -U ] [ PID | USER ]
       pstree -V
Display a tree of processes.

  -a, --arguments     show command line arguments
  -A, --ascii         use ASCII line drawing characters
  -c, --compact       don't compact identical subtrees
  -h, --highlight-all highlight current process and its ancestors
  -H PID,
  --highlight-pid=PID highlight this process and its ancestors
  -g, --show-pgids    show process group ids; implies -c
  -G, --vt100         use VT100 line drawing characters
  -l, --long          don't truncate long lines
  -n, --numeric-sort  sort output by PID
  -N type,
  --ns-sort=type      sort by namespace type (ipc, mnt, net, pid, user, uts)
  -p, --show-pids     show PIDs; implies -c
  -s, --show-parents  show parents of the selected process
  -S, --ns-changes    show namespace transitions
  -u, --uid-changes   show uid transitions
  -U, --unicode       use UTF-8 (Unicode) line drawing characters
  -V, --version       display version information
  -Z,
  --security-context   show SELinux security contexts
  PID    start at this PID; default is 1 (init)
  USER   show only trees rooted at processes of this user
  • gedit

16. 文件通配符

*匹配零个或多个字符
? 匹配任何单个字符
~ 当前用户家目录
~ mage 用户mage家目录
~ + 当前工作目录
~- 前一个工作目录
[0-9] 匹配数字范围
[a-z]:字母
[A-Z]:字母
[wang] 匹配列表中的任何的一个字符
[ ^wang] 匹配列表中的所有字符以外的字符

预定义的字符类:man 7 glob
[:digit:]:任意数字,相当于0-9
[:lower:]:任意小写字母
[:upper:]: 任意大写字母
[:alpha:]: 任意大小写字母
[:alnum:]:任意数字或字母
[:blank:]:水平空白字符
[:space:]:水平或垂直空白字符
[:punct:]:标点符号
[:print:]:可打印字符
[:cntrl:]:控制(非打印)字符
[:graph:]:图形字符
[:xdigit:]:十六进制字符
17. 文件查找相关命令
18. 文本处理三剑客

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值