LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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



Reply
 
Search this Thread
Old 12-17-2002, 06:11 PM   #1
darkmage
Member
 
Registered: Jun 2002
Location: Lousiville,KY
Distribution: Gentoo
Posts: 89

Rep: Reputation: 15
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
 
Old 12-17-2002, 06:47 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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.
 
Old 12-17-2002, 07:21 PM   #3
darkmage
Member
 
Registered: Jun 2002
Location: Lousiville,KY
Distribution: Gentoo
Posts: 89

Original Poster
Rep: Reputation: 15
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
 
Old 12-17-2002, 07:34 PM   #4
iocain
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: Reputation: 15
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 07:35 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Bash, Find script files in a directory or subdirectories within... ray5_83 Programming 4 10-10-2008 08:42 PM
copy 3 files to a directory and all subdirectories? snip128 Linux - Newbie 9 08-12-2005 10:18 PM
executing a script in multiple subdirectories jerryfreak Linux - Newbie 1 04-19-2005 09:34 PM
Unzipping all .gz files in all subdirectories darin3200 Linux - General 10 04-24-2004 10:58 PM
delete files / keep subdirectories? lhorstman Linux - Newbie 2 01-10-2003 04:01 PM


All times are GMT -5. The time now is 02:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration