Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 10-02-2005, 01:06 PM   #1
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, 01:12 PM   #2
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, 01:20 PM   #3
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, 01:34 PM   #4
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
I'll throw my hat in... It's similar to asuka's:
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:
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, 01:50 PM   #5
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 !
Old 02-17-2016, 01:24 AM   #6
LQ Newbie
Registered: May 2013
Location: New Zealand
Distribution: Debian (Wheezy)
Posts: 3

Rep: Reputation: Disabled
When moving items from my thumb drive to my OSMC system, I've found the following very useful:
find /media/AcornBBCnut\ 16GB/ -name '*' -exec mv -v {} /media/External\ HDD/Videos/ \;
I can't remember where I got it from, so I can't answer any questions about it, however, it works!

BTW, Don't forget to add a backslash before any spaces in the source or destination directory names (see above).

Anyway, that's my 2 cents worth.



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

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

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