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?

6
  • Don't think you can. Commented Jan 27, 2016 at 9:47
  • is there any way out? Commented Jan 27, 2016 at 9:48
  • If your shell supports the if [ "$src" -nt "$dst ]; then … construct you can use that one (however, not it's not in POSIX). Do you have pax or rsync available? That might be the easiest solution. Commented Jan 27, 2016 at 9:55
  • I haven't tried pax yet. But I am unable to install rsync on my solaris system Commented Jan 27, 2016 at 10:00
  • 1
    "cp" on Linux is usually from the GNU coreutils which are also available for Solaris - can you build & install software like that on your Solaris machine or are your privileges limited? Commented Jan 27, 2016 at 16:37

3 Answers 3

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.

1
  • Thanks Gilles. It works. cd /source pax -rw -u *.txt /destination Commented Jan 28, 2016 at 3:02
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).

4
  • 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? Commented Jan 27, 2016 at 9:55
  • Thanks jilliagre. I will let you know if your link solve my problem. Commented Jan 28, 2016 at 3: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. Commented Jan 28, 2016 at 3:10
  • Ok sure jilliagre. I will go with Gilles solution. Commented Jan 28, 2016 at 3: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 :-))

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.