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.
Asked
Active
Viewed 1,806 times
2 Answers
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
-
Thanks Guru.Is there any other way we can do? – user1929905 Jan 02 '13 at 12:35
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