LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 10-02-2005, 02:06 PM   #1
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
Recursively move files


Sorry, I know this is a common question but I can't figure out how to get this to work properly. When I manage it I'll post a recursivity how to to make up for it

I have a photo library program that manages files in a very peculiar way. Organized by year, then month, then something else I can't figure out, then a series of data files, thumbnails, and then below that, in a folder called Originals, are the actual photos.

What I need to do is take every file out of the Originals (nth-subfolder) and cp or mv that to another folder, to they're all in one place.

I'm sure this is a one-liner, can anybody help me ?
 
Old 10-02-2005, 02:12 PM   #2
linmix
Senior Member
 
Registered: Jun 2004
Location: Spain
Distribution: FC5
Posts: 1,993
Blog Entries: 1

Rep: Reputation: 46
how about

$mv ./*/*.jpg /destination/folder
 
Old 10-02-2005, 02:20 PM   #3
asuka
LQ Newbie
 
Registered: Oct 2004
Location: Korea
Distribution: Debian,Gentoo,FC2
Posts: 10

Rep: Reputation: 0
Here's how I would do it.

find $PHOTOROOT -name "*/Originals/*" -exec mv {} $DESTDIR \;

Replace $PHOTOROOT with where your program stores files,
and $DESTDIR with where u want to move it.
;D hope it works..
 
Old 10-02-2005, 02:34 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
I'll throw my hat in... It's similar to asuka's:
Code:
find $PHOTOROOT -type f -path "*/Originals/*" -iname "*.jpg" -exec mv {} $DESTDIR \;
So why is mine longer??
I'm not sure if find will match part of the path as the filename (haven't tried it). Also, there may be other files besides images in those directories. The "-path" option pulls the path match out of the filename argument, and the "-iname" part matches any file ending in ".jpg", ".JPG", ".Jpg", etc.

WARNING: Never, never, never run someone else's command (mine included) that moves or deletes files without verifying it works first!!! You can examine what files are selected by changing the above command to:
Code:
find $PHOTOROOT -type f -path "*/Originals/*" -iname "*.jpg"
That will print of list of matching files. You might also consider copying the files over instead of moving them (by replacing the "mv" with "cp" in the first command). Once the files are copied and you're happy, run the exact same command, but tell it to remove the file (again, substitute "rm" for the "cp" and get rid of the $DESTDIR)

Make sense?
 
Old 10-02-2005, 02:50 PM   #5
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Original Poster
Rep: Reputation: 30
Thanks everyone, very much appreciated !

And I was going to replace the mvs with cps I wouldn't run a command I wasn't familiar with without first checking what it would do to my entire library, very sound advice !
 
  


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
cannot using FTP move command to move files adrianmak Linux - Networking 4 04-21-2009 01:01 PM
Copying hidden files recursively? mrd Linux - General 1 09-30-2005 08:51 AM
List all files and recursively open directories. unreal128 Linux - General 2 07-16-2005 03:06 PM
how to rm backup files recursively wazoo Linux - Newbie 6 12-31-2004 11:03 AM
Recursively listing files over FTP? overbored Linux - Software 4 10-14-2004 01:12 PM


All times are GMT -5. The time now is 09:38 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