ztj.sh
#!/bin/bash
all_sh_files=$(find . -type f -name "*.shell")
for file in ${all_sh_files[*]}
do
filename=$(echo $file | awk -F'.shell' '{print $1}')
new_filename="${filename}.bak"
mv "$file" "$new_filename"
sed -i '2d' "$new_filename"
done
验证:
[root@logstash test]# ls
aa.shell bb.shell cc.shell ztj ztj.sh
[root@logstash test]# sh ztj.sh
[root@logstash test]# ls
aa.bak bb.bak cc.bak ztj ztj.sh
[root@logstash test]# cat aa.bak
aaa
[root@logstash test]#