千家信息网

shell 语法

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,用正则给ip对应的mac分割[root@room1pc01 桌面]# cat ipmac.txt192.168.4.5 121212452242192.168.4.2 242426231251192.
千家信息网最后更新 2026年11月01日shell 语法


用正则给ip对应的mac分割

[root@room1pc01 桌面]# cat ipmac.txt
192.168.4.5 121212452242
192.168.4.2 242426231251
192.168.4.3 242426231324

[root@room1pc01 桌面]#vim ipmac.txt

1 192.168.4.5 12:12:12:45:22:42
2 192.168.4.2 24:24:26:23:12:51
3 192.168.4.3 24:24:26:23:13:24
~
~
~
~
~
:%s /\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)$/\1:\2:\3:\4:\5:\6/g






[root@room1pc01 python]# grep -v "^$" kb |grep -v "^#"


# sed -i '/^$/d' 1.txt 删除空白行
#sed -i '/^$/d' kb
#sed -i 's/^/AAA/' kb
#sed -i 's/$/BBB/' kb

#sed -i "s/^#an/an/" /etc/vsftpd/vsftpd.conf 删除注释
#sed -i "s/^an/#an/" /etc/vsftpd/vsftpd.conf 添加注释

# sed '/id/s/[0-6]/5/' /etc/inittab


[root@vh03 00]# sed -i '/bash/s#/bin/bash#/sbin/nologin#' /etc/passwd
[root@vh03 00]# head -1 /etc/passwd
root:x:0:0:root:/root:/sbin/nologin



sed -i 'r /etc/passwd' 1.txt (在1.txt中每行下面都导入一个这样文件内容 )
sed -i '1r /etc/passwd' 1.txt (在第一行导入内容)


# sed '2,3w y.txt' n.txt (把n.txx第二和第三行导出到y.txt中 之前内容被覆盖了 且是真导入 不用-i)
[root@st5 ~]# cat y.txt
bbbbbbbbbb
ccccccccc
[root@st5 ~]# cat n.txt
aaaaaaaa
bbbbbbbbbb
ccccccccc
ddddddddd


(下面两个命令相等)
#sed -n '/bash$/s/:.*//p' /etc/passwd
# awk -F: '/bash$/{print $1}' /etc/passwd
root
dc
45


[root@room1pc01 桌面]# awk '/bash$/{print $1}' /etc/passwd
root:x:0:0:root:/root:/bin/bash
dc:x:501:501::/home/dc:/bin/bash
45:x:502:502::/home/45:/bin/bash


[root@room1pc01 ~]# awk '{print $1}' 1.txt


[root@room1pc01 ~]# awk '/ma/' 1.txt (专门打条件,没打指令是显示该条件整行)
chi l ma ni
[root@room1pc01 ~]# awk '/ma/{print $1}' 1.txt (显示该条件的行第一个
chi



[root@room1pc01 桌面]# awk '{print NR}' b.txt (显示b.txt该文件有多少行号)
1
2
3
[root@room1pc01 桌面]# awk '/555/{print NR}' b.txt (显示555在b.txt中第几行)


[root@room1pc01 桌面]# awk '{print NF}' b.txt (显示每行有多少列)
3
3
5



[root@room1pc01 桌面]# awk '{IP[$1]++} END{for(i in IP){print i,IP[i]}}' /var/log/httpd/access_log
192.168.4.254 2583
::1 80
[root@svr5 ~]# awk '{print $1}' /var/log/httpd/access_log |sort |uniq
80::1
2583 192.168.4.254
[root@svr5 ~]# who |awk '{IP[$1]++} END{for(i in IP) {print i,IP[i]}}'
root 2


[root@vh01 ~]# ifconfig eth0 |awk -F "[ :]" '/inet addr/{print $13}'
192.168.4.1



rpm包也可以用yum装 不需要用rpm -ivh *.rpm (这样可以解决依赖关系)
date -d @'1000'








去掉文件中的空行,并给有数据的行前面加AAA后面加BBB。

sed -i '/^$/d' kb
sed -i 's/^/AAA/' kb
sed -i 's/$/BBB/' kb



[root@room1pc01 python]# cat kb
dasdafdsf

fsadfas
f

#dfsadfas
#fasd
#f
#fasdfas
#df
#as

[root@room1pc01 python]# sed -i '/^$/d' kb
[root@room1pc01 python]# cat kb
dasdafdsf
fsadfas
f
#dfsadfas
#fasd
#f
#fasdfas
#df
#as

[root@room1pc01 python]# sed -i 's/^/AA/' kb

[root@room1pc01 python]# cat kb
AAdasdafdsf
AAfsadfas
AAf
AA#dfsadfas
AA#fasd
AA#f
AA#fasdfas
AA#df
AA#as
[root@room1pc01 python]# sed -i 's/$/BB/' kb
[root@room1pc01 python]# cat kb
AAdasdafdsfBB
AAfsadfasBB
AAfBB
AA#dfsadfasBB
AA#fasdBB
AA#fBB
AA#fasdfasBB
AA#dfBB
AA#asBB




客户端使用vnc和服务器同步屏幕

[root@room1pc01 桌面]# yum provides */vncviewer

[root@room1pc01 桌面]# yum -y install tigervnc

[root@room1pc01 桌面]# vncviewer

输入ip和端口就ok









桌面 内容 文件 条件 注释 一行 不用 两个 命令 客户 客户端 屏幕 指令 数据 服务器 正则 空白 空白行 空行 端口 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 广东万易互联网科技有限公司惠州分公司 深圳恒合互联网络科技有限公司 互联网科技行业发展 互联网科技资迅 世界互联网领先科技成果 互联网 视角下的科技创新 居家互联网科技有限公司 深圳互联网科技怎么样 华中科技有哪些互联网大佬 互联网科技公司需要的职位 江苏南京365互联网科技 欧洲十大科技互联网公司 栖莱科技互联网股份有限公司 河南猎农互联网科技有限公司 互联网科技研发水平 爱医互联网络科技 国大互联网教育科技有限公司薪资 10位科技互联网大佬 恒生互联网科技趋势 互联网企业和网络科技有限公司 华服互联网科技靠谱吗 上海互联网科技有限公司 科技互联网大厂 广西互联网科技孵化中心 健康食品互联网创新科技园项目 美国互联网科技实力 北京市互联网新科技 互联网科技实习生岗位 米泉互联网科技专业怎么样 数字科技和互联网金融哪个好
0