1848169 Members
5638 Online
104022 Solutions
New Discussion

Re: Linux cp -u

 
SOLVED
Go to solution
Liad Orr
New Member

Linux cp -u

I'm trying to port a script from linux to HP-UX.
cp -u on linux means copy only when the SOURCE file is newer than the destination file, and there isn't such option on HP-UX.
I there a solution such as a third party cp or anything else?
10x
7 REPLIES 7
Raj D.
Honored Contributor

Re: Linux cp -u

Hi Liad,

hpux cp command doensnt have the -u option.
You have to take help of script to do that, you can use find command, with mtime ctime to do that.

cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Orhan Biyiklioglu
Respected Contributor

Re: Linux cp -u

Since there is no -u option in hpux cp command you have to compare the files yourself.

Something like:

if [ sourcefile -nt destfile ]
then
cp sourcefile destfile
fi

should do the job.

hth
Orhan Biyiklioglu
Respected Contributor

Re: Linux cp -u

Excerpt from the ksh manual

file1 -nt file2 True if file1 exists and is newer than file2.

file1 -ot file2 True if file1 exists and is older than file2.

hth
Sergejs Svitnevs
Honored Contributor

Re: Linux cp -u

find -name -newer / -depth -exec cp -p / / \;

Regards,
Sergejs
Andrew Merritt_2
Honored Contributor

Re: Linux cp -u

You could also use cpio, which by default only copies over a newer file.

It depends on how the files to be copied are currently specified exactly what you'll need to do.

e.g., assuming you want to copy all the files below a certain directory:

cd
find . -depth -print | cpio -pdma

Andrew
Arunvijai_4
Honored Contributor
Solution

Re: Linux cp -u

You can try installing GNU's cp which is part of coreutils,

http://hpux.connect.org.uk/hppd/hpux/Gnu/coreutils-5.2.1/

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Liad Orr
New Member

Re: Linux cp -u

Thanks everyone.
The script solutions are quite wise, however the coreutils is the best solution for me.
10x
Liad