]> git.ipfire.org Git - thirdparty/util-linux.git/blame - misc-utils/rename.1
docs: update year in libs docs
[thirdparty/util-linux.git] / misc-utils / rename.1
CommitLineData
eb63b9b8
KZ
1.\" Written by Andries E. Brouwer (aeb@cwi.nl)
2.\" Placed in the public domain
3.\"
232dc924 4.TH RENAME 1 "June 2011" "util-linux" "User Commands"
eb63b9b8 5.SH NAME
0791a058 6rename \- rename files
eb63b9b8 7.SH SYNOPSIS
f736d385 8.B rename
f49ccec2
BS
9[options]
10.IR "expression replacement file" ...
eb63b9b8
KZ
11.SH DESCRIPTION
12.B rename
13will rename the specified files by replacing the first occurrence of
03b3d715 14.I expression
eb63b9b8 15in their name by
03b3d715
SK
16.IR replacement .
17.SH OPTIONS
2a45745f 18.TP
7ab71099
BS
19.BR \-s , " \-\-symlink"
20Do not rename a symlink but its target.
03b3d715 21.TP
7ab71099 22.BR \-v , " \-\-verbose"
deff4975 23Show which files were renamed, if any.
03b3d715 24.TP
f60d62af 25.BR \-n , " \-\-no\-act"
0849ff36 26Do not make any changes; add
0bb7e904 27.B \-\-verbose
0849ff36 28to see what would be made.
990bf1f0 29.TP
f60d62af 30.BR \-o , " \-\-no\-overwrite"
5bb92700 31Do not overwrite existing files. When
0bb7e904 32.B \-\-symlink
5bb92700 33is active, do not overwrite symlinks pointing to existing targets.
f60d62af 34.TP
eb4aea8a
M
35.BR \-i , " \-\-interactive"
36Ask before overwriting existing files.
37.TP
7ab71099
BS
38.BR \-V , " \-\-version"
39Display version information and exit.
5a2a8177 40.TP
7ab71099 41.BR \-h , " \-\-help"
449a215f 42Display help text and exit.
0791a058
BS
43.SH EXAMPLES
44Given the files
eb63b9b8
KZ
45.IR foo1 ", ..., " foo9 ", " foo10 ", ..., " foo278 ,
46the commands
eb63b9b8 47.RS
03b3d715 48.PP
eb63b9b8 49.nf
ed21c47a 50rename foo foo00 foo?
eb63b9b8
KZ
51rename foo foo0 foo??
52.fi
03b3d715 53.PP
eb63b9b8 54.RE
eb63b9b8
KZ
55will turn them into
56.IR foo001 ", ..., " foo009 ", " foo010 ", ..., " foo278 .
eb63b9b8
KZ
57And
58.RS
03b3d715 59.PP
eb63b9b8
KZ
60.nf
61rename .htm .html *.htm
62.fi
03b3d715 63.PP
eb63b9b8 64.RE
eb63b9b8 65will fix the extension of your html files.
7d85a7e9
K
66Provide an empty string for shortening:
67.RS
68.PP
69.nf
70rename '_with_long_name' '' file_with_long_name.*
71.fi
72.PP
73.RE
74will remove the substring in the filenames.
03b3d715 75.SH WARNING
961b0946
M
76The renaming has no safeguards by default or without any one of the options
77.B \-\-no-overwrite\fR,
78.B \-\-interactive
79or
80.B \-\-no\-act\fR.
81If the user has
990bf1f0
AR
82permission to rewrite file names, the command will perform the action without
83any questions. For example, the result can be quite drastic when the command
84is run as root in the /lib directory. Always make a backup before running the
85command, unless you truly know what you are doing.
16740b0c
M
86.SH INTERACTIVE MODE
87As most standard utilities rename can be used with a terminal device (tty in
88short) in canonical mode, where the line is buffered by the tty and you press
89ENTER to validate the user input. If you put your tty in cbreak mode however,
90rename requires only a single key press to answer the prompt. To set cbreak
91mode, run for example:
92.RS
93.PP
94.nf
1c4c6024 95sh \-c 'stty \-icanon min 1; "$0" "$@"; stty icanon' rename \-i from to files
16740b0c
M
96.fi
97.PP
98.RE
d6cf9e16
SK
99.SH "EXIT STATUS"
100.RS
101.PD 0
102.TP
103.B 0
104all requested rename operations were successful
105.TP
106.B 1
107all rename operations failed
108.TP
109.B 2
110some rename operations failed
111.TP
112.B 4
113nothing was renamed
114.TP
115.B 64
116unanticipated error occurred
117.PD
118.RE
eb63b9b8
KZ
119.SH "SEE ALSO"
120.BR mv (1)
86d62711 121.SH AVAILABILITY
601d12fb 122The rename command is part of the util-linux package and is available from
d673b74e 123https://www.kernel.org/pub/linux/utils/util-linux/.