shell文本处理工具-shell三剑客

news2025/1/10 3:28:55

shell脚本常用基础命令2


shell脚本常用基础命令

  • shell脚本常用基础命令2
  • 一、grep用法
  • 二、sed用法
    • 2.1p参数 (显示)n参数(只显示处理过的行)
  • shell脚本常用基础命令2
  • 一、grep用法
  • 二、sed用法
    • 2.1p参数 (显示)n参数(只显示处理过的行)


文本处理三剑客:grep sed awk

一、grep用法

grep -E = egrep (扩展搜索正文表达式)
grep格式
grep 匹配条件 处理文件(很多正文表达式用不了) |表示或者

[root@docker3 mnt]# grep "bash|root" passwd 
[root@docker3 mnt]# egrep "bash|root" passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
operator:x:11:0:operator:/root:/sbin/nologin
yan:x:1000:1000::/home/yan:/bin/bash
[root@docker3 mnt]# grep -E "bash|root" passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
operator:x:11:0:operator:/root:/sbin/nologin
yan:x:1000:1000::/home/yan:/bin/bash
[root@docker3 mnt]# grep -e bash -e root passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
operator:x:11:0:operator:/root:/sbin/nologin
yan:x:1000:1000::/home/yan:/bin/bash

grep开启的是贪婪模式,要是不匹配前面的<,不匹配后面>

[root@docker3 mnt]# grep -E "root" passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
chroot
rootch
[root@docker3 mnt]# grep -E "\<root" passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
rootch
operator:x:11:0:operator:/root:/sbin/nologin
[root@docker3 mnt]# grep -E "\<root\>" passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
operator:x:11:0:operator:/root:/sbin/nologin

grep 前面加数字,表示该关键字前面后面几行都显示出来

[root@docker3 mnt]# grep chroot passwd 
chroot
[root@docker3 mnt]# grep -2 chroot passwd 
test:root:test
TEST:ROOT:TEST
chroot
rootch
operator:x:11:0:operator:/root:/sbin/nologin
[root@docker3 mnt]# grep -A2 chroot passwd 
chroot
rootch
operator:x:11:0:operator:/root:/sbin/nologin
[root@docker3 mnt]# grep -B2 chroot passwd 
test:root:test
TEST:ROOT:TEST
chroot

显示匹配的在第几行

[root@docker3 mnt]# grep -n chroot passwd 
12:chroot

反向过滤,除了chroot其它行都过滤出来,展示部分。

[root@docker3 mnt]# grep -v chroot passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
yan:x:1000:1000::/home/yan:/bin/bash

以^…开头,…¥以…结尾

[root@docker3 mnt]# grep -E "^root" passwd 
root:x:0:0:root:/root:/bin/bash
rootch
[root@docker3 mnt]# grep -E "bash$" passwd 
root:x:0:0:root:/root:/bin/bash
yan:x:1000:1000::/home/yan:/bin/bash
[root@docker3 mnt]# grep -E "ws" yan
ws
[root@docker3 mnt]# grep -E "w.s" yan
was
[root@docker3 mnt]# grep -E "w...s" yan
waaas
[root@docker3 mnt]# grep -E "w.*s" yan
ws
was
waaas
waaaas
waaaaas
wabababs
[root@docker3 mnt]# grep -E "w.?s" yan
ws
was
[root@docker3 mnt]# grep -E "w.+s" yan
was
waaas
waaaas
waaaaas
wabababs
[root@docker3 mnt]# grep -E "w.{3}s" yan
waaas
[root@docker3 mnt]# grep -E "w.{2,3}s" yan
waaas
[root@docker3 mnt]# grep -E "w.{,3}s" yan
ws
was
waaas
[root@docker3 mnt]# grep -E "w.{3,}s" yan
waaas
waaaas
waaaaas
wabababs
[root@docker3 mnt]# grep -E "wab{1,}s" yan
[root@docker3 mnt]# grep -E "w(ab){1,}s" yan
wabababs

脚本
请显示系统中能被su命令切换的用户名称
在这里插入图片描述

[root@docker3 mnt]# sh user_check.sh 
root
yan

二、sed用法

用来对文本的内容进行处理,修改的是模式空间(内存),真实的(磁盘中)
sed 参数 命令 处理对象
sed 参数 处理对象 -f 处理规则文件

对字符的处理
p 显示
d 删除
a 添加
n 取消默认输出,sed默认会输出所有文本内容,使用-n参数后只显示处理过的行
i 插入,直接修改文件内容
c 替换
w 写入
r 整合文件

2.1p参数 (显示)n参数(只显示处理过的行)

[root@docker3 mnt]# sed -n 5p passwd 
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@docker3 mnt]# vim rule
[root@docker3 mnt]# cat rule 
5p
[root@docker3 mnt]# sed -n -f rule passwd 
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@docker3 mnt]# sed  '5p' fstab 
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed  -n '5p' fstab 
#5
[root@docker3 mnt]# sed  -n '3,5p' fstab 
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
[root@docker3 mnt]# sed  -n '3p;5p' fstab 
# /etc/fstab3
#5

#开头的行以及不是#开头的行

[root@docker3 mnt]# sed -n '/^#/p' fstab 
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
[root@docker3 mnt]# sed -n '/^#/!p' fstab 
1
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

^$空行

[root@docker3 mnt]# sed -n '/^#/!p' fstab | sed -n '/^$/!p'
1
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

最后一行$p

[root@docker3 mnt]# sed -n '$p' fstab
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed -n '5,$p' fstab
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

显示行号,‘=’, '$='最后一行的行号(可以统计文件有多少行)

[root@docker3 mnt]# sed -n '$=' fstab 
11
[root@docker3 mnt]# sed -n -e '3p' -e '5p' fstab 
# /etc/fstab3
#5

d参数删除

[root@docker3 mnt]# sed 5d fstab 
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed '3,5d' fstab 
1
#2
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed '3d;5d' fstab 
1
#2
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed '/^#/d' fstab 
1
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

a参数添加

[root@docker3 mnt]# sed '/^#/ahello' fstab 
1
#2
hello
# /etc/fstab3
hello
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
hello
#5
hello
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
hello
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
hello
#8
hello
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

最后一行后面添加

[root@docker3 mnt]# sed '$ahello' fstab 
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
hello
[root@docker3 mnt]# sed '$ahello\nyan' fstab 
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
hello
yan

i参数插入 i是在最后一行前面,a是添加到最后一行

[root@docker3 mnt]# sed '$ihello\nyan' fstab 
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
hello
yan
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed '1ihello\nyan' fstab 
hello
yan
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

c参数替换

[root@docker3 mnt]# sed '/^#/chello' fstab 
1
hello
hello
hello
hello
hello
hello
hello
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

w参数写入

[root@docker3 mnt]# sed '/^#/w file ' fstab 
[root@docker3 mnt]# cat file\  
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
就是
[root@docker3 mnt]# sed -n '/^#/p' fstab > file
[root@docker3 mnt]# cat file
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8

r

[root@docker3 mnt]# cat yan
1
2
3
[root@docker3 mnt]# cat yan1
4
5
6
[root@docker3 mnt]# cat yan yan1
1
2
3
4
5
6
[root@docker3 mnt]# cat yan yan1 > file

倒叙

[root@docker3 mnt]# tac yan
3
2
1
[root@docker3 mnt]# tac yan yan1
3
2
1
6
5
4
[root@docker3 mnt]# tac yan1 yan
6
5
4
3
2
1

cat tac无法把文件yan1整合到数字1后面,可以正序也可以倒序
1r第一行后面

[root@docker3 mnt]# sed '1ryan1' yan
1
4
5
6
2
3

整合到某关键字后面

[root@docker3 mnt]# sed '/2/ryan1' yan
1
2
4
5
6
3

更改到原文件

[root@docker3 mnt]# sed '/2/ryan1' -i yan
[root@docker3 mnt]# cat yan
1
2
4
5
6
3

脚本
Apache_port.sh
此脚本接入数字
http的端口就改为此数字
假设selinux为关闭状态
在这里插入图片描述

[root@docker3 mnt]# sh Apacha_port.sh 
Error: Please input port number following script!!!
[root@docker3 mnt]# sh Apacha_port.sh 80
Error:Apache is not installed!!

双引号不能被引用变量,单引号会注释变量,所以Listen注意是要双引号
在这里插入图片描述

[root@docker3 mnt]# sh Apacha_port.sh 8080
[root@docker3 mnt]# netstat -antlp | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      4140/httpd       
[root@docker3 mnt]# sh Apacha_port.sh 80
[root@docker3 mnt]# netstat -antlp | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      4172/httpd          

sed字符替换
s是全文的行,g全文的列
部分展示 /表示分割符

[root@docker3 mnt]# sed 's/sbin/hello/g' passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/hello/nologin
daemon:x:2:2:daemon:/hello:/hello/nologin
adm:x:3:4:adm:/var/adm:/hello/nologin
lp:x:4:7:lp:/var/spool/lpd:/hello/nologin
sync:x:5:0:sync:/hello:/bin/sync
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/hello/nologin
postfix:x:89:89::/var/spool/postfix:/hello/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/hello/nologin
yan:x:1000:1000::/home/yan:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/hello/nologin
[root@docker3 mnt]# sed 's/:/  /g' passwd 
root  x  0  0  root  /root  /bin/bash
bin  x  1  1  bin  /bin  /sbin/nologin
daemon  x  2  2  daemon  /sbin  /sbin/nologin
adm  x  3  4  adm  /var/adm  /sbin/nologin
lp  x  4  7  lp  /var/spool/lpd  /sbin/nologin
sync  x  5  0  sync  /sbin  /bin/sync
shutdown  x  6  0  shutdown  /sbin  /sbin/shutdown
halt  x  7  0  halt  /sbin  /sbin/halt
mail  x  8  12  mail  /var/spool/mail  /sbin/nologin
operator  x  11  0  operator  /root  /sbin/nologin
games  x  12  100  games  /usr/games  /sbin/nologin
[root@docker3 mnt]# sed 's/:/  /' passwd 
root  x:0:0:root:/root:/bin/bash
bin  x:1:1:bin:/bin:/sbin/nologin
daemon  x:2:2:daemon:/sbin:/sbin/nologin
adm  x:3:4:adm:/var/adm:/sbin/nologin
lp  x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync  x:5:0:sync:/sbin:/bin/sync
shutdown  x:6:0:shutdown:/sbin:/sbin/shutdown
[root@docker3 mnt]# sed '1,5s/:/  /' passwd 
root  x:0:0:root:/root:/bin/bash
bin  x:1:1:bin:/bin:/sbin/nologin
daemon  x:2:2:daemon:/sbin:/sbin/nologin
adm  x:3:4:adm:/var/adm:/sbin/nologin
lp  x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
[root@docker3 mnt]# sed '/lp/,/halt/s/:/  /g' passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp  x  4  7  lp  /var/spool/lpd  /sbin/nologin
sync  x  5  0  sync  /sbin  /bin/sync
shutdown  x  6  0  shutdown  /sbin  /sbin/shutdown
halt  x  7  0  halt  /sbin  /sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin

最后一行

[root@docker3 mnt]# sed '$s/:/  /g' passwd 
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
yan:x:1000:1000::/home/yan:/bin/bash
apache  x  48  48  Apache  /usr/share/httpd  /sbin/nologin
[root@docker3 mnt]# sed '$s/:/  /g;s/sbin/hello/g'  passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/hello/nologin
daemon:x:2:2:daemon:/hello:/hello/nologin
adm:x:3:4:adm:/var/adm:/hello/nologin
lp:x:4:7:lp:/var/spool/lpd:/hello/nologin
sync:x:5:0:sync:/hello:/bin/sync
shutdown:x:6:0:shutdown:/hello:/hello/shutdown

替换/,/需要转义,因为它是分割符

[root@docker3 mnt]# sed 's/:/  /g;s/\//##/g'  passwd 
root  x  0  0  root  ##root  ##bin##bash
bin  x  1  1  bin  ##bin  ##sbin##nologin
daemon  x  2  2  daemon  ##sbin  ##sbin##nologin
adm  x  3  4  adm  ##var##adm  ##sbin##nologin

/表示分割符,可以换成@

[root@docker3 mnt]# sed 's@:@ @g;s@/@##@g' passwd 
root x 0 0 root ##root ##bin##bash
bin x 1 1 bin ##bin ##sbin##nologin
daemon x 2 2 daemon ##sbin ##sbin##nologin
adm x 3 4 adm ##var##adm ##sbin##nologin

END

shell脚本常用基础命令2


shell脚本常用基础命令

  • shell脚本常用基础命令2
  • 一、grep用法
  • 二、sed用法
    • 2.1p参数 (显示)n参数(只显示处理过的行)
  • shell脚本常用基础命令2
  • 一、grep用法
  • 二、sed用法
    • 2.1p参数 (显示)n参数(只显示处理过的行)


文本处理三剑客:grep sed awk

一、grep用法

grep -E = egrep (扩展搜索正文表达式)
grep格式
grep 匹配条件 处理文件(很多正文表达式用不了) |表示或者

[root@docker3 mnt]# grep "bash|root" passwd 
[root@docker3 mnt]# egrep "bash|root" passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
operator:x:11:0:operator:/root:/sbin/nologin
yan:x:1000:1000::/home/yan:/bin/bash
[root@docker3 mnt]# grep -E "bash|root" passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
operator:x:11:0:operator:/root:/sbin/nologin
yan:x:1000:1000::/home/yan:/bin/bash
[root@docker3 mnt]# grep -e bash -e root passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
operator:x:11:0:operator:/root:/sbin/nologin
yan:x:1000:1000::/home/yan:/bin/bash

grep开启的是贪婪模式,要是不匹配前面的<,不匹配后面>

[root@docker3 mnt]# grep -E "root" passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
chroot
rootch
[root@docker3 mnt]# grep -E "\<root" passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
rootch
operator:x:11:0:operator:/root:/sbin/nologin
[root@docker3 mnt]# grep -E "\<root\>" passwd 
root:x:0:0:root:/root:/bin/bash
test:root:test
operator:x:11:0:operator:/root:/sbin/nologin

grep 前面加数字,表示该关键字前面后面几行都显示出来

[root@docker3 mnt]# grep chroot passwd 
chroot
[root@docker3 mnt]# grep -2 chroot passwd 
test:root:test
TEST:ROOT:TEST
chroot
rootch
operator:x:11:0:operator:/root:/sbin/nologin
[root@docker3 mnt]# grep -A2 chroot passwd 
chroot
rootch
operator:x:11:0:operator:/root:/sbin/nologin
[root@docker3 mnt]# grep -B2 chroot passwd 
test:root:test
TEST:ROOT:TEST
chroot

显示匹配的在第几行

[root@docker3 mnt]# grep -n chroot passwd 
12:chroot

反向过滤,除了chroot其它行都过滤出来,展示部分。

[root@docker3 mnt]# grep -v chroot passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
yan:x:1000:1000::/home/yan:/bin/bash

以^…开头,…¥以…结尾

[root@docker3 mnt]# grep -E "^root" passwd 
root:x:0:0:root:/root:/bin/bash
rootch
[root@docker3 mnt]# grep -E "bash$" passwd 
root:x:0:0:root:/root:/bin/bash
yan:x:1000:1000::/home/yan:/bin/bash
[root@docker3 mnt]# grep -E "ws" yan
ws
[root@docker3 mnt]# grep -E "w.s" yan
was
[root@docker3 mnt]# grep -E "w...s" yan
waaas
[root@docker3 mnt]# grep -E "w.*s" yan
ws
was
waaas
waaaas
waaaaas
wabababs
[root@docker3 mnt]# grep -E "w.?s" yan
ws
was
[root@docker3 mnt]# grep -E "w.+s" yan
was
waaas
waaaas
waaaaas
wabababs
[root@docker3 mnt]# grep -E "w.{3}s" yan
waaas
[root@docker3 mnt]# grep -E "w.{2,3}s" yan
waaas
[root@docker3 mnt]# grep -E "w.{,3}s" yan
ws
was
waaas
[root@docker3 mnt]# grep -E "w.{3,}s" yan
waaas
waaaas
waaaaas
wabababs
[root@docker3 mnt]# grep -E "wab{1,}s" yan
[root@docker3 mnt]# grep -E "w(ab){1,}s" yan
wabababs

脚本
请显示系统中能被su命令切换的用户名称
在这里插入图片描述

[root@docker3 mnt]# sh user_check.sh 
root
yan

二、sed用法

用来对文本的内容进行处理,修改的是模式空间(内存),真实的(磁盘中)
sed 参数 命令 处理对象
sed 参数 处理对象 -f 处理规则文件

对字符的处理
p 显示
d 删除
a 添加
n 取消默认输出,sed默认会输出所有文本内容,使用-n参数后只显示处理过的行
i 插入,直接修改文件内容
c 替换
w 写入
r 整合文件

2.1p参数 (显示)n参数(只显示处理过的行)

[root@docker3 mnt]# sed -n 5p passwd 
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@docker3 mnt]# vim rule
[root@docker3 mnt]# cat rule 
5p
[root@docker3 mnt]# sed -n -f rule passwd 
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@docker3 mnt]# sed  '5p' fstab 
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed  -n '5p' fstab 
#5
[root@docker3 mnt]# sed  -n '3,5p' fstab 
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
[root@docker3 mnt]# sed  -n '3p;5p' fstab 
# /etc/fstab3
#5

#开头的行以及不是#开头的行

[root@docker3 mnt]# sed -n '/^#/p' fstab 
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
[root@docker3 mnt]# sed -n '/^#/!p' fstab 
1
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

^$空行

[root@docker3 mnt]# sed -n '/^#/!p' fstab | sed -n '/^$/!p'
1
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

最后一行$p

[root@docker3 mnt]# sed -n '$p' fstab
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed -n '5,$p' fstab
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

显示行号,‘=’, '$='最后一行的行号(可以统计文件有多少行)

[root@docker3 mnt]# sed -n '$=' fstab 
11
[root@docker3 mnt]# sed -n -e '3p' -e '5p' fstab 
# /etc/fstab3
#5

d参数删除

[root@docker3 mnt]# sed 5d fstab 
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed '3,5d' fstab 
1
#2
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed '3d;5d' fstab 
1
#2
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed '/^#/d' fstab 
1
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

a参数添加

[root@docker3 mnt]# sed '/^#/ahello' fstab 
1
#2
hello
# /etc/fstab3
hello
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
hello
#5
hello
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
hello
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
hello
#8
hello
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

最后一行后面添加

[root@docker3 mnt]# sed '$ahello' fstab 
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
hello
[root@docker3 mnt]# sed '$ahello\nyan' fstab 
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
hello
yan

i参数插入 i是在最后一行前面,a是添加到最后一行

[root@docker3 mnt]# sed '$ihello\nyan' fstab 
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
hello
yan
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011
[root@docker3 mnt]# sed '1ihello\nyan' fstab 
hello
yan
1
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

c参数替换

[root@docker3 mnt]# sed '/^#/chello' fstab 
1
hello
hello
hello
hello
hello
hello
hello
/dev/mapper/rhel-root   /                       xfs     defaults        0 09
UUID=cf9ffcaf-d595-4545-9fd9-3573d573976e /boot  xfs  defaults        0 010
/dev/mapper/rhel-swap   swap                    swap    defaults        0 011

w参数写入

[root@docker3 mnt]# sed '/^#/w file ' fstab 
[root@docker3 mnt]# cat file\  
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8
就是
[root@docker3 mnt]# sed -n '/^#/p' fstab > file
[root@docker3 mnt]# cat file
#2
# /etc/fstab3
# Created by anaconda on Sun Mar 28 10:44:35 2021 4
#5
# Accessible filesystems, by reference, are maintained under '/dev/disk'6
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info7
#8

r

[root@docker3 mnt]# cat yan
1
2
3
[root@docker3 mnt]# cat yan1
4
5
6
[root@docker3 mnt]# cat yan yan1
1
2
3
4
5
6
[root@docker3 mnt]# cat yan yan1 > file

倒叙

[root@docker3 mnt]# tac yan
3
2
1
[root@docker3 mnt]# tac yan yan1
3
2
1
6
5
4
[root@docker3 mnt]# tac yan1 yan
6
5
4
3
2
1

cat tac无法把文件yan1整合到数字1后面,可以正序也可以倒序
1r第一行后面

[root@docker3 mnt]# sed '1ryan1' yan
1
4
5
6
2
3

整合到某关键字后面

[root@docker3 mnt]# sed '/2/ryan1' yan
1
2
4
5
6
3

更改到原文件

[root@docker3 mnt]# sed '/2/ryan1' -i yan
[root@docker3 mnt]# cat yan
1
2
4
5
6
3

脚本
Apache_port.sh
此脚本接入数字
http的端口就改为此数字
假设selinux为关闭状态
在这里插入图片描述

[root@docker3 mnt]# sh Apacha_port.sh 
Error: Please input port number following script!!!
[root@docker3 mnt]# sh Apacha_port.sh 80
Error:Apache is not installed!!

双引号不能被引用变量,单引号会注释变量,所以Listen注意是要双引号
在这里插入图片描述

[root@docker3 mnt]# sh Apacha_port.sh 8080
[root@docker3 mnt]# netstat -antlp | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      4140/httpd       
[root@docker3 mnt]# sh Apacha_port.sh 80
[root@docker3 mnt]# netstat -antlp | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      4172/httpd          

sed字符替换
s是全文的行,g全文的列
部分展示 /表示分割符

[root@docker3 mnt]# sed 's/sbin/hello/g' passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/hello/nologin
daemon:x:2:2:daemon:/hello:/hello/nologin
adm:x:3:4:adm:/var/adm:/hello/nologin
lp:x:4:7:lp:/var/spool/lpd:/hello/nologin
sync:x:5:0:sync:/hello:/bin/sync
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/hello/nologin
postfix:x:89:89::/var/spool/postfix:/hello/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/hello/nologin
yan:x:1000:1000::/home/yan:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/hello/nologin
[root@docker3 mnt]# sed 's/:/  /g' passwd 
root  x  0  0  root  /root  /bin/bash
bin  x  1  1  bin  /bin  /sbin/nologin
daemon  x  2  2  daemon  /sbin  /sbin/nologin
adm  x  3  4  adm  /var/adm  /sbin/nologin
lp  x  4  7  lp  /var/spool/lpd  /sbin/nologin
sync  x  5  0  sync  /sbin  /bin/sync
shutdown  x  6  0  shutdown  /sbin  /sbin/shutdown
halt  x  7  0  halt  /sbin  /sbin/halt
mail  x  8  12  mail  /var/spool/mail  /sbin/nologin
operator  x  11  0  operator  /root  /sbin/nologin
games  x  12  100  games  /usr/games  /sbin/nologin
[root@docker3 mnt]# sed 's/:/  /' passwd 
root  x:0:0:root:/root:/bin/bash
bin  x:1:1:bin:/bin:/sbin/nologin
daemon  x:2:2:daemon:/sbin:/sbin/nologin
adm  x:3:4:adm:/var/adm:/sbin/nologin
lp  x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync  x:5:0:sync:/sbin:/bin/sync
shutdown  x:6:0:shutdown:/sbin:/sbin/shutdown
[root@docker3 mnt]# sed '1,5s/:/  /' passwd 
root  x:0:0:root:/root:/bin/bash
bin  x:1:1:bin:/bin:/sbin/nologin
daemon  x:2:2:daemon:/sbin:/sbin/nologin
adm  x:3:4:adm:/var/adm:/sbin/nologin
lp  x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
[root@docker3 mnt]# sed '/lp/,/halt/s/:/  /g' passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp  x  4  7  lp  /var/spool/lpd  /sbin/nologin
sync  x  5  0  sync  /sbin  /bin/sync
shutdown  x  6  0  shutdown  /sbin  /sbin/shutdown
halt  x  7  0  halt  /sbin  /sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin

最后一行

[root@docker3 mnt]# sed '$s/:/  /g' passwd 
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
yan:x:1000:1000::/home/yan:/bin/bash
apache  x  48  48  Apache  /usr/share/httpd  /sbin/nologin
[root@docker3 mnt]# sed '$s/:/  /g;s/sbin/hello/g'  passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/hello/nologin
daemon:x:2:2:daemon:/hello:/hello/nologin
adm:x:3:4:adm:/var/adm:/hello/nologin
lp:x:4:7:lp:/var/spool/lpd:/hello/nologin
sync:x:5:0:sync:/hello:/bin/sync
shutdown:x:6:0:shutdown:/hello:/hello/shutdown

替换/,/需要转义,因为它是分割符

[root@docker3 mnt]# sed 's/:/  /g;s/\//##/g'  passwd 
root  x  0  0  root  ##root  ##bin##bash
bin  x  1  1  bin  ##bin  ##sbin##nologin
daemon  x  2  2  daemon  ##sbin  ##sbin##nologin
adm  x  3  4  adm  ##var##adm  ##sbin##nologin

/表示分割符,可以换成@

[root@docker3 mnt]# sed 's@:@ @g;s@/@##@g' passwd 
root x 0 0 root ##root ##bin##bash
bin x 1 1 bin ##bin ##sbin##nologin
daemon x 2 2 daemon ##sbin ##sbin##nologin
adm x 3 4 adm ##var##adm ##sbin##nologin

END

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1420058.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

The Rise and Potential of Large Language Model Based Agents: A Survey 中文翻译

大型语言模型代理的崛起与潜力&#xff1a;综述 摘要 长期以来&#xff0c;人类一直追求与或超越人类水平的人工智能&#xff08;AI&#xff09;&#xff0c;而人工智能代理被视为实现这一目标的有希望的方式。人工智能代理是感知环境、做出决策并采取行动的人工实体。已经有…

postman之接口参数签名(js接口HMAC-SHA256签名)

文章目录 postman之接口参数签名&#xff08;js接口签名&#xff09;一、需求背景二、签名生成规则三、postman js接口签名步骤1. postman设置全局、或环境参数2. 配置Pre-request Scripts脚本 四、Pre-request Scripts脚本 常见工作整理1. js获取unix时间戳2. body json字符串…

LeetCode —— 43. 字符串相乘

&#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️Take your time ! &#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️…

【AI_Design】Midjourney学习笔记

目录 后缀解析Promot合格使用prompt关键词描述 关键词化合作用关键词网站推荐 联合Chatgpt使用总结 后缀解析 –ar&#xff1a;宽高比设置–c&#xff1a;多样性设置&#xff08;数值0-100&#xff0c;默认值0&#xff09;–s&#xff1a;风格化设置&#xff08;数值0-1000&am…

【C/C++ 06】基数排序

基数排序是桶排序的一种&#xff0c;算法思路为&#xff1a; 利用队列进行数据收发创建一个队列数组&#xff0c;数组大小为10&#xff0c;每个元素都是一个队列&#xff0c;存储取模为1~9的数从低位到高位进行数据收发&#xff0c;完成排序适用于数据位不高的情况&#xff08…

C++入门(一)— 使用VScode开发简介

文章目录 C 介绍C 擅长领域C 程序是如何开发编译器、链接器和库编译预处理编译阶段汇编阶段链接阶段 安装集成开发环境 &#xff08;IDE&#xff09;配置编译器&#xff1a;构建配置配置编译器&#xff1a;编译器扩展配置编译器&#xff1a;警告和错误级别配置编译器&#xff1…

8-小程序数据promise化、共享、分包、自定义tabbar

小程序API Promise化 wx.requet 官网入口 默认情况下&#xff0c;小程序官方异步API都是基于回调函数实现的 wx.request({method: , url: , data: {},header: {content-type: application/json // 默认值},success (res) {console.log(res.data)},fail () {},complete () { }…

CSS之webkit内核中的属性text-stroke

让我为大家介绍一下text-stroke 大家是否想过要弄一个描边过的文字&#xff0c;接下来&#xff0c;text-stroke就可以为你解决 text-stroke是一个复合属性&#xff0c;里面有两个参数&#xff1a;描边的尺寸 描边的颜色 <!DOCTYPE html> <html lang"en">…

20世纪物理学:对宇宙认知的一次巨大飞跃

20世纪物理学&#xff1a;对宇宙认知的一次巨大飞跃 20th Century Physics: A Monumental Leap in Understanding the Universe 在20世纪这个科学大爆发的时代&#xff0c;现代物理学经历了前所未有的飞速发展与变革。这一时期诞生了众多奠基性的理论和杰出的物理学家&#xff…

三、ElasticSearch集群搭建实战

本篇ES集群搭建主要是在Linux VM上&#xff0c;未使用Docker方式, ES版本为7.10 ,选择7.10版本原因可以看往期文章介绍。 一、ElasticSearch集群搭建须知 JVM设置 Elasticsearch是基于Java运行的&#xff0c;es7.10可以使用jdk1.8 ~ jdk11之间的版本&#xff0c;更高版本还没…

Python 手签文字识别

easyocr插件使用 1、上传签字图片&#xff08;图片背景颜色&#xff0c;和图片的大小会影响文字识别准确率&#xff09; 2、服务端代码如下 from flask import Flask, request, Response import easyocr import json from hanziconv import HanziConv reader easyocr.Reade…

PyFlink使用教程,Flink,Python,Java

环境准备 环境要求 Java 11 Python 3.7, 3.8, 3.9 or 3.10文档&#xff1a;https://nightlies.apache.org/flink/flink-docs-release-1.17/zh/docs/dev/python/installation/ 打开 Anaconda3 Prompt > java -version java version "11.0.22" 2024-01-16 LTS J…

探索Pyecharts:绘制多彩日历图的艺术与技巧

Pyecharts绘制多种炫酷日历图参数说明代码实战 导言 在数据可视化领域&#xff0c;日历图是一种直观展示时间和数据关系的方式。Pyecharts是一个基于Echarts的Python库&#xff0c;可以方便地绘制各种图表&#xff0c;包括炫酷的日历图。本篇博客将介绍Pyecharts中绘制多种炫…

AI未来10年展望【2024-2034】

人工智能&#xff08;AI&#xff09;在过去十年中迅速发展&#xff0c;其未来有望取得更加引人注目的发展。 在本文中&#xff0c;我们将探讨人工智能的未来 10 年以及我们对未来十年的期望。 我们将解决一些关键问题&#xff0c;以全面概述人工智能的未来。 NSDT工具推荐&…

17. 使用 tslib 库

17. 使用 tslib 库 1. tslib 简介2. tslib 移植2.1 下载 tslib 源码2.2 编译 tslib 源码2.3 tslib 安装目录下的文件夹介绍2.4 在开发板上测试 tslib 3. tslib 库函数介绍3.1 打开触摸屏设备3.2 配置触摸屏设备3.3 读取触摸屏设备 4. 基于 tslib 编写触摸屏应用程序4.1 单点触摸…

CHS_03.2.3.2_2+进程互斥的硬件实现方法

CHS_03.2.3.2_2进程互斥的硬件实现方法 知识总览中断屏蔽方法TestAndSet指令Swap指令 知识回顾 进程互斥的四种软件实现方法 知识总览 这个小节我们会介绍另外的三种进程互斥的硬件实现方法 那么 这个小节的学习过程当中 大家需要注意理解各个方法的原理 并且要稍微的了解各个…

OpenHarmony RK3568 启动流程优化

目前rk3568的开机时间有21s&#xff0c;统计的是关机后从按下 power 按键到显示锁屏的时间&#xff0c;当对openharmony的系统进行了裁剪子系统&#xff0c;系统app&#xff0c;禁用部分服务后发现开机时间仅仅提高到了20.94s 优化微乎其微。在对init进程的log进行分析并解决其…

机器学习:多项式回归(Python)

多元线性回归闭式解&#xff1a; closed_form_sol.py import numpy as np import matplotlib.pyplot as pltclass LRClosedFormSol:def __init__(self, fit_interceptTrue, normalizeTrue):""":param fit_intercept: 是否训练bias:param normalize: 是否标准化…

重写Sylar基于协程的服务器(1、日志模块的架构)

重写Sylar基于协程的服务器&#xff08;1、日志模块的架构&#xff09; 重写Sylar基于协程的服务器系列&#xff1a; 重写Sylar基于协程的服务器&#xff08;0、搭建开发环境以及项目框架 || 下载编译简化版Sylar&#xff09; 重写Sylar基于协程的服务器&#xff08;1、日志模…

2.室内设计学习 - CAD 2021 调整经典界面教程及基本设置

设置经典界面 1.在第二行的空白处右击&#xff0c;弹出对话框&#xff0c;并点击【关闭】&#xff0c;关闭掉。 2.菜单栏没有显示的情况下&#xff0c;在最上面的一排&#xff0c;点击向下的箭头展开下拉框&#xff0c;勾选 【显示菜单栏】 3.点击菜单【工具】-【工具栏】-【a…