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