Bash

(遇到时就更新)

①批量将文件编码由gb2312转为utf8:

1 for filename in `find . -type f | xargs ls -l | awk '{print $8}'`;do echo $filename;iconv -f utf8 -t gb2312 $filename -o $filename;done

②批量在文件开头添加文本内容:

1 for filename in `find . -type f | xargs ls -l | awk '{print $8}'`;do echo $filename;sed -i '1i\the text need to add' $filename;done

③批量在文件末尾添加文本内容:

1 for filename in `find . -type f | xargs ls -l | awk '{print $8}'`;do echo $filename;sed -i '$a\the text need to add' $filename;done

④批量替换多个文件中的字符串:

1 sed -i "s/8080/8443/g" `grep 8080 -rl .`

 ⑤批量修改文件名:

1 ls -l conf* | awk '{filename=$8;gsub(/conf/,"config",$8);print "mv "filename " "$8}'|sh

 

你可能感兴趣的:(bash)