1.\" $OpenBSD: mv.1,v 1.22 2007/05/31 19:19:15 jmc Exp $ 2.\" $NetBSD: mv.1,v 1.8 1995/03/21 09:06:51 cgd Exp $ 3.\" 4.\" Copyright (c) 1989, 1990, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" This code is derived from software contributed to Berkeley by 8.\" the Institute of Electrical and Electronics Engineers, Inc. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)mv.1 8.1 (Berkeley) 5/31/93 35.\" 36.Dd $Mdocdate: May 31 2007 $ 37.Dt MV 1 38.Os 39.Sh NAME 40.Nm mv 41.Nd move files 42.Sh SYNOPSIS 43.Nm mv 44.Op Fl fi 45.Ar source target 46.Nm mv 47.Op Fl fi 48.Ar source ... directory 49.Sh DESCRIPTION 50In its first form, the 51.Nm 52utility renames the file named by the 53.Ar source 54operand to the destination path named by the 55.Ar target 56operand. 57This form is assumed when the last operand does not name an already 58existing directory. 59.Pp 60In its second form, 61.Nm 62moves each file named by a 63.Ar source 64operand to a destination specified by the 65.Ar directory 66operand. 67It is an error if the 68.Ar directory 69operand does not exist. 70The destination path for each 71.Ar file 72operand is the pathname produced by the concatenation of the 73.Ar directory 74operand, a slash, and the final pathname component of the named file. 75.Pp 76The options are as follows: 77.Bl -tag -width Ds 78.It Fl f 79Do not prompt for confirmation before overwriting the destination 80path. 81.It Fl i 82Causes 83.Nm 84to write a prompt to standard error before moving a file that would 85overwrite an existing file. 86If the response from the standard input begins with the character 87.Dq y , 88the move is attempted. 89.El 90.Pp 91The last of any 92.Fl f 93or 94.Fl i 95options is the one which affects 96.Nm mv Ns 's 97behavior. 98.Pp 99If the destination path does not have a mode which permits writing, 100.Nm 101prompts the user for confirmation as specified for the 102.Fl i 103option. 104.Pp 105As the 106.Xr rename 2 107call does not work across file systems, 108.Nm 109uses 110.Xr cp 1 111and 112.Xr rm 1 113to accomplish the move. 114The effect is equivalent to: 115.Bd -literal -offset indent 116$ rm -f destination_path && \e 117 cp -PRp source_file destination && \e 118 rm -rf source_file 119.Ed 120.Pp 121.Ex -std mv 122.Sh EXAMPLES 123Rename file 124.Pa foo 125to 126.Pa bar , 127overwriting 128.Pa bar 129if it already exists: 130.Pp 131.Dl $ mv -f foo bar 132.Pp 133Either of these commands will rename the file 134.Pa -f 135to 136.Pa bar , 137prompting for confirmation if 138.Pa bar 139already exists: 140.Bd -literal -offset indent 141$ mv -i -- -f bar 142$ mv -i ./-f bar 143.Ed 144.Sh SEE ALSO 145.Xr cp 1 , 146.Xr symlink 7 147.Sh STANDARDS 148The 149.Nm 150utility is compliant with the 151.St -p1003.1-2004 152specification. 153.Sh HISTORY 154A 155.Nm 156command appeared in 157.At v1 . 158.Sh CAVEATS 159In the second synopsis form 160if the destination path exists, 161the 162.Ar source 163operand and the destination path 164must both be a file or must both be a directory 165for the operation to succeed. 166For example, if 167.Pa f 168is a file and 169.Pa d 170and 171.Pa d/f 172are directories, the following command will fail: 173.Pp 174.Dl $ mv f d 175