diff script to copy files to other dir when not exists


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting diff script to copy files to other dir when not exists
# 1  
Old 11-04-2011
diff script to copy files to other dir when not exists

I have two directories that are mostly the same:

dir1
dir2

Is there an easy way to take the output of diff and copy files from dir1 that do not exist in dir2 - but copy them to the same path (many nested directories).

am only trying to copy files in dir1 that do not exist in dir2.

thanks
# 2  
Old 11-04-2011
But what do you mean by:
Quote:
but copy them to the same path (many nested directories).
?
# 3  
Old 11-04-2011
GNU cp has the -u option:

Code:
   -u, --update
              copy only when the SOURCE file is newer than the destination file or when the destination file is miss-
              ing

It doesn't match exactly your requirement, of course.
# 4  
Old 11-04-2011
diff cp

I do not want to copy the entire directory.

I just want to copy only those files that exist in dir1 to dir2 with the same path.
any ideas or help there?

---------- Post updated at 01:58 PM ---------- Previous update was at 01:57 PM ----------

so if:

dir1/path1/path2/path3/file_exists.txt is here in dir1 but not dir2, then I want to copy file_exists.txt over to dir2 with the same path: like: dir2/path1/path2/path3/file_exists.txt

---------- Post updated at 01:59 PM ---------- Previous update was at 01:58 PM ----------

Quote:
Originally Posted by vbe
But what do you mean by:
?
so if:

dir1/path1/path2/path3/file_exists.txt is here in dir1 but not dir2, then I want to copy file_exists.txt over to dir2 with the same path: like: dir2/path1/path2/path3/file_exists.txt
# 5  
Old 11-04-2011
If you have rsync installed, you can go that route. It'll only copy new files in dir1 to dir2. Just cd into dir1 and run "rsync -avz --stats * /tmp/dir2" and it should only copy files that do not already exist in dir2.

Hope this helps.
# 6  
Old 11-04-2011
Quote:
Originally Posted by in2nix4life
If you have rsync installed, you can go that route. It'll only copy new files in dir1 to dir2. Just cd into dir1 and run "rsync -avz --stats * /tmp/dir2" and it should only copy files that do not already exist in dir2.

Hope this helps.
OK, I will try that. Also another requirement is that I want to skip certain meta-data directories like "CVS/". Is there a way to exclude a list of directories?

Also I do not want to copy files that differ, just files that do not exist in one, that do exist in the other. What flag controls this behaviour?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files to a dir using from a list

Hi all, I'd very grateful for some help with the following: I have a directory with several subdirectories with files in them. All files are named different, even between different subdirectories. I also have a list with some of those file names in a txt file (without the path, just the file... (5 Replies)
Discussion started by: foracoffee
5 Replies

2. Shell Programming and Scripting

files copy to dir

Hi, I have a directory which is having many files. I want to copy 10files at a time to another directory. For example. First 10 files to one directory, then next 10 files to another directory and so on. Please let me know if any work around there for it. Thanks (4 Replies)
Discussion started by: Anjan1
4 Replies

3. Shell Programming and Scripting

Copy files and subdirs from dir to a new dir

Hello Comunity I am trying to make a bash shell script that it copies files and subdirs(with files) to a new dir. I would like the dest_dir to contain only subdirectories with files not other subdirs inside. it called : cpflatdir src_dir dest_dir Pleaze help me! Thank you in... (2 Replies)
Discussion started by: BTKBaaMMM
2 Replies

4. Shell Programming and Scripting

Copy Files to Dir and Check If File Exists

Hi everyone. I am trying to write a bash script that will copy files from one directory to another but I need to be able to check the directory that I'm copying the files to and see if the file already exists. If it does I need to add a number at the end of the copied file. Thanks for your help. (3 Replies)
Discussion started by: snag49ers
3 Replies

5. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

6. Shell Programming and Scripting

How to copy specified files from list of files from dir A to dir B

Hello, fjalkdsjfkldsajflkajdskl (3 Replies)
Discussion started by: pmeesara
3 Replies

7. Shell Programming and Scripting

copy files from one dir to another

Hi , I want to copy files from one dir to anothe dir and check if destination dir exists ,if not exist ,has to create but when executing the below schell script ,the destination directory not exist and exit the shell script. #!/bin/sh src_path=/home/owngdw/abc tgt_path=/home/owngdw/abc/xyz if... (6 Replies)
Discussion started by: mohan705
6 Replies

8. UNIX for Advanced & Expert Users

copy diff files

I have to synchronize files on two machines, but these are not connected via LAN. Now I'm using DVD's to copy new data. The question is how can I create a list of files on one machine and having this list archive or copy only new files from other. Are there any standard tools like diff/patch for... (3 Replies)
Discussion started by: Hitori
3 Replies

9. UNIX for Dummies Questions & Answers

How to copy N files from one dir to another

Hi, I have a script that can only handLE limited number of input files. I need to be able to write a command (or a script) that: 1> copies N number of files from one directory (A) to another (B). 2> Files that are moved need to be renamed. 3> Files picked to be moved have... (1 Reply)
Discussion started by: GMMike
1 Replies

10. Shell Programming and Scripting

perl package directories - what if the script is diff DIR to the one contain *.pm?

Hi there, say the package is in the ~/ and it's ~/packageFoo.pm I can use usePackage.pl in ~/ (~/usePackage.pl). Now, if I move it to ~/subDIR/usePackage.pl, the script won't work because it's not in the same DIR with packageFoo.pm How can i fix it? Thanks Gusla (1 Reply)
Discussion started by: gusla
1 Replies
Login or Register to Ask a Question