for in linux
时间:2009-01-18 来源:isqlw
一、for对数字的操作
1、for ip in 100 101 102
do
done
2、for ip in $(seq 1 10) //seq 1 10生成从1到10的整数
do
ping -c 1 "192.168.1.$ip" >> p.txt
done
3、for ip in {1..10} // {1..10}==$(seq 1 10)
do
ping -c 1 "192.168.1.$ip" >> p.txt
done
less p.txt |grep ttl |wc -l
二、对文件的操作
把/etc/中的.conf文件备份到/tmp下
方法1:
[root@isqlw tmp]# pwd
/tmp
[root@isqlw tmp]# cat conffile.sh
#!/bin/bash for conffile in $(find ./ |grep .conf)
do
cp -v $conffile /tmp/$conffile.$(date +%F)
done
[root@isqlw tmp]# chmod 755 conffile.sh
[root@isqlw tmp]# cd /etc
[root@isqlw etc]# . /tmp/conffile.sh 方法2: [root@isqlw tmp]# cat backupconf.sh
#!/bin/bash for FILENAME in *.conf
do
cp -v $FILENAME /tmp/$FILENAME.$(date +%F)
done
[root@isqlw tmp]# chmod 755 backupconf.sh
[root@isqlw tmp]# cd /etc
[root@isqlw etc]# . /tmp/backupconf.sh
/tmp
[root@isqlw tmp]# cat conffile.sh
#!/bin/bash for conffile in $(find ./ |grep .conf)
do
cp -v $conffile /tmp/$conffile.$(date +%F)
done
[root@isqlw tmp]# chmod 755 conffile.sh
[root@isqlw tmp]# cd /etc
[root@isqlw etc]# . /tmp/conffile.sh 方法2: [root@isqlw tmp]# cat backupconf.sh
#!/bin/bash for FILENAME in *.conf
do
cp -v $FILENAME /tmp/$FILENAME.$(date +%F)
done
[root@isqlw tmp]# chmod 755 backupconf.sh
[root@isqlw tmp]# cd /etc
[root@isqlw etc]# . /tmp/backupconf.sh
相关阅读 更多 +