Copy files from multiple directories into one directory without overwriting them


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy files from multiple directories into one directory without overwriting them
# 1  
Old 08-27-2011
Copy files from multiple directories into one directory without overwriting them

I have several directories and all those directories have .dat files in them. I want to copy all those .dat files to one directory say "collected_directory"

The problem is I don't want to overwrite files. So, if two file names match, I don't want the old file to be overwritten with a new one.

I know how to copy files from multiple directories to one directory:

Code:
find <start directory> -iname "<all my file_type>" -exec cp {} <target_dir> \;

But how to handle the case where no overwrite occurs rather the same file names get a new name like abc_1.dat if abc.dat already exists in "collected_directory"?

I am using Linux with BASH.
# 2  
Old 08-27-2011
The GNU version of cp has the -n (do not overwrite an existing file) option.
This User Gave Thanks to radoulov For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy particular files from a multiple directories and paste in a new directory?

Dear all I have a multiple directories, say for example org1, org2, org3 ..... org100 and each directory having a file namely dnaG.fasta. I need to copy all the dnaG.fasta file from each directory and paste in another directory fastconcatg. Therefore, my script has to copy dnaG.fasta file from... (5 Replies)
Discussion started by: dineshkumarsrk
5 Replies

2. Shell Programming and Scripting

Compare directories and copy differences (files) in a another directory

Hey im working on script that can compare 2 directory and check difference, then copy difference files in third diretory. here is the story: in folder one we have 12 subfolder and in each of them near 500 images hosted. 01 02 03 04 05 06 07 08 09 10 11 12 in folder 2 we have same subfolder... (2 Replies)
Discussion started by: nimafire
2 Replies

3. Shell Programming and Scripting

Rename files from multiple directories along with directory indicator

Hi, Friends, i have a requirement where i need to rename my files residing in multiple sub directories and move them to one different directory along with some kind of directory indicator. For eg: test--is my parent directory and it has many files such as a1.txt a2.txt a3.txt ... (5 Replies)
Discussion started by: gnnsprapa
5 Replies

4. Filesystems, Disks and Memory

Slow copy (cp) performance when overwriting files

I have a lot of binary files I need to copy to a folder. The folder is already filled with files of the same name. Copying on top of the old files takes MUCH longer than if I were to delete the old files then copy the new files to the now-empty folder. This result is specific to one system -... (3 Replies)
Discussion started by: ces55
3 Replies

5. Shell Programming and Scripting

Copy files/directories excluding multiple paterns

my directory structure is like below: basedir\ p.txt q.htm r.java b\ abc.htm xyz.java c\ p.htm q.java rst.txt my requirement is i want to copy all the files and directories... (0 Replies)
Discussion started by: ajayyadavmca
0 Replies

6. UNIX for Advanced & Expert Users

FTP failed to copy mulitple files from multiple directory

I am using below scripts to copy all the files from multiple folders. By executing individually command i am able to copy all the files but using scripts only getting first file. System is ignoring the second CD and mget command. HOST=server.com USER=loginid PASSWD="abc" echo "open $HOST... (6 Replies)
Discussion started by: meetvipin
6 Replies

7. Shell Programming and Scripting

Copy one folder to multiple directories

Hello, I have a small question and i hope someone can help me, if i have 200 domains directories in my server under this directory something like now how i can copy one folder i have to this directories? Thank You (5 Replies)
Discussion started by: GamGom
5 Replies

8. Shell Programming and Scripting

copy files using scp without overwriting

Hi, i need to use "scp" to copy a file without overwriting the same in destinations. any suggestion? thanks Sivaji (3 Replies)
Discussion started by: sivarajb
3 Replies

9. UNIX for Dummies Questions & Answers

Renaming files after their directory name in multiple sub directories

So I am not sure if this should go in the shell forum or in the beginners. It is my first time posting on these forums. I have a directory, main_dir lets say, with multiple sub directories (one_dir through onehundred_dir for example) and in each sub directory there is a test.txt. How would one... (2 Replies)
Discussion started by: robotsbite
2 Replies

10. UNIX for Dummies Questions & Answers

copy multiple files in different directories

I have a report file that is generated every day by a scheduled process. Each day the file is written to a directory named .../blah_blah/Y07/MM-DD-YY/reportmmddyy.tab I want to copy all of this reports to a separate directory without having to do it one by one. However, if I try cp... (3 Replies)
Discussion started by: ken2834
3 Replies
Login or Register to Ask a Question