使用shell脚本,找出/etc目录下以.conf结尾文件复制到/tmp下面 (四种方法)
[root@handsome-man ~]# find /etc -type f -name '*.conf'|xargs cp -t /tmp
-t是cp的一个参数
2
[root@handsome-man ~]# cp $(find /etc -type f -name '*.conf') /tmp
find /etc/ -type f -name "*.conf" -exec cp {} /tmp \;
find /etc/ -type f -name "*.conf" |xargs -i cp {} /tmp/
xargs -i 让xargs后面可以使用{ } 表示前面find找出的文件 类似 - exec里面的{ }
打包备份/etc 目录到/backup 下面,保证每天备份的压缩名字不同
tar zcf /backup/etc -$(date +%F).tar.gz /etc/
取出网卡ip地址
ip a s eth0
方法1 sed 正则
[root@handsome-man ~]# ip a s eth0|sed -n '3p' |sed 's#^.*t ##g'|sed 's#/.*$##g'
10.0.0.202
方法2 sed 后向引用
[root@oldboyedu59 ~]# ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:ff:79:0e brd ff:ff:ff:ff:ff:ff
inet 10.0.0.201/24 brd 10.0.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feff:790e/64 scope link
valid_lft forever preferred_lft forever
[root@oldboyedu59 ~]# ip a s eth0 |sed -n 3p
inet 10.0.0.201/24 brd 10.0.0.255 scope global eth0
[root@oldboyedu59 ~]# ip a s eth0 |sed -n 3p |sed -r 's#^.*t (.*)/.*$#\1#g'
10.0.0.201
[root@oldboyedu59 ~]#
[root@oldboyedu59 ~]# ip a s eth0 |sed -n 3p |sed -r 's#(^.*t )(.*)(/.*$)#\1#g'
inet
[root@oldboyedu59 ~]# ip a s eth0 |sed -n 3p |sed -r 's#(^.*t )(.*)(/.*$)#\3#g'
/24 brd 10.0.0.255 scope global eth0
stat /etc/hosts
取出结果中的644
网友评论