linux for 循环的小应用

[root@localhost ~]# mkdir -pv /home/data{1..5}  # 创建多个目录

以下两种方法类似。

for i in {1..5};do echo  "<h3>test<h3>" > /home/data$i/index.html; done 

[root@localhost ~]# for i in $(seq 1 4);do echo "<h3>123456<h3>" /home/data$i/index.html; done   # for循环多个目录写入文件。

关闭所有系统服务

for i in `chkconfig --list |awk '{print $1}'`;
do chkconfig $i off;
echo chkconfig $i off;
done

开启指定的服务
for i in auditd crond network iptables messagebus udev-post ntpd sshd rsyslog sysstat zabbix-agent;
do chkconfig $i --level 234 on;
echo chkconfig $i --level 234 on;
done

原文地址:https://www.cnblogs.com/zoulixiang/p/9207473.html