当前位置: 代码迷 >> 综合 >> 20201009 学习Linux 8 心路历程
  详细解决方案

20201009 学习Linux 8 心路历程

热度:52   发布时间:2024-02-26 22:30:58.0

10.history命令

history命令用于显示执行过的命令历史,语法格式为:“history [-c]”。

history命令应该是运维人员最喜欢的命令。执行history命令能显示出当前用户在本地计算机中执行过的最近1000条命令记录。如果觉得1000不够用,可以自定义/etc/profile文件中的HISTSIZE变量值。在使用history命令时,可以使用-c参数清空所有的命令历史记录。还可以使用“!编码数字”的方式来重复执行某一次的命令。总之,history命令有很多有趣的玩法等待您去开发。

[root@linuxprobe ~]# history
1 ifconfig
2 uname -a
3 cat /etc/redhat-release
4 uptime
5 free -h
6 who
7 last
8 ping -c 192.168.10.10
9 ping -c 192.168.10.20
10 tracepath www.linuxprobe.com
11 netstat -a
12 netstat -i
13 history
[root@linuxprobe ~]# !3
cat /etc/redhat-release
Red Hat Enterprise Linux release 8.0 (Ootpa)
历史命令会被保存到用户家目录中的.bash_history文件中。Linux系统中以点(.)开头的文件均代表隐藏文件,这些文件大多数为系统服务文件,可以用cat命令查看其文件内容:

[root@linuxprobe ~]# cat ~/.bash_history
要清空当前用户在本机上执行的Linux命令历史记录信息,可执行如下命令:

[root@linuxprobe ~]# history -c
11.sosreport命令

sosreport命令用于收集系统配置及架构信息并输出诊断文档,输入后回车执行即可。

当Linux系统出现故障需要联系技术支持人员时,大多数时候都要先使用这个命令来简单收集系统的运行状态和服务配置信息,以便让技术支持人员能够远程解决一些小问题,亦或让他们能提前了解某些复杂问题。

在下面的输出信息中,加粗的部分是收集好的资料压缩文件以及校验码,将其发送给技术支持人员:

[root@linuxprobe ~]# sosreport
sosreport (version 3.6)
This command will collect diagnostic and configuration information from
this Red Hat Enterprise Linux system and installed applications.

An archive containing the collected information will be generated in
/var/tmp/sos.9_i0glu8 and may be provided to a Red Hat support
representative.

Any information provided to Red Hat will be treated in accordance with
the published support policies at:
https://access.redhat.com/support/
The generated archive may contain data considered sensitive and its
content should be reviewed by the originating organization before being
passed to any third party.

No changes will be made to system configuration.
Press ENTER to continue, or CTRL-C to quit.
此处按下回车键进行确认
Please enter the case id that you are generating this report for []:此处按下回车键进行确认
Setting up archive …
Setting up plugins …
Running plugins. Please wait …
………………省略部分输出信息………………
Finished running plugins
Creating compressed archive…

Your sosreport has been generated and saved in:
/var/tmp/sosreport-linuxprobe.com-2021-05-18-jnkaspu.tar.xz

The checksum is: 9fbecbd167b7e5836db1ff8f068c4db3
Please send this file to your support representative.
Tips
sosreport命令有点像是远程问诊,假如今天有点咳嗽发烧不舒服,可以先从网上搜索一下,如果仅仅是感冒的话就多喝水就行,免去了到医院挂号看病的车马劳顿,而如果远程问诊怀疑出了大毛病,再请专业人员进行处理也不迟。
2.5 查找定位文件命令

工作目录指的是用户当前在系统中所处的位置,由于工作目录会牵涉系统存储结构相关的知识,因此第6章会再详细讲解这部分内容。读者只需简单了解一下这里的操作实验即可,如果不能完全掌握也没有关系,毕竟Linux系统的知识体系太过庞大,每一位初学人员都需要经历这么一段时期。

1.pwd命令

pwd命令用于显示用户当前所处的工作目录,英文全称为:“print working directory”,输入后回车执行即可。

查看当前所处的工作目录:

[root@linuxprobe etc]# pwd
/etc
2.cd命令

在这里插入图片描述