xref: /openbsd/bin/mv/mv.1 (revision 3df326f4)
1.\"	$OpenBSD: mv.1,v 1.24 2008/10/21 06:42:45 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: October 21 2008 $
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 moves 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 source
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
99The
100.Nm
101utility moves symbolic links, not the files referenced by the links.
102.Pp
103If the destination path does not have a mode which permits writing,
104.Nm
105prompts the user for confirmation as specified for the
106.Fl i
107option.
108.Pp
109Should the
110.Xr rename 2
111call fail because the source and destination are on different file systems,
112.Nm
113will use
114.Xr cp 1
115and
116.Xr rm 1
117to accomplish the move.
118The effect is equivalent to:
119.Bd -literal -offset indent
120$ rm -f destination_path && \e
121    cp -PRp source_file destination && \e
122    rm -rf source_file
123.Ed
124.Pp
125.Ex -std mv
126.Sh EXAMPLES
127Rename file
128.Pa foo
129to
130.Pa bar ,
131overwriting
132.Pa bar
133if it already exists:
134.Pp
135.Dl $ mv -f foo bar
136.Pp
137Either of these commands will rename the file
138.Pa -f
139to
140.Pa bar ,
141prompting for confirmation if
142.Pa bar
143already exists:
144.Bd -literal -offset indent
145$ mv -i -- -f bar
146$ mv -i ./-f bar
147.Ed
148.Sh SEE ALSO
149.Xr cp 1 ,
150.Xr rm 1 ,
151.Xr rename 2 ,
152.Xr symlink 7
153.Sh STANDARDS
154The
155.Nm
156utility is compliant with the
157.St -p1003.1-2004
158specification.
159.Sh HISTORY
160A
161.Nm
162command appeared in
163.At v1 .
164.Sh CAVEATS
165In the second synopsis form
166if the destination path exists,
167the
168.Ar source
169operand and the destination path
170must both be a file or must both be a directory
171for the operation to succeed.
172For example, if
173.Pa f
174is a file and
175.Pa d
176and
177.Pa d/f
178are directories, the following command will fail:
179.Pp
180.Dl $ mv f d
181