复盘Linux期末考试【已凉凉】

🏡 博客首页:派 大 星

🍎 root创建用户

useradd 用户名

passwd 密码

🍓 Shell脚本的编写

🍇 什么是Shell脚本

shell脚本是一种解释性语言,用shell脚本保存执行动作;用脚本判断命令的执行条件;用脚本来实现操作的批量执行。

🥑 如何创建shell脚本

🌶 脚本的编写

    使用vi 建立一个hello.sh 保存文件:wq 给文件赋予可执行权限 sh xxx.sh
[root@localhost]# vi hello.sh
## 以下是编写shell脚本内容
#! /bin/bash
watch -n 1 date ## 执行程序时间

## 下面是执行脚本程序的命令
## 方式一:
[root@localhost]# sh hello.sh

## 方式二:
[root@localhost]# chmod +x hello.sh   加可执行权限
[root@localhost]# /mnt/hello.sh   绝对路径的方式执行

执行脚本结果如下:

🍒 脚本调试

首先编辑shell脚本:

#! /bin/bash -x
echo  hello pdx

执行测试结果如下:

脚本示例:编辑shell脚本显示IP

[root@localhost]# vi ip_show.sh  编辑脚本显示

#####################################
# Author : pdx											#
# Mail : pdx_jie@163.com						#
# Version : 1.0											#
# Description : 										#
#																		#
#																		#
#####################################

#! /bin/bash
ifconfig eth0 |awk -F "" /inet/{print $2} #显示IP

执行脚本测试:sh ip_show.sh

这里报错的原因是因为我没有配置网卡,所以显示Device not fount

🥝 Diff 指令比较两文件的不同

diff在比较文件过程中结果 读取方式

[num1,num2]a|c|d[num3,num4]
num1,num2 表示在第一个文件的行数
a表示添加:add
c表示更改:change
d表示删除:delete
num3,num4表示在第二个文件中的行数

示例:

[root@localhost]# cd /mnt     进入目录建立文件
[root@localhost]# vi hello1  建立文件hello1并写入内容123
[root@localhost]# vi hello2  建立文件hello2并写入内容123 456
使用diff指令比较两个文件的不同:表示第一个文件的第二行在加上456就和第二个文件一样

🥦 find指令查找

参数:
-type          类型
-size          大小
-perm          权限
-user          拥有着
-group         所有组
-name          名字
-mindepth      最小深度
-maxdepth      最大深度

测试示例:

[root@localhost]# find /mnt/ -type l          查找/mnt/的连接的文件
[root@localhost]# find /mnt/ -group student   查找/mnt/的student组的文件
[root@localhost]# find  /mnt/ -user root -a  -group student   
[root@localhost]# 查找/mnt/的文件是root用户并且是student组的文件
[root@localhost]# find  /mnt/ -user root -o  -group student   
查找/mnt/的文件是root用户或者是student组的文件

期末考试结束,我在这里宣布Linux课程凉凉

经验分享 程序员 微信小程序 职场和发展