Sponsored Content
Top Forums Shell Programming and Scripting copy only newer files? (xcopy equivalent) Post 91350 by Chomps on Thursday 1st of December 2005 09:36:51 AM
Old 12-01-2005
copy only newer files? (xcopy equivalent)

Howdy folks.

I have a problem - I'm sure the answer is very simple, but I can't work it out.

I want to create a UNIX shell script that does what I've been doing in DOS batch files for years - that is, backing up files. By which I mean copying files from a source directory to a target directory, only if a) the file doesn't exist at the target, or b) the file does exist but is older than the source.

In DOS, I did something like this:

xcopy c:\path\directory\*.* x:\backup\ /d /e

Where x was a networked drive, /d meaning only copy files newer than the target, /e meaning recurse into subdirectories.

In UNIX, I'm close but no cigar yet... I have the following:

cp -r /testdir/source/ /testdir/target/

This works in that it copies files, leaving the originals behind and recursing into subdirectories, but it doesn't only copy source files if they're newer than the target. It copies eveything.

I have read in a few different places that cp accepts the -u ('update' I think) option, to make it only copy newer files, but I can't get this to work. If I write cp -u, I am told that 'u' is an 'illegal option' for cp.

So, is there a way to get the behviour I'm after? Am I right to be using cp, or is there a better function to do what I want?

Doing all this on Mac OS 10.3.9, using the terminal, tcsh.

Very grateful for any help.

Cheers.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

tar --newer = tar --newer-mtime ?

Hi, I have the following question : As far as I know unix doesn't store file creation dates. Would that imply the following? tar -cvzf backup.tar --newer is equal to: tar -cvzf backup.tar --newer-mtime ? (1 Reply)
Discussion started by: jamesbond
1 Replies

2. UNIX for Dummies Questions & Answers

Find files newer than...

Is there a way to use the find command to locate files newer than a specific date? Thanks! --Alex (4 Replies)
Discussion started by: vertigo23
4 Replies

3. Solaris

To copy the files newer than specific date

Dear all, Can you help me in copying files newer than speciifc date Thanks in advance, Rajesh (3 Replies)
Discussion started by: RAJESHKANNA
3 Replies

4. UNIX and Linux Applications

sftp -> put : How to uplaod only newer files

I have tried winscp, filezilla to copy data from windows xp SP2 machine to the sun sparc unix machine. However speed is around 120 to 130 kb/sec. I do have lot of files & with large size. So I switched to windows command prompt & transfered few files using sftp command. Its very fast as compared... (0 Replies)
Discussion started by: _prasad
0 Replies

5. Shell Programming and Scripting

cp work as xcopy.

Actually i want to copy some file locations to another. so if directory not exist it should create that. i used cp -R/r but it copies only one directory. it doesnt make directory inside directory.. so i want this should create them automatically. One more thing if file already exist there... (8 Replies)
Discussion started by: ajayyadavmca
8 Replies

6. Shell Programming and Scripting

Copy newer files without create

I want the same effect as "cp -u" but without create missing files, it is possible ? ps: bash (2 Replies)
Discussion started by: mrxrsd
2 Replies

7. Solaris

How to safely copy full filesystems with large files (10Gb files)

Hello everyone. Need some help copying a filesystem. The situation is this: I have an oracle DB mounted on /u01 and need to copy it to /u02. /u01 is 500 Gb and /u02 is 300 Gb. The size used on /u01 is 187 Gb. This is running on solaris 9 and both filesystems are UFS. I have tried to do it using:... (14 Replies)
Discussion started by: dragonov7
14 Replies

8. UNIX for Dummies Questions & Answers

Find files newer than x days

We had an arrant rsync run and started copying over new files from one system to another. Although this is what we will want to do at some point, for now, we want to maintain the system as it was a few days ago. I am looking for a script that will find files that are newer than x days. ... (5 Replies)
Discussion started by: Leyva62
5 Replies

9. Shell Programming and Scripting

ls files newer than 6 hours

How do I list al files in a folder with a creation date/time newer than 6 hours? (2 Replies)
Discussion started by: locoroco
2 Replies

10. Shell Programming and Scripting

Copy file only if newer

I only want the file copied if it is newer. But it still copies the file? zip -u Ubuntu_Documents.zip ./* cp -u Ubuntu_Documents.zip $DOCS_Backup/Ubuntu_Documents_`date +"%Y-%m-%d-%H-%M"`.zip (5 Replies)
Discussion started by: drew77
5 Replies
mkmanifest(1)						      General Commands Manual						     mkmanifest(1)

NAME
mkmanifest - mtools utility to create a shell script to restore UNIX file names from DOS SYNOPSIS
mkmanifest [files] OPTIONS
None OPERANDS
A list of UNIX file names to be converted to DOS name format. DESCRIPTION
The mkmanifest command creates a shell script that aids in the restore of UNIX file names that were overwritten by DOS file name restric- tions. DOS file names are uppercase only, cannot exceed 8 character names, 3 character extensions and do not support device names or non- alphanumeric characters. Not all UNIX file names are supported in the DOS world. The mtools commands may have to change UNIX names to fit the DOS file name conven- tions. Most commands provide the verbose option (-v), that displays new file names if they have been changed. The following table shows some examples of file name conversions: ----------------------------------------------- UNIX name DOS name Reason for the change ----------------------------------------------- thisisatest THISISAT file name too long file.stuff FILE.STU extension too long prn.txt XRN.TXT PRN is a device name .abc X.ABC null file name hot+cold HOTXCOLD illegal character ----------------------------------------------- EXIT STATUS
The following exit values are returned: Success. Failure. EXAMPLES
Assume you have the following UNIX files that you want to copy to a DOS diskette using the mcopy command. very_long_name 2.many.dots illegal: good.c prn.dev Capital The mcopy command converts these file names to the following: very_lon 2xmany.dot illegalx good.c xprn.dev capital To restore the previous file names, use the mkmanifest command as follows: mkmanifest very_long_name 2.many.dots illegal: good.c prn.dev Capital > manifest The previous mkmanifest command line produces the following: mv very_lon very_long_name mv 2xmany.dot 2.many.dots mv illegalx illegal: mv xprn.dev prn.dev mv capital Capital The good.c file name did not require conversion, hence it was not included in the output. If these files were copied from diskette to another UNIX system, and you wanted to restore the original names, retain a copy of the mani- fest file (captured output) so that it can be used to convert the file names again. FILES
Executable file SEE ALSO
Commands: mcopy(1), mtools(1) mkmanifest(1)
All times are GMT -4. The time now is 10:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy