Reputation: 22810
lets say we have something like a bunch of file from
find development/js -name "*.js"
it returns something like
development/js/folder1/*.js
development/js/folder2/*.js
that we need to move to
# as you can see folder 1 & 2 is the same but diffrent folder
production/js/folder1/*.js
production/js/folder2/*.js
how can we move files in bash like above?
thanks!
edit* heres what im upto
#!/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
Upvotes: 0
Views: 154
Reputation: 8452
You can do:
#!/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
Upvotes: 1
Reputation: 274
You mean like 'mv' :P
http://linux.about.com/library/cmd/blcmdl1_mv.htm
Upvotes: 0