Solved Backup (-b) option in mv

Hi
I am trying to port some of my Linux scripts to my FreeBSD. In this regard, one of my scripts, the "mv" command uses (-b) option to make a backup of existing file in destination directory (instead of overwriting it). For instance, if the destination directory contains a file named "foo", so the script will rename it to "foo~" and then move the source file to destination.
I am looking for same functionality in "mv" in FreeBSD, however, the manpage of "mv" does not give any such option (to backup the original file). The closest I can get is "-i" option which prompts for overwriting, but it does not fulfill my objective. Maybe one way is to add a line something like:
Code:
if [  -f $1 ] then mv $1 $1~
But, I was wondering that whether it is possible to get this "backup creation" functionality in "mv" in FreeBSD?
Thanks
 
Not related to the question but you need to quote your variables. If you have a filename with a space in it things will go haywire.

In this regard, one of my scripts, the "mv" command uses (-b) option to make a backup of existing file in destination directory (instead of overwriting it).
That option seems to be specific to GNU's mv.
 
-b is a non-standard option, it’s only supported by GNU mv (used by Linux).

The simplest and quickest solution is to install sysutils/coreutils. It contains a collection of GNU utilities, including mv. In order to not confuse them with the utilities of the same name that belong to FreeBSD’s base system, the GNU utilities are installed with the prefix letter g. So you just have to replace mv with gmv in your scripts, or put the line alias mv=gmv at the beginning.
 
-b is a non-standard option, it’s only supported by GNU mv (used by Linux).

The simplest and quickest solution is to install sysutils/coreutils. It contains a collection of GNU utilities, including mv. In order to not confuse them with the utilities of the same name that belong to FreeBSD’s base system, the GNU utilities are installed with the prefix letter g. So you just have to replace mv with gmv in your scripts, or put the line alias mv=gmv at the beginning.
It solved the problem. Thanks :)
 
Back
Top