开发者

moving files with folder to new folder in bash

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


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


You mean like 'mv' :P

http://linux.about.com/library/cmd/blcmdl1_mv.htm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜