我们可以说我们有一堆来自的文件
find development/js -name "*.js"
返回类似
的内容development/js/folder1/*.js
development/js/folder2/*.js
我们需要转移到
# as you can see folder 1 & 2 is the same but diffrent folder
production/js/folder1/*.js
production/js/folder2/*.js
我们怎么能像上面那样用bash移动文件?
谢谢!
编辑*继承人的内容
#!/bin/bash
devel_file_js=`find ../../development/js -name "*.js"`
production_folder=`../../production/js`
for i in $devel_file_js;
do
mv #hmm
done
Adam Ramadhan
答案 0 :(得分:1)
你可以这样做:
#!/bin/bash
dev_folder="../../development/js";
production_folder="../../production/js"
for old_location in $(find $dev_folder -name "*.js")
do
new_location=$(echo ${old_location/${dev_folder}/${production_folder}/})
new_dirname=$(dirname ${new_location})
echo "Moving ${old_location} to ${new_location}"
# Create folder if not exists
if [[ ! -d ${new_dirname} ]]
then
mkdir -p ${new_dirname}
fi
# mv ${old_location} ${new_location}
done
答案 1 :(得分:0)