LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2008, 11:56 PM   #1
vl.yc.lw
LQ Newbie
 
Registered: Dec 2008
Posts: 1

Rep: Reputation: 0
Question C-shell question


How do you use cp to copy recursively from a directory to another. The directory that I am copying from has multiple different directories underneath it, that is each directory has directories inside it. Now, I want to copy some select files from a directory.
I am trying to use:
cp -rv directory destination - but this gives me all the files
if I use:
cp -rv directory/*.txt destination - this will only give me the .txt files that are under directory.

What I want is all the .txt files that are under every directory.

Anyone can help?
Thank you very much!

Sorry there are too many "directories"
 
Old 12-14-2008, 12:19 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I'd use tar -c $( find -type f -name 'pattern' ) | tar -xC destination.
ta0kira

PS This needs to be done from the relevant directory because it will create every directory between the file and the current working directory in the destination. In other words, copying /home/you/file will create dest/you/file if called from /home, but dest/home/you/file if called from /.

Last edited by ta0kira; 12-14-2008 at 12:26 AM.
 
Old 12-14-2008, 01:32 AM   #3
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
You can also use rsync to grab those files, for example, to get all the text files (ending in ".txt"):

Code:
rsync -r -f "+ */" -f "+ *.txt" -f "- *" tmp/ temp/
Where "tmp" is the source directory, and "temp" is the destination (it will copy from the source dir, not the source dir itself)

Last edited by SciYro; 12-14-2008 at 01:34 AM.
 
  


Reply



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
shell question Rob Pijpers Linux - Newbie 4 08-16-2006 02:12 AM
Shell question satimis Linux - General 5 08-11-2005 09:57 AM
shell question supervillan Linux - Newbie 4 10-20-2004 06:50 AM
c(++) shell question karlan Programming 3 09-14-2003 04:07 AM
question about shell jaylee Linux - General 8 06-22-2003 09:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:58 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
Open Source Consulting | Domain Registration