案例
1、解压一个目录下的文件到指定的文件夹下
#!/bin/bash unzip_path='/opt/fossx/data/codedownload/c/repository/' go_path='/opt/fossx/data/coderepo/c/group2/' filelist=$(ls ${unzip_path}) # shellcheck disable=SC1073 for filename in ${filelist} do mkdir ${go_path}${filename%--*} tar zxvf $unzip_path${filename} -C ${go_path}${filename%--*} done
2、移动文件到某文件夹++list
#!/bin/bash copy_path='/opt/fossx/data/coderepo/c/group2test/' filelist=$(ls ${copy_path}) num=1 cd $copy_path # shellcheck disable=SC1073 for filename in ${filelist} do # shellcheck disable=SC1019 # shellcheck disable=SC1072 # shellcheck disable=SC1020 if test -d "$filename" then cd "$filename" fileNum=`ls -l|wc -l` let fileNum-- if test "$num" -eq "$fileNum" then mv `ls` "$filename" mv $copy_path$filename $copy_path${filename%--*} fi cd - fi done