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
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
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
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
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
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
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
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
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
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
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
mcopy(1) General Commands Manual mcopy(1)
Name
mcopy - copy MSDOS files to/from Unix
Note of warning
This manpage has been automatically generated from mtools's texinfo documentation, and may not be entirely accurate or complete. See the
end of this man page for details.
Description
The mcopy command is used to copy MS-DOS files to and from Unix. It uses the following syntax:
mcopy [-bspanvmQT] [-D clash_option] sourcefile targetfile
mcopy [-bspanvmQT] [-D clash_option] sourcefile [ sourcefiles... ] targetdirectory
mcopy [-tnvm] MSDOSsourcefile
Mcopy copies the specified file to the named file, or copies multiple files to the named directory. The source and target can be either
MS-DOS or Unix files.
The use of a drive letter designation on the MS-DOS files, 'a:' for example, determines the direction of the transfer. A missing drive
designation implies a Unix file whose path starts in the current directory. If a source drive letter is specified with no attached file
name (e.g. mcopy a: .), all files are copied from that drive.
If only a single, MS-DOS source parameter is provided (e.g. "mcopy a:foo.exe"), an implied destination of the current directory (`.') is
assumed.
A filename of `-' means standard input or standard output, depending on its position on the command line.
Mcopy accepts the following command line options:
t Text file transfer. Mcopy translates incoming carriage return/line feeds to line feeds when copying from Dos to Unix, and vice-
versa when copying from Unix to Dos.
b Batch mode. Optimized for huge recursive copies, but less secure if a crash happens during the copy.
s Recursive copy. Also copies directories and their contents
p Preserves the attributes of the copied files
Q When mcopying multiple files, quits as soon as one copy fails (for example due to lacking storage space on the target disk)
a Text (Ascii) file transfer. Mcopy translates incoming carriage return/line feeds to line feeds.
T Text (Ascii) file transfer with charset conversion. Differs from -a in the Mcopy also translates incoming PC-8 characters to
ISO-8859-1 equivalents as far as possible. When reading DOS files, untranslatable characters are replaced by '#'; when writing DOS
files, untranslatable characters are replaced by '.'.
n No confirmation when overwriting Unix files. Mcopy doesn't warn the user when overwriting an existing Unix file. In order to
switch off confirmation for DOS files, use -o.
m Preserve the file modification time. If the target file already exists, and the -n option is not in effect, mcopy asks whether to
overwrite the file or to rename the new file (`name clashes') for details).
v Verbose. Displays the name of each file as it is copied.
Bugs
Unlike MS-DOS, the '+' operator (append) from MS-DOS is not supported. However, you may use mtype to produce the same effect:
mtype a:file1 a:file2 a:file3 >unixfile
mtype a:file1 a:file2 a:file3 | mcopy - a:msdosfile
See Also
Mtools' texinfo doc
Viewing the texi doc
This manpage has been automatically generated from mtools's texinfo documentation. However, this process is only approximative, and some
items, such as crossreferences, footnotes and indices are lost in this translation process. Indeed, these items have no appropriate repre-
sentation in the manpage format. Moreover, not all information has been translated into the manpage version. Thus I strongly advise you
to use the original texinfo doc. See the end of this manpage for instructions how to view the texinfo doc.
* To generate a printable copy from the texinfo doc, run the following commands:
./configure; make dvi; dvips mtools.dvi
* To generate a html copy, run:
./configure; make html
A premade html can be found at: `http://mtools.linux.lu' and also at: `http://www.tux.org/pub/knaff/mtools'
* To generate an info copy (browsable using emacs' info mode), run:
./configure; make info
The texinfo doc looks most pretty when printed or as html. Indeed, in the info version certain examples are difficult to read due to the
quoting conventions used in info.
mtools-3.9.8 02Jun01 mcopy(1)