xref: /freebsd/bin/mv/mv.1 (revision cbb3ec25236ba72f91cbdf23f8b78b9d1af0cedf)
1.\"-
2.\" Copyright (c) 1989, 1990, 1993
3.\"	The Regents of the University of California.  All rights reserved.
4.\"
5.\" This code is derived from software contributed to Berkeley by
6.\" the Institute of Electrical and Electronics Engineers, Inc.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"	@(#)mv.1	8.1 (Berkeley) 5/31/93
33.\"
34.Dd March 15, 2013
35.Dt MV 1
36.Os
37.Sh NAME
38.Nm mv
39.Nd move files
40.Sh SYNOPSIS
41.Nm
42.Op Fl f | i | n
43.Op Fl hv
44.Ar source target
45.Nm
46.Op Fl f | i | n
47.Op Fl v
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 file in the existing directory named by the
65.Ar directory
66operand.
67The destination path for each operand is the pathname produced by the
68concatenation of the last operand, a slash, and the final pathname
69component of the named file.
70.Pp
71The following options are available:
72.Bl -tag -width indent
73.It Fl f
74Do not prompt for confirmation before overwriting the destination
75path.
76(The
77.Fl f
78option overrides any previous
79.Fl i
80or
81.Fl n
82options.)
83.It Fl h
84If the
85.Ar target
86operand is a symbolic link to a directory,
87do not follow it.
88This causes the
89.Nm
90utility to rename the file
91.Ar source
92to the destination path
93.Ar target
94rather than moving
95.Ar source
96into the directory referenced by
97.Ar target .
98.It Fl i
99Cause
100.Nm
101to write a prompt to standard error before moving a file that would
102overwrite an existing file.
103If the response from the standard input begins with the character
104.Ql y
105or
106.Ql Y ,
107the move is attempted.
108(The
109.Fl i
110option overrides any previous
111.Fl f
112or
113.Fl n
114options.)
115.It Fl n
116Do not overwrite an existing file.
117(The
118.Fl n
119option overrides any previous
120.Fl f
121or
122.Fl i
123options.)
124.It Fl v
125Cause
126.Nm
127to be verbose, showing files after they are moved.
128.El
129.Pp
130It is an error for the
131.Ar source
132operand to specify a directory if the target exists and is not a directory.
133.Pp
134If the destination path does not have a mode which permits writing,
135.Nm
136prompts the user for confirmation as specified for the
137.Fl i
138option.
139.Pp
140As the
141.Xr rename 2
142call does not work across file systems,
143.Nm
144uses
145.Xr cp 1
146and
147.Xr rm 1
148to accomplish the move.
149The effect is equivalent to:
150.Bd -literal -offset indent
151rm -f destination_path && \e
152cp -pRP source_file destination && \e
153rm -rf source_file
154.Ed
155.Sh EXIT STATUS
156.Ex -std
157.Sh EXAMPLES
158Rename file
159.Pa foo
160to
161.Pa bar ,
162overwriting
163.Pa bar
164if it already exists:
165.Pp
166.Dl $ mv -f foo bar
167.Sh COMPATIBILITY
168The
169.Fl h ,
170.Fl n ,
171and
172.Fl v
173options are non-standard and their use in scripts is not recommended.
174.Sh SEE ALSO
175.Xr cp 1 ,
176.Xr rm 1 ,
177.Xr symlink 7
178.Sh STANDARDS
179The
180.Nm
181utility is expected to be
182.St -p1003.2
183compatible.
184.Sh HISTORY
185A
186.Nm
187command appeared in
188.At v1 .
189