xref: /openbsd/bin/mv/mv.1 (revision b76c7f09)
1.\"	$OpenBSD: mv.1,v 1.29 2011/06/15 23:47:37 tedu 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: June 15 2011 $
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 the destination specified by the
65.Ar directory
66operand.
67It is an error if the
68.Ar directory
69does 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
76In both forms, a
77.Ar source
78operand is skipped with an error message
79when the respective destination path is a non-empy directory,
80or when the source is a non-directory file but the destination path
81is a directory, or vice versa.
82.Pp
83The options are as follows:
84.Bl -tag -width Ds
85.It Fl f
86Do not prompt for confirmation before overwriting the destination
87path.
88The
89.Fl f
90option overrides any previous
91.Fl f
92options.
93.It Fl i
94Causes
95.Nm
96to write a prompt to standard error before moving a file that would
97overwrite an existing file.
98If the response from the standard input begins with the character
99.Dq y ,
100the move is attempted.
101The
102.Fl i
103option overrides any previous
104.Fl f
105options.
106.El
107.Pp
108The
109.Nm
110utility moves symbolic links, not the files referenced by the links.
111.Pp
112If the destination path does not have a mode which permits writing,
113.Nm
114prompts the user for confirmation as specified for the
115.Fl i
116option.
117.Pp
118Should the
119.Xr rename 2
120call fail because the source and destination are on different file systems,
121.Nm
122will use
123.Xr cp 1
124and
125.Xr rm 1
126to accomplish the move.
127The effect is equivalent to:
128.Bd -literal -offset indent
129$ rm -df -- destination_path && \e
130    cp -PRp -- source destination_path && \e
131    rm -rf -- source
132.Ed
133.Sh EXIT STATUS
134.Ex -std mv
135.Sh EXAMPLES
136Rename file
137.Pa foo
138to
139.Pa bar ,
140overwriting
141.Pa bar
142if it already exists:
143.Pp
144.Dl $ mv -f foo bar
145.Pp
146Either of these commands will rename the file
147.Pa -f
148to
149.Pa bar ,
150prompting for confirmation if
151.Pa bar
152already exists:
153.Bd -literal -offset indent
154$ mv -i -- -f bar
155$ mv -i ./-f bar
156.Ed
157.Sh SEE ALSO
158.Xr cp 1 ,
159.Xr rm 1 ,
160.Xr rename 2 ,
161.Xr symlink 7
162.Sh STANDARDS
163The
164.Nm
165utility is compliant with the
166.St -p1003.1-2008
167specification.
168.Sh HISTORY
169A
170.Nm
171command appeared in
172.At v1 .
173.Sh CAVEATS
174In the second synopsis form, incompatible file types in
175.Ar source
176and
177.Ar directory
178cause partial moves.
179For example, if
180.Pa f
181and
182.Pa g
183are non-directory files and
184.Pa d
185and
186.Pa d/f
187are directories, the command
188.Pp
189.Dl $ mv f g d
190.Pp
191will print an error message, leave
192.Pa f
193where it is, move
194.Pa g
195to
196.Pa d/g
197and return a non-zero exit status.
198