LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-24-2003, 01:18 PM   #1
mizuki
LQ Newbie
 
Registered: May 2003
Posts: 4

Rep: Reputation: 0
Question how to cp filestructure for specific file pattern


hi,
think that's a simple one:

how can i copy a a filestructure recursively for files matching a specific pattern like *.java -> copy all javafiles from that dir + subdirs and create the same dirstructure at the destination...d'you know what i mean?

thanx mizuki
 
Old 05-24-2003, 03:00 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
I don't know of a way to do it without writing a script but you could copy the folder then remove everything else.
 
Old 05-24-2003, 03:06 PM   #3
mizuki
LQ Newbie
 
Registered: May 2003
Posts: 4

Original Poster
Rep: Reputation: 0
hmm

if i would copy the whole structure i would overwrite also files that are not *.java. that's what i want to avoid. i want to copy only the java files recursively from one structure to another. both file structures looking the same. i just want to "update" the java files in that structure. any idea?
 
Old 05-24-2003, 03:09 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
Ok folder1 has the .java files you want and folder3 is where you want the files to end up.
1) copy folder1 to folder2
2) remove all non .java files
3) move folder2s contents to folder3
 
Old 05-24-2003, 03:40 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
find . -name *java | cpio -pvd /destination/directory

you could probably rearrange the command to allow you to copy from somewhere else than the current directory, but that will then use absolute paths, and so create leading directories all the way back to /, not just the current directory:
Code:
chris@trevor mail $ find .
.
./sent-mail
./saved-messages
./sent-mail-apr-2003
chris@trevor mail $ find /home/chris/mail/
/home/chris/mail/
/home/chris/mail/sent-mail
/home/chris/mail/saved-messages
/home/chris/mail/sent-mail-apr-2003

Last edited by acid_kewpie; 05-24-2003 at 03:44 PM.
 
Old 05-24-2003, 03:58 PM   #6
mizuki
LQ Newbie
 
Registered: May 2003
Posts: 4

Original Poster
Rep: Reputation: 0
thanx

sounds good...
i think that will work.
thank you.
 
  


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
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 07:17 AM
pattern file with no return character ksun Linux - Newbie 1 12-28-2004 07:40 PM
rename file with a pattern sujith_deva Programming 7 12-16-2004 08:39 PM
Grep pattern first line of a file ericcarlson Linux - Newbie 11 07-20-2004 11:51 AM
multiline pattern search in a file mimi Linux - General 1 09-01-2002 01:22 PM


All times are GMT -5. The time now is 10:49 PM.

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