平日里有很多的事情都可以用Script来完成,学习必要的脚本并写出Script以代替手工。
我们的目标是DRY和Automation。
需要的工具:
Shell
Perl
Linux tools: sed, replace, find, xargs等等。
如,替换文件中的某些内容就可以用replace命令来完成:
#replace audio image Audio Image -- file
或者,对当前目录下所有的都如此处理:
#find . -type f -exec replace audio image Audio Image -- {} ';'
自己用sed来写replace脚本:
#!/bin/sh TMP_FILE=temp_temp.tmp if [ ! $# -eq 3 ] then echo "Usage: replace.sh match pattern file"; exit; fi sed -e "s/$1/$2/g" $3 > $TMP_FILE mv $TMP_FILE $3
之后这样应用:
#replace.sh audio image file1
或者
# find . -type f -exec ./replace.sh audio image {} ';'
正所谓磨刀不误砍柴功,花点时间学习一下这些脚本语言并写写脚本来替代手工操作,将会使工作效率大幅提升。有关DRY和Automation可以看看《Pragmatic Programmer》和《The Productive Programmer》这二本书,其中都有比较详细和深入的讨论。