hi i m using linux server. and want to move 100s of file to their parent directory. my current directory look like this. 301/name 1/*.jpg 302/name 2/*.jpg 303/name 3/*.jpg . . . . 860/name 4/*.jpg Parent folder name is in serial like 301, 302, 303 and so on till 860. But subfolder are different names containing jpg files. I want to move those jpg file from name1, name2, to 301, 302 and so on and i also dont want to delete those subfolder bcoz i have to copy their name to database. i just want to look like this after moving files. 301/*.jpg, name 1 302/*.jpg, name 2 303/*.jpg, name 3 . . . . 860/*.jpg, name 4/ i somehow got this thread. http://www.howtoforge.com/forums/sho...d.php?p=187161 but cant able to figure it out, as i m newbie in it. so any help would be appreciated.
Create file mover.sh in the folder with 301, 302, 303, .., 860 #!/bin/sh for i in `ls` do if [ -d $i ] then cd $i; for j in `ls` do if [ -d $j ] then cd $j; mv *.jpg ..; cd ..; fi done cd ..; fi done Code (markup): Do chmod u+x mover.sh And run ./mover.sh
As i m new to this i m asking so something not goes wrong. 1. i have to copy the code to a text file and rename it to mover.sh 2. should i have to place it to one up directory, where the folder 301, 302, 303, 860 are located. and finally how to run this. is blank folder still available after running this code ? After running it is not working giving error on syntax 3 rd line do
should do the task you described - recurse into folders inside 310, 302, 303, ... and move jpegs inside that folders up one level. What blank folder do you mean? It doesn't remove any folder just moving jpegs - is it right? About the error - what OS (cat /etc/issue) are you using? Script tested on Centos 5.3 and should work almost on every shell.
using centos-5-i386-hostinabox575 Error: -bash: ./mover.sh: /bin/sh^M: bad interpreter: No such file or directory
@nura235 i cannot help you with your problem but you can upload all of the files to my FileHosting site in my signature.So you dont loose them and its free.
The problem is because of ^M symbol at the end of the line. This symbol inserted by text editor in some MS Windows box. You should delete ^M on the end of the each line or create this file in UNIX using vi editor for example. Or just download this file using wget or some other tool from http://polkan.net/download/mover.sh
it goes well with your provided download file, however i have changed it to know the problem. it not working with folders whose name with space eg: freedom fighter and tom jerry however it work well with folder name in one word. what to edit in this to work well.
Its not good idea to have folders with pace in name under unix - acceptable but not usual like wearing saucepan on the head... Do you see these folders echoed? Try to use cd \"$i\" and cd \"$j\" instead of just cd $i and cd $j
yes i can these folder echoed. it not working with cd \"$i\" and cd \"$j\" line 8 is for j in `ls` line 17 is cd ..; it giving error in line 8 and line17 cd:"1" no such file and directory mv: cannot stat '*.jpg: no such file and directory