陈千语都能看懂的入门级Linux命令(1)
Linux代码指南-Linux 命令行
文章目录
基础知识
控制台
Console,也就是控制台,也称为终端,提供命令行输入数据和展示命令行输出数据。
- 物理控制台,用于与系统交互的硬件接口。
- 虚拟控制台, 名称为tty1–tty6,通过ctrl + alt + F1…F6切换。tty1是图形化程序所在的终端。
ctrl + alt + F3 进入3号虚拟控制台,登录后,执行tty命令,效果如下:
输入密码的时候,屏幕是不显示任何字符的。
shell 介绍
shell,用于解析终端中输入的字符串,交由kernel执行,并将执行结果显示到终端中。Linux命令行由shell程序提供。在Linux发展过程中,产生了多种shell程序。Bash是类UNIX系统中最成功的shell,也是用户的默认shell。
命令提示符
作用:提示计算机正在等待用户的输入。
# 代表普通用户提示符,提示符最后是有一个空格。
[RBH@CentOS7 ~]$ date
# 代表管理员提示符
[root@CentOS7 ~]#
shell 解析字符串的语法
shell命令行,通过空格分隔,包涵三个部分:
- 命令,第一部分必须是命令,代表要执行的程序,其后可能跟着选项或参数。
- 选项,调整命令的行为或作用。通常以一个或两个
-符号开头,例如(-a --all)。 - 参数,典型的参数是命令的目标,命令后面可能接多个参数。
Enter键,shell开始解析命令行中字符串,并交由kernel执行。
基础命令
一行要执行多个命令,使用分号(;)分隔。(e.g. ls;date)
–help
命令后面加上–help可以看命令的使用方法:

#注:只有history命令是
history help
ls
作用:列出当前文件夹里面所有文件和目录
用法:ls [选项]… [文件]…
ls -l # 长格式,看权限、所有者、大小、时间
ls -a # 显示所有文件,包含隐藏文件(以 . 开头的)
ls --all # -l + -a 组合,最常用
#效果:
[RBH@centos7 ~ 09:49:04]$ ls -l
总用量 0
drwxr-xr-x. 2 RBH RBH 6 9月 1 15:09 公共
drwxr-xr-x. 2 RBH RBH 6 9月 1 15:09 模板
drwxr-xr-x. 2 RBH RBH 6 9月 1 15:09 视频
drwxr-xr-x. 2 RBH RBH 6 9月 1 15:09 图片
drwxr-xr-x. 2 RBH RBH 6 9月 1 15:09 文档
drwxr-xr-x. 2 RBH RBH 6 9月 1 15:09 下载
drwxr-xr-x. 2 RBH RBH 6 9月 1 15:09 音乐
drwxr-xr-x. 2 RBH RBH 6 9月 1 15:09 桌面
[RBH@centos7 ~ 11:23:44]$ ls -a
. .bash_logout .bashrc .config .esd_auth .local .Xauthority 模板 图片 下载 桌面
.. .bash_profile .cache .dbus .ICEauthority .mozilla 公共 视频 文档 音乐
[RBH@centos7 ~ 11:23:48]$ ls --all
. .bash_logout .bashrc .config .esd_auth .local .Xauthority 模板 图片 下载 桌面
.. .bash_profile .cache .dbus .ICEauthority .mozilla 公共 视频 文档 音乐

附:
-a, --all 不隐藏任何以. 开始的项目
-A, --almost-all 列出除. 及.. 以外的任何项目
--author 与-l 同时使用时列出每个文件的作者
-b, --escape 以八进制溢出序列表示不可打印的字符
--block-size=SIZE scale sizes by SIZE before printing them; e.g.,
'--block-size=M' prints sizes in units of
1,048,576 bytes; see SIZE format below
-B, --ignore-backups do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last
modification of file status information);
with -l: show ctime and sort by name;
otherwise: sort by ctime, newest first
-C list entries by columns
--color[=WHEN] colorize the output; WHEN can be 'never', 'auto',
or 'always' (the default); more info below
-d, --directory list directories themselves, not their contents
-D, --dired generate output designed for Emacs' dired mode
-f do not sort, enable -aU, disable -ls --color
-F, --classify append indicator (one of */=>@|) to entries
--file-type likewise, except do not append '*'
--format=WORD across -x, commas -m, horizontal -x, long -l,
single-column -1, verbose -l, vertical -C
--full-time like -l --time-style=full-iso
-g 类似-l,但不列出所有者
--group-directories-first
group directories before files;
can be augmented with a --sort option, but any
use of --sort=none (-U) disables grouping
-G, --no-group 以一个长列表的形式,不输出组名
-h, --human-readable 与-l 一起,以易于阅读的格式输出文件大小
(例如 1K 234M 2G)
--si 同上面类似,但是使用1000 为基底而非1024
-H, --dereference-command-line
follow symbolic links listed on the command line
--dereference-command-line-symlink-to-dir
follow each command line symbolic link
that points to a directory
--hide=PATTERN do not list implied entries matching shell PATTERN
(overridden by -a or -A)
--indicator-style=WORD append indicator with style WORD to entry names:
none (default), slash (-p),
file-type (--file-type), classify (-F)
-i, --inode print the index number of each file
-I, --ignore=PATTERN do not list implied entries matching shell PATTERN
-k, --kibibytes default to 1024-byte blocks for disk usage
-l 使用较长格式列出信息
-L, --dereference 当显示符号链接的文件信息时,显示符号链接所指示
的对象而并非符号链接本身的信息
-m 所有项目以逗号分隔,并填满整行行宽
-n, --numeric-uid-gid 类似 -l,但列出UID 及GID 号
-N, --literal 输出未经处理的项目名称 (如不特别处理控制字符)
-o 类似 -l,但不列出有关组的信息
-p, --indicator-style=slash 对目录加上表示符号"/"
-q, --hide-control-chars print ? instead of nongraphic characters
--show-control-chars show nongraphic characters as-is (the default,
unless program is 'ls' and output is a terminal)
-Q, --quote-name enclose entry names in double quotes
--quoting-style=WORD use quoting style WORD for entry names:
literal, locale, shell, shell-always, c, escape
-r, --reverse 逆序排列
-R, --recursive 递归显示子目录
-s, --size 以块数形式显示每个文件分配的尺寸
-S sort by file size
--sort=WORD sort by WORD instead of name: none (-U), size (-S),
time (-t), version (-v), extension (-X)
--time=WORD with -l, show time as WORD instead of default
modification time: atime or access or use (-u)
ctime or status (-c); also use specified time
as sort key if --sort=time
--time-style=STYLE with -l, show times using style STYLE:
full-iso, long-iso, iso, locale, or +FORMAT;
FORMAT is interpreted like in 'date'; if FORMAT
is FORMAT1<newline>FORMAT2, then FORMAT1 applies
to non-recent files and FORMAT2 to recent files;
if STYLE is prefixed with 'posix-', STYLE
takes effect only outside the POSIX locale
-t sort by modification time, newest first
-T, --tabsize=COLS assume tab stops at each COLS instead of 8
-u with -lt: sort by, and show, access time;
with -l: show access time and sort by name;
otherwise: sort by access time
-U do not sort; list entries in directory order
-v natural sort of (version) numbers within text
-w, --width=COLS assume screen width instead of current value
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-1 list one file per line
SELinux options:
--lcontext Display security context. Enable -l. Lines
will probably be too wide for most displays.
-Z, --context Display security context so it fits on most
displays. Displays only mode, user, group,
security context and file name.
--scontext Display only security context and file name.
--help 显示此帮助信息并退出
--version 显示版本信息并退出
SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).
使用色彩来区分文件类型的功能已被禁用,默认设置和 --color=never 同时禁用了它。
使用 --color=auto 选项,ls 只在标准输出被连至终端时才生成颜色代码。
LS_COLORS 环境变量可改变此设置,可使用 dircolors 命令来设置。
退出状态:
0 正常
1 一般问题 (例如:无法访问子文件夹)
2 严重问题 (例如:无法使用命令行参数)
date
作用:查看Linux 系统当前日期、时间、时区
用法:date [选项]… [+格式]
或:date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]]l
[RBH@centos7 ~ 11:33:15]$ date -u
2026年 09月 02日 星期三 03:34:29 UTC
[RBH@centos7 ~ 11:34:29]$ date --utc
2026年 09月 02日 星期三 03:35:22 UTC
[RBH@centos7 ~ 11:35:22]$ date --universal
2026年 09月 02日 星期三 03:35:32 UTC

[RBH@centos7 ~ 11:37:31]$ date --date='@2147483647'
2038年 01月 19日 星期二 11:14:07 CST
[RBH@centos7 ~ 11:37:45]$ date --date='+100 days'
2026年 12月 11日 星期五 11:38:04 CST
[RBH@centos7 ~ 11:38:04]$ TZ='America/Los_Angeles' date
2026年 09月 01日 星期二 20:38:20 PDT
[RBH@centos7 ~ 11:38:20]$ TZ='Beijing' date
2026年 09月 02日 星期三 03:38:36 Beijing

附:
Mandatory arguments to long options are mandatory for short options too.
-d, --date=STRING display time described by STRING, not 'now'
-f, --file=DATEFILE like --date once for each line of DATEFILE
-I[TIMESPEC], --iso-8601[=TIMESPEC] output date/time in ISO 8601 format.
TIMESPEC='date' for date only (the default),
'hours', 'minutes', 'seconds', or 'ns' for date
and time to the indicated precision.
-r, --reference=文件 显示文件指定文件的最后修改时间
-R, --rfc-2822 以RFC 2822格式输出日期和时间
例如:2006年8月7日,星期一 12:34:56 -0600
--rfc-3339=TIMESPEC output date and time in RFC 3339 format.
TIMESPEC='date', 'seconds', or 'ns' for
date and time to the indicated precision.
Date and time components are separated by
a single space: 2006-08-07 12:34:56-06:00
-s, --set=STRING set time described by STRING
-u, --utc, --universal print or set Coordinated Universal Time (UTC)
--help 显示此帮助信息并退出
--version 显示版本信息并退出
给定的格式FORMAT 控制着输出,解释序列如下:
%% 一个文字的 %
%a 当前locale 的星期名缩写(例如: 日,代表星期日)
%A 当前locale 的星期名全称 (如:星期日)
%b 当前locale 的月名缩写 (如:一,代表一月)
%B 当前locale 的月名全称 (如:一月)
%c 当前locale 的日期和时间 (如:2005年3月3日 星期四 23:05:25)
%C 世纪;比如 %Y,通常为省略当前年份的后两位数字(例如:20)
%d 按月计的日期(例如:01)
%D 按月计的日期;等于%m/%d/%y
%e 按月计的日期,添加空格,等于%_d
%F 完整日期格式,等价于 %Y-%m-%d
%g ISO-8601 格式年份的最后两位 (参见%G)
%G ISO-8601 格式年份 (参见%V),一般只和 %V 结合使用
%h 等于%b
%H 小时(00-23)
%I 小时(00-12)
%j 按年计的日期(001-366)
%k hour, space padded ( 0..23); same as %_H
%l hour, space padded ( 1..12); same as %_I
%m month (01..12)
%M minute (00..59)
%n 换行
%N 纳秒(000000000-999999999)
%p 当前locale 下的"上午"或者"下午",未知时输出为空
%P 与%p 类似,但是输出小写字母
%r 当前locale 下的 12 小时时钟时间 (如:11:11:04 下午)
%R 24 小时时间的时和分,等价于 %H:%M
%s 自UTC 时间 1970-01-01 00:00:00 以来所经过的秒数
%S 秒(00-60)
%t 输出制表符 Tab
%T 时间,等于%H:%M:%S
%u 星期,1 代表星期一
%U 一年中的第几周,以周日为每星期第一天(00-53)
%V ISO-8601 格式规范下的一年中第几周,以周一为每星期第一天(01-53)
%w 一星期中的第几日(0-6),0 代表周一
%W 一年中的第几周,以周一为每星期第一天(00-53)
%x 当前locale 下的日期描述 (如:12/31/99)
%X 当前locale 下的时间描述 (如:23:13:48)
%y 年份最后两位数位 (00-99)
%Y 年份
%z +hhmm 数字时区(例如,-0400)
%:z +hh:mm 数字时区(例如,-04:00)
%::z +hh:mm:ss 数字时区(例如,-04:00:00)
%:::z 数字时区带有必要的精度 (例如,-04,+05:30)
%Z 按字母表排序的时区缩写 (例如,EDT)
默认情况下,日期的数字区域以0 填充。
The following optional flags may follow '%':
- (hyphen) do not pad the field
_ (underscore) pad with spaces
0 (zero) pad with zeros
^ use upper case if possible
# use opposite case if possible
在任何标记之后还允许一个可选的域宽度指定,它是一个十进制数字。
作为一个可选的修饰声明,它可以是E,在可能的情况下使用本地环境关联的
表示方式;或者是O,在可能的情况下使用本地环境关联的数字符号。
Examples:
Convert seconds since the epoch (1970-01-01 UTC) to a date
$ date --date='@2147483647'
Show the time on the west coast of the US (use tzselect(1) to find TZ)
$ TZ='America/Los_Angeles' date
Show the local time for 9AM next Friday on the west coast of the US
$ date --date='TZ="America/Los_Angeles" 09:00 next Fri'
bash 执行命令
passwd
作用:管理用户密码。
用法: passwd [选项…] <帐号名称>
passwd

#提升为管理员权限 su -l root
[RBH@centos7 ~ 17:03:32]$ su -l root
#更改用户的密码 passwd + 用户名
[root@centos7 ~ 17:04:24]# passwd RBH

#清除用户的密码 passwd -d + 用户名
[root@centos7 ~ 17:05:05]# passwd -d RBH
清除用户的密码 RBH。
passwd: 操作成功
# 锁定用户密码,用户将无法登录 passwd -l + 用户名
[root@centos7 ~ 17:07:46]# passwd -l RBH
锁定用户 RBH 的密码 。
passwd: 操作成功
# 解锁用户密码,用户可以正常登录 passwd -u + 用户名
[root@centos7 ~ 17:09:13]# passwd -u RBH
解锁用户 RBH 的密码。
passwd: 操作成功
附:
用法: passwd [选项...] <帐号名称>
-k, --keep-tokens 保持身份验证令牌不过期
-d, --delete 删除已命名帐号的密码(只有根用户才能进行此操作)
-l, --lock 锁定指名帐户的密码(仅限 root 用户)
-u, --unlock 解锁指名账户的密码(仅限 root 用户)
-e, --expire 终止指名帐户的密码(仅限 root 用户)
-f, --force 强制执行操作
-x, --maximum=DAYS 密码的最长有效时限(只有根用户才能进行此操作)
-n, --minimum=DAYS 密码的最短有效时限(只有根用户才能进行此操作)
-w, --warning=DAYS 在密码过期前多少天开始提醒用户(只有根用户才能进行此操作)
-i, --inactive=DAYS 当密码过期后经过多少天该帐号会被禁用(只有根用户才能进行此操作)
-S, --status 报告已命名帐号的密码状态(只有根用户才能进行此操作)
--stdin 从标准输入读取令牌(只有根用户才能进行此操作)
Help options:
-?, --help Show this help message
--usage Display brief usage message
file
作用:判定文件类型。
用法:file [OPTION…] [FILE…]
[RBH@centos7 ~ 14:18:49]$ file /etc
/etc: directory

--help display this help and exit
-v, --version output version information and exit
-m, --magic-file LIST use LIST as a colon-separated list of magic
number files
-z, --uncompress try to look inside compressed files
-b, --brief do not prepend filenames to output lines
-c, --checking-printout print the parsed form of the magic file, use in
conjunction with -m to debug a new magic file
before installing it
-e, --exclude TEST exclude TEST from the list of test to be
performed for file. Valid tests are:
ascii, apptype, compress, elf, soft, tar, tokens, troff
-f, --files-from FILE read the filenames to be examined from FILE
-F, --separator STRING use string as separator instead of `:'
-i, --mime output MIME type strings (--mime-type and
--mime-encoding)
--apple output the Apple CREATOR/TYPE
--mime-type output the MIME type
--mime-encoding output the MIME encoding
-k, --keep-going don't stop at the first match
-l, --list list magic strength
-L, --dereference follow symlinks (default)
-h, --no-dereference don't follow symlinks
-n, --no-buffer do not buffer output
-N, --no-pad do not pad output
-0, --print0 terminate filenames with ASCII NUL
-p, --preserve-date preserve access times on files
-r, --raw don't translate unprintable chars to \ooo
-s, --special-files treat special (block/char devices) files as
ordinary ones
-C, --compile compile file specified by -m
-d, --debug print debugging messages
cat
作用:一次性读取文件内容,将[文件]或标准输入组合输出到标准输出。
用法:cat [选项]… [文件]…
[RBH@CentOS7 ~]$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.1.8.88 CentOS7.redhat.fun CentOS7
# -A选项等于-vET,用于显示行尾加个$,用^I显示制表符(tab键)
[RBH@CentOS7 ~]$ cat -A /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4$
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6$
10.1.8.88^ICentOS7.redhat.fun^ICentOS7$
# 一次性查看多个文件
[RBH@CentOS7 ~]$ cat /etc/hosts /etc/fstab
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.1.8.88 CentOS7.redhat.fun CentOS7
#
# /etc/fstab
# Created by anaconda on Wed Nov 2 17:31:41 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=047729d6-683f-4aec-b614-28d20ce0a90c /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
附:
-A, --show-all 等于-vET
-b, --number-nonblank 对非空输出行编号
-e 等于-vE
-E, --show-ends 在每行结束处显示"$"
-n, --number 对输出的所有行编号
-s, --squeeze-blank 不输出多行空行
-t 与-vT 等价
-T, --show-tabs 将跳格字符显示为^I
-u (被忽略)
-v, --show-nonprinting 使用^ 和M- 引用,除了LFD和 TAB 之外
--help 显示此帮助信息并退出
--version 显示版本信息并退出
如果没有指定文件,或者文件为"-",则从标准输入读取。
示例:
cat f - g 先输出f 的内容,然后输出标准输入的内容,最后输出g 的内容。
cat 将标准输入的内容复制到标准输出。
head
作用:显示文件头部内容。
用法:head [选项]… [文件]…
[root@centos7 ~ 14:58:35]# head /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
[root@centos7 ~ 14:58:53]# head /etc/profile | cat -n
1 # /etc/profile
2
3 # System wide environment and startup programs, for login setup
4 # Functions and aliases go in /etc/bashrc
5
6 # It's NOT a good idea to change this file unless you know what you
7 # are doing. It's much better to create a custom.sh shell script in
8 # /etc/profile.d/ to make custom changes to your environment, as this
9 # will prevent the need for merging in future updates.
10
[root@centos7 ~ 14:59:10]# head -n 4 /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
[root@centos7 ~ 15:00:16]# head -c 5 /etc/profile
# /et[root@centos7 ~ 15:00:35]# tail /etc/profile
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
[root@centos7 ~ 15:00:40]# head -n 15 /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
[root@centos7 ~ 15:00:49]# head -n 15 /etc/profile | tail -n 5
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
[root@centos7 ~ 15:01:31]# cat -n /etc/profile | tail -n +11 |head -n 5
11 pathmunge () {
12 case ":${PATH}:" in
13 *:"$1":*)
14 ;;
15 *)
附:
-c, --bytes=[-]K print the first K bytes of each file;
with the leading '-', print all but the last
K bytes of each file
-n, --lines=[-]K print the first K lines instead of the first 10;
with the leading '-', print all but the last
K lines of each file
-q, --quiet, --silent 不显示包含给定文件名的文件头
-v, --verbose 总是显示包含给定文件名的文件头
--help 显示此帮助信息并退出
--version 显示版本信息并退出
K 后面可以跟乘号:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, 对于T, P, E, Z, Y 同样适用。
tail
作用:显示文件尾部内容。
用法:head [选项]… [文件]…
同head。
附:
-c, --bytes=K output the last K bytes; or use -c +K to output
bytes starting with the Kth of each file
-f, --follow[={name|descriptor}]
output appended data as the file grows;
an absent option argument means 'descriptor'
-F same as --follow=name --retry
-n, --lines=K output the last K lines, instead of the last 10;
or use -n +K to output starting with the Kth
--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not
changed size after N (default 5) iterations
to see if it has been unlinked or renamed
(this is the usual case of rotated log files);
with inotify, this option is rarely useful
--pid=PID with -f, terminate after process ID, PID dies
-q, --quiet, --silent never output headers giving file names
--retry keep trying to open a file if it is inaccessible
-s, --sleep-interval=N with -f, sleep for approximately N seconds
(default 1.0) between iterations;
with inotify and --pid=P, check process P at
least once every N seconds
-v, --verbose always output headers giving file names
--help 显示此帮助信息并退出
--version 显示版本信息并退出
less
作用:交互式、翻页查看文件内容。
# 使用less查看多页文档,可以翻页,搜索等
[RBH@CentOS7 ~]$ less -N /etc/profile
# 在less查看文件过程中常见指令:
# / 搜索,n(next)搜索下一个,N搜索上一个。
# 上下方向键 逐行查看,左右键左右翻页
# pageup和pagedown 上下翻页
# q,退出文档查看

wc
作用:统计文件行数、单词数、字节数。
用法:wc [选项]… [文件]…
或:wc [选项]… --files0-from=F
-c, --bytes print the byte counts
-m, --chars print the character counts
-l, --lines print the newline counts
--files0-from=文件 从指定文件读取以NUL 终止的名称,如果该文件被
指定为"-"则从标准输入读文件名
-L, --max-line-length 显示最长行的长度
-w, --words 显示单词计数
--help 显示此帮助信息并退出
--version 显示版本信息并退出
tab 按键
补全功能:补全命令、补全选项、补全参数
# tab 一次,就出结果,说明匹配结果
# tab 两次,才补全出结果,说明匹配结果不唯一
# 可以补全命令、补全选项、补全参数
history命令
作用:显示或操纵历史列表。
用法:history [-c] [-d 偏移量] [n] 或 history -anrw [文件名] 或 history -ps 参数 [参数…]
# history命令查看帮助不能使用 history --help
[RBH@centos7 ~]$ history --help
-bash: history: --: 无效选项
带行号显示历史列表,将每个被修改的条目加上前缀 `*'。
参数 N 会仅列出最后的 N 个条目。
选项:
-c 删除所有条目从而清空历史列表。
-d 偏移量 从指定位置删除历史列表。
-a 将当前绘画的历史行追加到历史文件中
-n 从历史文件中读取所有未被读取的行
-r 读取历史文件并将内容追加到历史列表中
-w 将当前历史写入到历史文件中,并追加到历史列表中
-p 对每一个 ARG 参数展开历史并显示结果,而不存储到历史列表中
-s 以单条记录追加 ARG 到历史列表中
如果给定了 FILENAME 文件名,则它将被作为历史文件。否则
如果 $HISTFILE 变量有值的话使用之,不然使用 ~/.bash_history 文件。
如果 $HISTTIMEFORMAT 变量被设定并且不为空,它的值会被用于
strftime(3) 的格式字符串来打印与每一个显示的历史条目想关联的时
间戳,否则不打印时间戳。
退出状态:
返回成功,除非使用了无效的选项或者发生错误。
script命令
作用:录制终端里所有敲过的命令与屏幕输出结果,保存成日志文件。
用法:script [选项] [文件]
#开始录制
[root@centos7 ~ 15:50:12]# script --timing=time.log operator.log
Script started, file is operator.log
……
Script done, file is operator.log
#查看录制
[root@centos7 ~ 15:52:59]# scriptreplay -t time.log operator.log

bash快捷键
| 快捷键 | 作用 |
|---|---|
| Ctrl+a 或者 Home | 光标定位到命令行开头 |
| Ctrl+e 或者 End | 光标定位到命令行末尾 |
| Ctrl+u | 删除光标位置到命令行开头 |
| Ctrl+k | 删除光标位置到命令行末尾 |
| Ctrl+<- | 光标向左跳转一个单词 |
| Ctrl±> | 光标向右跳转一个单词 |
| Ctrl+r | 搜索历史命令 |
| Ctrl+w | 向左删除一个参数 |
| Esc(松开)+. | 打印上一个命令的最后一个参数 |
| Ctrl+l(L的小写) | 清空屏幕 |
| Ctrl+d | 登出终端 |
,全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构
更多推荐


所有评论(0)