shell script

来源:互联网 发布:淘宝零食店一箱零食 编辑:程序博客网 时间:2024/05/06 20:00

比较健忘,有用的shell脚本贴过来,以便下次参考

 

1.将某个文件夹下的所有以.h和.c结尾的文件中的aaa替换为bbb

#!/bin/bash

find ../ -name '*.h' -print0 |xargs -0 sed -i 's/aaa/bbb/g'
find ../ -name '*.c' -print0 |xargs -0 sed -i 's/aaa/bbb/g'

 

2.将某个文件夹下指定的一些文件对应的copy到另外一个目录

#!/bin/bash

src="src_dir"

des="des_dir"

files="Makefile a/a.h b/b.c"

 

#copy files
echo "-----------------copy files---------------------"
for i in $files;
do
  if cp $src/$i $des/$i
  then echo "success copy $i destination"
  else echo "can not copy $src/$i to $des/$i"
  fi
done

 

原创粉丝点击