Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-17-2002, 05:11 PM
|
#1
|
Member
Registered: Jun 2002
Location: Lousiville,KY
Distribution: Gentoo
Posts: 89
Rep:
|
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
|
|
|
12-17-2002, 05:47 PM
|
#2
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep: 
|
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.
|
|
|
12-17-2002, 06:21 PM
|
#3
|
Member
Registered: Jun 2002
Location: Lousiville,KY
Distribution: Gentoo
Posts: 89
Original Poster
Rep:
|
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
|
|
|
12-17-2002, 06:34 PM
|
#4
|
LQ Newbie
Registered: Dec 2002
Location: Canada
Distribution: Debian, BSD, IRIX, MacOS, Solaris, AIX, HP-UX, other Unix, other Linux, other, windos (declining...)
Posts: 25
Rep:
|
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
|
Last edited by iocain; 12-17-2002 at 06:35 PM.
|
|
|
All times are GMT -5. The time now is 04:37 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|