1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
'\" t
.\" Title: rename
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
.\" Date: 2024-05-01
.\" Manual: User Commands
.\" Source: util-linux 2.40.1
.\" Language: English
.\"
.TH "RENAME" "1" "2024-05-01" "util\-linux 2.40.1" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
. mso www.tmac
. am URL
. ad l
. .
. am MTO
. ad l
. .
. LINKSTYLE blue R < >
.\}
.SH "NAME"
rename \- rename files
.SH "SYNOPSIS"
.sp
\fBrename\fP [options] \fIexpression replacement file\fP...
.SH "DESCRIPTION"
.sp
\fBrename\fP will rename the specified files by replacing the first occurrence of \fIexpression\fP in their name by \fIreplacement\fP.
.SH "OPTIONS"
.sp
\fB\-s\fP, \fB\-\-symlink\fP
.RS 4
Do not rename a symlink but change where it points.
.RE
.sp
\fB\-v\fP, \fB\-\-verbose\fP
.RS 4
Show which files were renamed, if any.
.RE
.sp
\fB\-n\fP, \fB\-\-no\-act\fP
.RS 4
Do not make any changes; add \fB\-\-verbose\fP to see what would be made.
.RE
.sp
\fB\-a\fP, \fB\-\-all\fP
.RS 4
Replace all occurrences of \fIexpression\fP rather than only the first one.
.RE
.sp
\fB\-l\fP, \fB\-\-last\fP
.RS 4
Replace the last occurrence of \fIexpression\fP rather than the first one.
.RE
.sp
\fB\-o\fP, \fB\-\-no\-overwrite\fP
.RS 4
Do not overwrite existing files. When \fB\-\-symlink\fP is active, do not overwrite symlinks pointing to existing targets.
.RE
.sp
\fB\-i\fP, \fB\-\-interactive\fP
.RS 4
Ask before overwriting existing files.
.RE
.sp
\fB\-h\fP, \fB\-\-help\fP
.RS 4
Display help text and exit.
.RE
.sp
\fB\-V\fP, \fB\-\-version\fP
.RS 4
Print version and exit.
.RE
.SH "WARNING"
.sp
The renaming has no safeguards by default or without any one of the options \fB\-\-no\-overwrite\fP, \fB\-\-interactive\fP or \fB\-\-no\-act\fP. If the user has permission to rewrite file names, the command will perform the action without any questions. For example, the result can be quite drastic when the command is run as root in the \fI/lib\fP directory. Always make a backup before running the command, unless you truly know what you are doing.
.SH "EDGE CASES"
.sp
If the \fIexpression\fP is empty, then by default \fIreplacement\fP will be added to the start of the filename. With \fB\-\-all\fP, \fIreplacement\fP will be inserted in between every two characters of the filename, as well as at the start and end.
.sp
Normally, only the final path component of a filename is updated. (Or with \fB\-\-symlink\fP, only the final path component of the link.) But if either \fIexpression\fP or \fIreplacement\fP contains a \fI/\fP, the full path is updated. This can cause a file to be moved between folders. Creating folders, and moving files between filesystems, is not supported.
.SH "INTERACTIVE MODE"
.sp
As most standard utilities rename can be used with a terminal device (tty in short) in canonical mode, where the line is buffered by the tty and you press ENTER to validate the user input. If you put your tty in cbreak mode however, rename requires only a single key press to answer the prompt. To set cbreak mode, run for example:
.sp
.if n .RS 4
.nf
.fam C
sh \-c \*(Aqstty \-icanon min 1; "$0" "$@"; stty icanon\*(Aq rename \-i from to files
.fam
.fi
.if n .RE
.SH "EXIT STATUS"
.sp
\fB0\fP
.RS 4
all requested rename operations were successful
.RE
.sp
\fB1\fP
.RS 4
all rename operations failed
.RE
.sp
\fB2\fP
.RS 4
some rename operations failed
.RE
.sp
\fB4\fP
.RS 4
nothing was renamed
.RE
.sp
\fB64\fP
.RS 4
unanticipated error occurred
.RE
.SH "EXAMPLES"
.sp
Given the files \fIfoo1\fP, ..., \fIfoo9\fP, \fIfoo10\fP, ..., \fIfoo278\fP, the commands
.sp
.if n .RS 4
.nf
.fam C
rename foo foo00 foo?
rename foo foo0 foo??
.fam
.fi
.if n .RE
.sp
will turn them into \fIfoo001\fP, ..., \fIfoo009\fP, \fIfoo010\fP, ..., \fIfoo278\fP. And
.sp
.if n .RS 4
.nf
.fam C
rename .htm .html *.htm
.fam
.fi
.if n .RE
.sp
will fix the extension of your html files. Provide an empty string for shortening:
.sp
.if n .RS 4
.nf
.fam C
rename \*(Aq_with_long_name\*(Aq \*(Aq\*(Aq file_with_long_name.*
.fam
.fi
.if n .RE
.sp
will remove the substring in the filenames.
.SH "SEE ALSO"
.sp
\fBmv\fP(1)
.SH "REPORTING BUGS"
.sp
For bug reports, use the issue tracker at \c
.URL "https://github.com/util\-linux/util\-linux/issues" "" "."
.SH "AVAILABILITY"
.sp
The \fBrename\fP command is part of the util\-linux package which can be downloaded from \c
.URL "https://www.kernel.org/pub/linux/utils/util\-linux/" "Linux Kernel Archive" "."
|