-1

when i use mv command in aix to move a file to a destination directory ,it should fail if another file with the same name exists in that destination. But what happens now is it replaces the file in destination. Pls help.Is there any other command should i use or how should i use mv command.

user1929905
  • 389
  • 3
  • 9
  • 25

2 Answers2

1

Something like this:

$ TDIR="/home/xyz"
$ FILE="f1"
$ [ -f $TDIR/$FILE ] || mv $FILE $TDIR/$FILE

This will move the file named f1 only if it is not present in the target directory

Guru
  • 16,456
  • 2
  • 33
  • 46
0

Many versions of mv support a -n option. To be fully portable, you can do:

echo no | mv -i a b

If you are moving multiple files, you can do:

yes no | mv -i a b target-dir
William Pursell
  • 204,365
  • 48
  • 270
  • 300