LinuxQuestions.org
Help answer threads with 0 replies.
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 02-21-2011, 09:00 AM   #1
mahmoodn
Member
 
Registered: May 2010
Posts: 409

Rep: Reputation: 16
copying files from multiple locations to one destination


suppose I have a tree structure like this:
/home/mahmood/sim/a/b/file1.cpp
/home/mahmood/sim/a/b/file2.h
/home/mahmood/sim/a/c/file3.txt
/home/mahmood/sim/d/file4.txt

How can I copy all of them to /home/mahmood/sim. So that when I run "ls" in /home/mahmood/sim, I see all files:
file1.cpp
file2.h
file3.txt
file4.txt

Can 'cp' search for all file and copy them in another folder?
 
Old 02-21-2011, 09:18 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Nope. cp haven't got searching capabilities, it can only use patterns (globbing) that will be expanded by the shell. Anyway you can use find to look for files and apply an action to every file found, e.g.
Code:
find /home/mahmood/sim -type f -exec echo cp -p {} /home/mahmood/sim \;
The echo statement is for testing purposes: the commands will be printed out without being actually executed. Just to review the results before doing the copy. Furthermore you may consider to move or link the files (instead of copying them) to avoid duplicates. Hope this helps.
 
Old 02-21-2011, 09:22 AM   #3
coolsreejith
LQ Newbie
 
Registered: Oct 2010
Distribution: CentOS 5.5
Posts: 23

Rep: Reputation: 2
you can use the command

find /home/mahmood/sim/ -name file* -exec cp {} /home/mahmood/sim/ \;
 
Old 02-21-2011, 09:33 AM   #4
mahmoodn
Member
 
Registered: May 2010
Posts: 409

Original Poster
Rep: Reputation: 16
Thanks it works fine
 
  


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
copy files from one source to multiple destination simultaneously mdfakkeer Linux - Software 3 08-10-2010 03:25 PM
copy files from one source to multiple destination simultaneously mdfakkeer Programming 7 08-06-2010 07:05 AM
Copy files from various locations to a single destination folder deostroll Linux - Newbie 5 05-13-2009 06:52 AM
Copying single file to multiple locations Ashiro Linux - Server 4 12-05-2008 05:50 AM
Copying Files from one source to a destination vgdeveloper05 Programming 1 12-10-2006 02:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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