1RENAME(1) User Commands RENAME(1)
2
3
4
6 rename - rename files
7
9 rename [options] expression replacement file...
10
12 rename will rename the specified files by replacing the first
13 occurrence of expression in their name by replacement.
14
16 -s, --symlink
17 Do not rename a symlink but change where it points.
18
19 -v, --verbose
20 Show which files were renamed, if any.
21
22 -n, --no-act
23 Do not make any changes; add --verbose to see what would be made.
24
25 -a, --all
26 Replace all occurrences of expression rather than only the first
27 one.
28
29 -l, --last
30 Replace the last occurrence of expression rather than the first
31 one.
32
33 -o, --no-overwrite
34 Do not overwrite existing files. When --symlink is active, do not
35 overwrite symlinks pointing to existing targets.
36
37 -i, --interactive
38 Ask before overwriting existing files.
39
40 -h, --help
41 Display help text and exit.
42
43 -V, --version
44 Print version and exit.
45
47 The renaming has no safeguards by default or without any one of the
48 options --no-overwrite, --interactive or --no-act. If the user has
49 permission to rewrite file names, the command will perform the action
50 without any questions. For example, the result can be quite drastic
51 when the command is run as root in the /lib directory. Always make a
52 backup before running the command, unless you truly know what you are
53 doing.
54
56 If the expression is empty, then by default replacement will be added
57 to the start of the filename. With --all, replacement will be inserted
58 in between every two characters of the filename, as well as at the
59 start and end.
60
61 Normally, only the final path component of a filename is updated. (Or
62 with --symlink, only the final path component of the link.) But if
63 either expression or replacement contains a /, the full path is
64 updated. This can cause a file to be moved between folders. Creating
65 folders, and moving files between filesystems, is not supported.
66
68 As most standard utilities rename can be used with a terminal device
69 (tty in short) in canonical mode, where the line is buffered by the tty
70 and you press ENTER to validate the user input. If you put your tty in
71 cbreak mode however, rename requires only a single key press to answer
72 the prompt. To set cbreak mode, run for example:
73
74 sh -c 'stty -icanon min 1; "$0" "$@"; stty icanon' rename -i from to files
75
77 0
78 all requested rename operations were successful
79
80 1
81 all rename operations failed
82
83 2
84 some rename operations failed
85
86 4
87 nothing was renamed
88
89 64
90 unanticipated error occurred
91
93 Given the files foo1, ..., foo9, foo10, ..., foo278, the commands
94
95 rename foo foo00 foo?
96 rename foo foo0 foo??
97
98 will turn them into foo001, ..., foo009, foo010, ..., foo278. And
99
100 rename .htm .html *.htm
101
102 will fix the extension of your html files. Provide an empty string for
103 shortening:
104
105 rename '_with_long_name' '' file_with_long_name.*
106
107 will remove the substring in the filenames.
108
110 mv(1)
111
113 For bug reports, use the issue tracker at
114 https://github.com/util-linux/util-linux/issues.
115
117 The rename command is part of the util-linux package which can be
118 downloaded from Linux Kernel Archive
119 <https://www.kernel.org/pub/linux/utils/util-linux/>.
120
121
122
123util-linux 2.39.2 2023-06-14 RENAME(1)