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