LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Script For Moving Files In Subdirectories (http://www.linuxquestions.org/questions/linux-general-1/script-for-moving-files-in-subdirectories-38690/)

darkmage 12-17-2002 05:11 PM

Script For Moving Files In Subdirectories
 
Heres an interesting situation, can anyone think of a script that would do this?
I have a directory, it has a lot of other directoriess, and in each one of those is an image directory with an image called admin.gif, now i am trying to figure a way to mv all those gif files to another directory of the same type but i really don't want to have to do it one by one.

Thanks in advance

Hko 12-17-2002 05:47 PM

Could you please explain more specific about what exactly you would like to do? I mean, for example, if I guess correctly, do all the GIF files have exactly the same name ("admin.gif") but thay are in different subdirs? And you want to move them to one single directory? If so, this means you want to rename the files to have unique names, by adding an incremental number or so?

Or do you want to move them to a similar dir / subdir tree? If so, it may be easier to rename the subdir's instead of moving them.

Maybe you could give some examples of the actual paths.

darkmage 12-17-2002 06:21 PM

Hko, the rename with incremental number thing sounds good, could you give an example. The directories are like /images/001/admin.gif ore /images/002/admin.gif. I was trying to figure out if Linux could do this. Thanks for the help so far

iocain 12-17-2002 06:34 PM

Quote:

Originally posted by darkmage
Hko, the rename with incremental number thing sounds good, could you give an example. The directories are like /images/001/admin.gif ore /images/002/admin.gif.
I'm a tcsh user, so what I'd do for what it sounds like you want is something like this:

Quote:

mkdir images-all
cd images
foreach i (*)
ln ${i}/admin.gif ../images-all/admin-${i}.gif
end
This would have the effect of "hard-linking" the admin.gif image from the /images/001/ and /images/002/ (and so on) directories into my /images-all/ directory, but with the name admin-001.gif and admin-002.gif (and so on). This way, any change made to /images/001/admin.gif would also affect /images-all/admin-001.gif -- but if you don't want that, just use the "mv" command in place of the "ln" command, above.

Oh, and to do the same thing under bash, which perhaps more Linux users are familiar with, would look like this:

Quote:

mkdir images-all
cd images
for i in *; do ln ${i}/admin.gif ../images-all/admin-${i}.gif; done


All times are GMT -5. The time now is 04:12 PM.