[root@localhost ~]$ w
08:30:47 up 1:37, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty2 tty2 06:54 1:37m 41.83s 0.23s /usr/libexec/tracker-miner-fs
[root@localhost ~]$ who
root tty2 2021-01-14 06:54 (tty2)#登录用户名 终端设备 登录到系统的时间
2.4.6 last
功能:查看主机的被访记录,很容易被篡改;
示例:
[root@localhost ~]$ last
root tty2 tty2 Thu Jan 14 06:54 still logged inreboot system boot 4.18.0-80.el8.x8 Thu Jan 14 06:53 still running
root tty2 tty2 Wed Jan 13 22:16 - crash (08:37)...
[root@localhost ~]$ history
1 ls
2 vim anaconda-ks.cfg
3 cd /etc/sysconfig/network-scripts/
4 ls
5 vim ifcfg-ens160
6 mkdir -p test
7 cdtest
8 ls
9 vim shtest.sh
10 ls
11 bash shtest.sh
12 echo[ -d shtest.sh ][root@localhost ~]$ history -c # 清空历史[root@localhost ~]$ history
1 history
2.4.8 sosreport
功能:用于收集系统配置及架构信息并输出诊断文档,不断回车执行即可;
2.4.9 ping
功能:测试主机之间的网络连通性;
格式:ping [参数] 主机地址
参数
作用
-c
总共发送次数
-l(小写L)
指定网卡名称(Lan)
-i
每次间隔时间(秒)
-W
最长等待时间(秒)
示例:
[root@localhost ~]$ ping -c 4 192.168.10.10
2.5 工作目录切换命令
2.5.1 pwd
功能:显示用户当前所处的工作目录;
示例:
[root@localhost ~]$ pwd
/root
2.5.2 cd
功能:切换当前的工作路径;
格式:cd [参数]目录
示例:
[root@localhost ~]$ cd - # 返回上次目录[root@localhost ~]$ cd..# 返回上级目录[root@localhost ~]$ cd ~ # 切至家目录[root@localhost ~]$ cd ~username # 切至其他用户家目录
2.5.3 ls
功能:显示目录中的文件信息;
格式:ls [参数]文件名称
-a 全部文件 -l 显示文件属性 以 . 开头的文件是隐藏文件,白字:文件,蓝字:文件夹/目录文件;红字:压缩包。
示例:
[root@localhost ~]$ alias ll # ll是别名alias ll='ls -l --color=auto'[root@localhost ~]$ ll # 从上面可以看出,ll其实和 ls -l是一样的
total 6184
-rw-------. 1 root root 1395 Jan 9 01:00 anaconda-ks.cfg
-rw-r--r--. 1 root root 6316925 Jan 10 03:32 backup.tar.gz
drwxr-xr-x. 2 root root 6 Jan 9 01:22 Desktop
...
[root@localhost ~]$ ls -ld /etc # 查看单个目录权限,"-ld"要连用
drwxr-xr-x. 135 root root 8192 Jan 10 04:10 /etc/
[root@localhost ~]$ ls -al
total 6236
dr-xr-x---. 15 root root 4096 Jan 14 06:54 .
dr-xr-xr-x. 17 root root 224 Jan 9 00:49 ..
2.6 文本文件编辑命令
2.6.1 cat
功能:查看纯文本文件(内容较少的);
格式:cat [参数]文件名称
示例:
[root@localhost ~]$ cat -n initial-setup-ks.cfg # -n 显示行号
1 #version=RHEL8
2 # X Window System configuration information
3 xconfig --startxonboot
4 # License agreement
5 eula --agreed
6 # Use graphical install
7 graphical
2.6.2 more
功能:查看纯文本文件(内容较多的),回车下一行,空格下一页;
格式:more [参数] 文件名称
示例:
[root@localhost ~]$ more initial-setup-ks.cfg
#version=RHEL8# X Window System configuration information
xconfig --startxonboot
# License agreement...
2.6.3 head
功能:查看纯文本文件的前N行;
格式:head [参数] 文件名称
示例:
[root@linuxprobe ~]$ head -n 6 initial-setup-ks.cfg # 查看前6行的文本#version=RHEL8# X Window System configuration information
xconfig --startxonboot
# License agreement
eula --agreed
# Use graphical install
[root@localhost ~]$ dd if=/dev/zero of=test_file count=1 bs=100M #bs默认是B
1+0 records in
1+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.411219 s, 255 MB/s # 可以用来测试硬盘速度#可以使用dd命令来压制出镜像文件[root@linuxprobe ~]$ dd if=/dev/cdrom of=RHEL-server-8.0-x86_64-LinuxProbe.Com.iso
13873152+0 records in
13873152+0 records out
7103053824 bytes (7.1 GB, 6.6 GiB) copied, 27.8812 s, 255 MB/s
2.7.7 file
功能:查看文件的类型(Linux中一切皆文件);
格式:file 文件名称
示例:
[root@localhost ~]$ file a
a: directory
2.8 打包压缩与搜索命令
rhel考题
2.8.1 tar
功能:对文件进行打包压缩或解压;
格式:tar 参数 文件名称
作用
参数
创建压缩文件
-c
解开压缩文件
-x
查看压缩包内有哪些文件
-t
用Gzip压缩或解压
-z
用bzip2压缩或解压
-j
显示压缩或解压的过程
-v
目标文件名
-f
保留原始的权限与属性
-p
使用绝对路径来压缩
-P
指定解压到的目录
-C
z :gzip压缩, 常用命名为xxxx.tar.gz j :bzip2压缩,常用命令为xxxx.tar.bz2 压缩和解压时,参数的 “-” 可以省略
示例:
# 将a目录文件采用Gzip压缩,显示过程,压缩成文件test.tar.gz[root@localhost ~]$ tar -czvf test.tar.gz a # f 需要在最后一位,用来连接目标文件名# 将目标文件test.tar.gz采用Gzip解压缩,指定解压目录为当前路径a目录下[root@localhost ~]$ tar xzvf test.tar.gz -C a