]> git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/rename.1.adoc
Merge branch 'misc-utils-rename-symlink-paths' of https://github.com/ChickenProp...
[thirdparty/util-linux.git] / misc-utils / rename.1.adoc
1 //po4a: entry man manual
2 // Written by Andries E. Brouwer (aeb@cwi.nl)
3 // Placed in the public domain
4 = rename(1)
5 :doctype: manpage
6 :man manual: User Commands
7 :man source: util-linux {release-version}
8 :page-layout: base
9 :command: rename
10
11 == NAME
12
13 rename - rename files
14
15 == SYNOPSIS
16
17 *rename* [options] _expression replacement file_...
18
19 == DESCRIPTION
20
21 *rename* will rename the specified files by replacing the first occurrence of _expression_ in their name by _replacement_.
22
23 == OPTIONS
24
25 *-s*, *--symlink*::
26 Do not rename a symlink but change where it points.
27
28 *-v*, *--verbose*::
29 Show which files were renamed, if any.
30
31 *-n*, *--no-act*::
32 Do not make any changes; add *--verbose* to see what would be made.
33
34 *-a*, *--all*::
35 Replace all occurrences of _expression_ rather than only the first one.
36
37 *-l*, *--last*::
38 Replace the last occurrence of _expression_ rather than the first one.
39
40 *-o*, *--no-overwrite*::
41 Do not overwrite existing files. When *--symlink* is active, do not overwrite symlinks pointing to existing targets.
42
43 *-i*, *--interactive*::
44 Ask before overwriting existing files.
45
46 include::man-common/help-version.adoc[]
47
48 == WARNING
49
50 The renaming has no safeguards by default or without any one of the options *--no-overwrite*, *--interactive* or *--no-act*. 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 _/lib_ directory. Always make a backup before running the command, unless you truly know what you are doing.
51
52 == EDGE CASES
53
54 If the _expression_ is empty, then by default _replacement_ will be added to the start of the filename. With *--all*, _replacement_ will be inserted in between every two characters of the filename, as well as at the start and end.
55
56 Normally, only the final path component of a filename is updated. (Or with *--symlink*, only the final path component of the link.) But if either _expression_ or _replacement_ contains a _/_, 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.
57
58 == INTERACTIVE MODE
59
60 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:
61
62 ....
63 sh -c 'stty -icanon min 1; "$0" "$@"; stty icanon' rename -i from to files
64 ....
65
66 == EXIT STATUS
67
68 *0*::
69 all requested rename operations were successful
70
71 *1*::
72 all rename operations failed
73
74 *2*::
75 some rename operations failed
76
77 *4*::
78 nothing was renamed
79
80 *64*::
81 unanticipated error occurred
82
83 == EXAMPLES
84
85 Given the files _foo1_, ..., _foo9_, _foo10_, ..., _foo278_, the commands
86
87 ....
88 rename foo foo00 foo?
89 rename foo foo0 foo??
90 ....
91
92 will turn them into _foo001_, ..., _foo009_, _foo010_, ..., _foo278_. And
93
94 ....
95 rename .htm .html *.htm
96 ....
97
98 will fix the extension of your html files. Provide an empty string for shortening:
99
100 ....
101 rename '_with_long_name' '' file_with_long_name.*
102 ....
103
104 will remove the substring in the filenames.
105
106 == SEE ALSO
107
108 *mv*(1)
109
110 include::man-common/bugreports.adoc[]
111
112 include::man-common/footer.adoc[]
113
114 ifdef::translation[]
115 include::man-common/translation.adoc[]
116 endif::[]