LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-09-2010, 07:47 PM   #1
jsmith54
LQ Newbie
 
Registered: Aug 2010
Posts: 1

Rep: Reputation: 0
Copying jpegs recursively while preserving the directory structure


So I have a bunch of directories:

dir1
dir2
dir3
etc.

which themselves all contain subdirectories:

dir1
subdir1
subdir2
etc.
and at the lowest level they contain all of these jpegs that I need. The problem is that I only need some of them. They're named like this:

pic1.jpg
pic1_med.jpg
pic1_small.jpg
pic2.jpg
pic2_med.jpg
etc.

I want to just grab the ones without the size suffix and copy them all to another set of folders, while preserving the directory structure. The numbering all starts at 1 for each low level subdirectory, so I think that the directory structure is the only way to not get them mixed up.

I know that cp has a recursive option -r but how do I just extract the ones without the underscore? And then how do I preserve the directory structure when I move them over?
 
Old 08-09-2010, 08:17 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
find

Code:
find . -type f -regextype posix-extended -regex ".*pic[0-9]+\.jpg" -exec cp -p --parents "{}" /TARGET/PATH/ \;
The above should work; run it from the top of the source tree - it will recursively copy the pictures matching filename of "pic" followed by "number(s)" ending with ".jpg", with no underscore/extension, and create the target directory tree as the source was.

I tested it - and it works for me - but as with anything free, no guarantee!

Cheers,
Sasha

PS - I encourage you to read the manpages for `cp` and `find` and understand the options I used.

Last edited by GrapefruiTgirl; 08-09-2010 at 08:19 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to recursively delete *.xtension files from a directory structure kpachopoulos Linux - General 6 08-24-2008 09:53 AM
Problem in copying directory structure agogoaye Linux - Newbie 9 07-02-2008 05:44 AM
copying a directory and preserving links? sinc Linux - Newbie 1 07-01-2005 07:01 AM
copying directory structure in FTP malaka56 Linux - Software 2 05-14-2005 08:04 PM
Preserving directory tree structure /etc/fstab Hikito Linux - Newbie 1 09-11-2004 05:07 PM


All times are GMT -5. The time now is 08:42 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration