3

I want to copy only when the SOURCE file is newer than the destination file or when the destination file is missing. As you know, this feature will work on Linux system on following command.

cp -u /source/*.txt /destination/  

but when i am using this command on solaris system 10. Below is my outut:

cp: illegal option -- u
Usage: cp [-f] [-i] [-p] [-@] f1 f2
cp [-f] [-i] [-p] [-@] f1 ... fn d1
cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn 

Is there any solution?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Wasila
  • 113

3 Answers3

3

cp -u is a feature of GNU coreutils, which is the standard on non-embedded Linux but not on Solaris.

On Solaris or any other POSIX-compliant system¹, you can use pax, which has similar functionality. The pax command is POSIX's replacement for the historical cpio and tar commands; in its pass-through mode, it's similar to cp -R. The -u option is similar to that of GNU cp (they both took it from historical archivers such as tar and ar).

cd /source
pax -rw -u *.txt /destination

(Not pax -rw -u /source/*.txt /destination, because that would create /destination/source/file.txt)

¹ Beware that many Linux distributions omit pax from the default installation. It's always available as a package however.

jlliagre
  • 61,204
2

You might use rsync -u which provides the same functionality. It is available on the current Solaris release (11.x) and also in the last Solaris 10 one (Oracle Solaris 10 1/13).

The source code of the Solaris 10 one is included in the full open source code bundle downloadable from here (beware that it's a 1 GB file).

jlliagre
  • 61,204
  • I am facing problem installing RSYNC Solaris 10. I have asked another question about the procedure. Subject line: RSYNC installation procedure on Solaris 10.

    any other solution rather than RSYNC/ CP -u?

    – Wasila Jan 27 '16 at 09:55
  • Thanks jilliagre. I will let you know if your link solve my problem. – Wasila Jan 28 '16 at 03:05
  • Beware recompiling is the hard way if you aren't familiar doing it. I would suggest you to consider Gilles' answer as it doesn't require any new software installation. – jlliagre Jan 28 '16 at 03:10
  • Ok sure jilliagre. I will go with Gilles solution. – Wasila Jan 28 '16 at 03:30
0

You are on a rather old Solaris there. Anyways as others have pointed out the -u option is something 'invented' in GNU, so you would have to use the GNU version of cp. This is done by installing GNU coreutils and then explicitly referencing gcp on your command line. Your example would become

gcp -u /source/*.txt /destination/

How this can be installed can be found here, but if your SysAdm had done his job it would have been there already (that's just my personal opinion :-))

peterh
  • 922