附上网友们总结出来的方法如下(以批量解压tar文件为例):
第一:
for tar in *.tar.gz; do tar xvf $tar; done
for tar in *.tar.bz2; do tar xvf $tar; done
第二:用tar命令批量解压某个文件夹下所有的tar.gz文件
ls *.tar.gz | xargs -n1 tar xzvf
第三:find -maxdepth 1 -name “*.bz2″|xargs -i tar xvjf {}
这条命令可解压当前目录下的所有bz2文件,maxdepth表示搜索深度,1代表只搜索当前目录
第四:for i in $(ls *.tar);do tar xvf $i;done
以上,第二个方法最为简单明了!
再附上第四种,附上批量压缩静态文件(js、css)成tar.gz:
此脚本 好处是判断文件修改时间,不重复生成
find ./ -type f -printf ‘%TY %Tm %Td %TH %TM %TS\t%p\n’ \
| grep -iE ‘\.(html|txt|css|js)$’ \
| awk -F’\t’ ‘{
gz_file=$2 “.gz”;
stat_cmd=”stat -c \”%Y\” ” gz_file;
exist_cmd=”[ -e \"" gz_file "\" ] && echo 1 || echo 0″;
exist_cmd | getline gz_file_exist;
if (gz_file_exist) {
stat_cmd | getline last_modify_timestamp;
} else {
last_modify_timestamp=0;
}
if (last_modify_timestamp < mktime($1)) {
system(“gzip -c9 ” $2 ” > ” gz_file);
print gz_file ” [created]“;
}
}’
此脚本结合nginx的gzip static模块使用,编译时加上--with-http_gzip_static_module
nginx.conf中加上:
sendfile on; # 最好打开这个sendfile
gzip on;
gzip_static on;
gzip_http_version 1.0;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
gzip_comp_level 2;
gzip_min_length 1024;
gzip_buffers 4 16k;
gzip_types text/plain html application/x-javascript text/css;