遍历目录下的所有文件,并将文件解压到对应的文件夹里。
1 遍历文件
#!/bin/bash
function getdir(){
for element in `ls $1`
do
dir_or_file=$1"/"$element
if [ -d $dir_or_file ]
then
rename 's/ /_/g' $dir_or_file/*
getdir $dir_or_file
else
echo $dir_or_file
fi
done
}
root_dir="/home/zhanghan/huangle/fugi/fungi_download"
getdir $root_dir
2遍历文件+解压脚本
#!/bin/bash
function getdir(){
for element in `ls $1`
do
dir_or_file=$1"/"$element
if [ -d $dir_or_file ]
then
rename 's/ /_/g' $dir_or_file/* #将该路径下带有空格的文件名全都换成下划线
getdir $dir_or_file#递归
else
#echo $dir_or_file
for key1 in ${arr[@]};
do
#key1="CDS"
new_path=~/huangle/fugi/$key1
if [ ! -d $new_path ];then #没有key1文件夹,创建该文件夹
mkdir "$new_path"
fi
result=$(echo $element | grep "${key1}")#判断element 是否包含 key1
if [[ "$result" != "" ]]
then
echo $element
gunzip -c $dir_or_file > ~/huangle/fugi/$key1/$element.txt #解压该路径下的所有.gz文件
fi
done
fi
done
}
arr=("CDS" "KEGG" "GO" "IPR" "KOG" "SigP" "gff3" "genes" "proteins" "AssemblyScaffolds_Repeatmasked")
root_dir="/home/zhanghan/huangle/fugi/fungi_download"
getdir $root_dir