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 | 当前工作目录基名 |
\t | 24小时时间格式:时:分:秒 |
\A | 24小时时间格式:时:分 |
\T | 12小时时间格式:时:分:秒 |
\! | 命令历史数 |
\ # | 开机后命令历史数 |
\d | 日期:星期 月 日 |
\v | BASH的版本信息 |
\e | 设置颜色,也可用\033表示,格式为:[\e[F;B;Sm]](下为详解) |
“\e”选项格式中,‘F’为字体颜色,编号为30-37 ;‘B’为背景色,编号为40-47;对应颜色如下表:
字体颜色F | 背景色B | 颜色 |
---|---|---|
30 | 40 | 黑色 |
31 | 41 | 红色 |
32 | 42 | 绿色 |
33 | 43 | 黄色 |
34 | 44 | 蓝色 |
35 | 45 | 紫色 |
36 | 46 | 青色 |
37 | 47 | 白色 |
“\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:帮助手册(几乎所有命令)
- man页面分组为不同的“章节”,统称为Linux手册:
章节 | 含义 |
---|---|
1 | 用户命令 |
2 | 系统调用 |
3 | C库调用 |
4 | 设备文件及特殊文件 |
5 | 配置文件格式 |
6 | 游戏 |
7 | 杂项 |
8 | 管理类的命令 |
9 | Linux 内核API |
- man使用格式:man [章节][OPTION] keyword
选项 | 含义 |
---|---|
[章节数] | 查看对应章节 |
-a | 列出所有帮助 |
-k | 列出所有匹配的页面 |
-w | 打印man帮助文件的路径 |
-f | 相当于whatis |
-
man帮助手册中的段落说明:
NAME 名称及简要说明 SYNOPSIS 用法格式说明 • [] 可选内容 • <> 必选内容 • a|b 二选一 • { } 分组 • ... 同一内容可出现多次 DESCRIPTION 详细说明 OPTIONS 选项说明 EXAMPLES 示例 FILES 相关文件 AUTHOR 作者 COPYRIGHT 版本信息 REPORTING BUGS bug信息 SEE ALSO 其它帮助参考
-
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 回到文件首部 回到文件尾部 -
man搜索
/KEYWORD: 从当前位置向文件尾部搜索;不区分大小写; n: 下一个 N:上一个 ?KEYWORD: 从当前位置向文件首部搜索;不区分大小写; n: 跟搜索命令同方向,下一个 N:跟搜索命令反方向,上一个
-
其他
存放位置:/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. 文本处理三剑客