How to find and copy files from one directory to another


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to find and copy files from one directory to another
# 1  
Old 11-21-2009
How to find and copy files from one directory to another

Ok i have three directories

Destination - /u/dir1 (has subdirectories dir2 which also has subdirectory dir3)

Source1 - /u/test/files/dir1/dir2/dir3
Source2 - /u/out/images/dir1/dir2/dir3


What i would like to do is copy everything from Source1 and Source2 into the Destination directory. The only thing is the directories on Source1 and Source2 differ slightly with the Destination directory. I only want to copy "dir1" recursively from source1 and source2 to "dir1" in the destination directory.

i tried something like this but i am failing miserably

Code:
cd /u
find ./test/files/dir1 ./out/images/dir1 -print | cp dir1

I think the problem is whenever i use find or ls, the directories i dont want to include (test/files and out/images) are also included which is making it difficult to copy it to the exact equivalent location on the destination diretory.

by the way the os i am using is "SunOS 5.9 Generic_122300-13 sun4u sparc SUNW,Sun-Blade-1500"

Any ideas?

Thanks
# 2  
Old 11-21-2009
To copy files or folders recursively use -R parameter. -R means Recursively. You also can use /test/files/dir1/* to copy all files that are located in dir1

Cheers.
# 3  
Old 11-21-2009
try:

Code:
tar cvf - /u/test/files/dir1/dir2/dir3 /u/out/images/dir1/dir2/dir3 | ( cd /u/dir1; tar xvf -)

# 4  
Old 11-21-2009
Hi thanks guys.

Is it possible to do it using the find command or any other command that will allow to copy files of a specific size?

I know how to do it using the cp -R option i.e. cp -r /src /dest
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find most recent file and copy to another directory.

Very new to shell scripting. Not sure if my title is correct but I will try and explain. Directory has 100+ files with this format, " ABCD_ABC_Abc_AB0126.abc ". When a new file gets created, the 16-19 characters in the file name gets incremented by 1. Ex...todays most recent file is... (14 Replies)
Discussion started by: askvip
14 Replies

2. Shell Programming and Scripting

Copy the files in directory and sub folders as it is to another directory.

How to copy files from one directory to another directory with the subfolders copied. If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*. I do not want to create sub folders in folder2. Can copy command create them automatically? I tried cp -a and cp -R but did... (4 Replies)
Discussion started by: santosh2626
4 Replies

3. Shell Programming and Scripting

Find and copy these files to particular directory

RedHat Enterprise Linux 5.4 I have some files with the extension .cdp in several directories in various mountpoints(filesystems) . I would like to find and copy all these files into a single directory /u03/diagnore/data. How can I do this ? (3 Replies)
Discussion started by: kraljic
3 Replies

4. Red Hat

Unable to copy files due to many files in directory

I have directory that has some billion file inside , i tried copy some files for specific date but it's always did not respond for long time and did not give any result.. i tried everything with find command and also with xargs.. even this command find . -mtime -2 -print | xargs ls -d did not... (2 Replies)
Discussion started by: before4
2 Replies

5. UNIX for Dummies Questions & Answers

Copy files into another directory

I have a folder will a lot of documents (pdf, xls, doc etc.) which users have uploaded but only 20% of them are currently linking from my html files. So my goal is to copy only the files which are linked in my html files from my Document directory into another directory. Eg: My documents exist... (5 Replies)
Discussion started by: ankitha
5 Replies

6. Shell Programming and Scripting

find and copy file to another directory..

Hi Everybody, i want a samll help to write a script. i had source location with :/user/bin (bin contains subdirectories with like names emails etc and had several files in each subdirectory) and target location with :/usr/scripts (having same subdirectories names and had some files)... (1 Reply)
Discussion started by: Reddy482
1 Replies

7. Shell Programming and Scripting

find list of files from a list and copy to a directory

I will be very grateful if someone can help me with bash shell script that does the following: I have a list of filenames: A01_155716 A05_155780 A07_155812 A09_155844 A11_155876 that are kept in different sub directories within my current directory. I want to find these files and copy... (3 Replies)
Discussion started by: manishabh
3 Replies

8. UNIX for Dummies Questions & Answers

Find & Copy Selected files to another Directory

I am wanting to find files within a directory that are over a certain number of days old and copy them to another directory. And unfortunately not having much luck.......is someone able to help. Would also like to add that there are literally thousands of files that I am wanting to copy in one... (3 Replies)
Discussion started by: hellfyre
3 Replies

9. Shell Programming and Scripting

shell script to find and copy the files creted in the year 2006 to another directory

Hi All, I am new to UNIX. I will be thankful if some one helps me. I have to write a shell script for one of the requirement. I have files created from Jan 2006 to March 2008. My requirement is to write a script in such a way that 1) To find and copy(not Moving) the files created in the... (2 Replies)
Discussion started by: manas6
2 Replies

10. Shell Programming and Scripting

find files and copy into a directory

hi all, can u please help me in finding all ksh file in directory and including all subdirectories and then copy those files into another directory. thanks in advance -bali (4 Replies)
Discussion started by: balireddy_77
4 Replies
Login or Register to Ask a Question