NAME(SECTION)NAME(SECTION)Namerename - file rename tool
SYNOPSISrename OldName NewName
rename [options] files ...
DESCRIPTION
This rename is a quick and powerful tool for upcasing, lowcasing file‐
names or substituting substring in filenames, which can be specified
with a regular expression pattern. Unlike other rename tools written in
script language, this one is written in C so it runs fast.
OPTIONS-l, --lowcase
Lowcase specified filenames.
-u, --upcase
Upcase specified filenames.
-R, --recursive
Perform on the specified files and all subdirectories.
-t, --test
Do not change filenames, just test the result of substituting.
-o, --owner OWNER
When changing filenames, it changes the owner of filenames to
OWNER. This funtion not works only when renaming filename, but
works individually just like a file owner changer. (superuser
only)
-v, --verbose
verbose display.
--yes confirm all prompts with YES.
--no confirm all prompts with NO.
-s/PATTERN/STRING[/sw]
Substitute PATTERN with STRING in filenames. sw is the follow‐
ing switch:
g replace all occurrences in the filename.
i ignore case when searching.
b backward searching and substituting. This does not sup‐
port regular expression.
s change filenames' suffix. In this case, the PATTERN
should be some kind of filename suffix.
r declare that PATTERN is a regular expression.
e declare that PATTERN is an extended regular expression.
REGULAR EXPRESSION
This section about extended regular expression is digisted from the
manpage of fgrep(1). See it for details.
A regular expression is a pattern that describes a set of strings.
Regular expressions are constructed analogously to arithmetic expres‐
sions, by using various operators to combine smaller expressions.
The fundamental building blocks are the regular expressions that match
a single character. Most characters, including all letters and digits,
are regular expressions that match themselves. Any metacharacter with
special meaning may be quoted by preceding it with a backslash.
A list of characters enclosed by [ and ] matches any single character
in that list; if the first character of the list is the caret ^ then it
matches any character not in the list. For example, the regular
expression [0123456789] matches any single digit. A range of ASCII
characters may be specified by giving the first and last characters,
separated by a hyphen. Finally, certain named classes of characters
are predefined. Their names are self explanatory, and they are
[:alnum:], [:alpha:], [:cntrl:], [:digit:], [:graph:], [:lower:],
[:print:], [:punct:], [:space:], [:upper:], and [:xdigit:]. For exam‐
ple, [[:alnum:]] means [0-9A-Za-z], except the latter form is dependent
upon the ASCII character encoding, whereas the former is portable.
(Note that the brackets in these class names are part of the symbolic
names, and must be included in addition to the brackets delimiting the
bracket list.) Most metacharacters lose their special meaning inside
lists. To include a literal ] place it first in the list. Similarly,
to include a literal ^ place it anywhere but first. Finally, to
include a literal - place it last.
The period . matches any single character. The symbol \w is a synonym
for [[:alnum:]] and \W is a synonym for [^[:alnum]].
The caret ^ and the dollar sign $ are metacharacters that respectively
match the empty string at the beginning and end of a line. The symbols
\< and \> respectively match the empty string at the beginning and end
of a word. The symbol \b matches the empty string at the edge of a
word, and \B matches the empty string provided it's not at the edge of
a word.
A regular expression may be followed by one of several repetition oper‐
ators:
? The preceding item is optional and matched at most once.
* The preceding item will be matched zero or more times.
+ The preceding item will be matched one or more times.
{n} The preceding item is matched exactly n times.
{n,} The preceding item is matched n or more times.
{,m} The preceding item is optional and is matched at most m times.
{n,m} The preceding item is matched at least n times, but not more
than m times.
Two regular expressions may be concatenated; the resulting regular
expression matches any string formed by concatenating two substrings
that respectively match the concatenated subexpressions.
Two regular expressions may be joined by the infix operator |; the
resulting regular expression matches any string matching either subex‐
pression.
Repetition takes precedence over concatenation, which in turn takes
precedence over alternation. A whole subexpression may be enclosed in
parentheses to override these precedence rules.
The backreference \n, where n is a single digit, matches the substring
previously matched by the nth parenthesized subexpression of the regu‐
lar expression.
In basic regular expressions the metacharacters ?, +, {, |, (, and )
lose their special meaning; instead use the backslashed versions \?,
\+, \{, \|, \(, and \).
SEE ALSOmv(1), chown(1), regex(7), regex(3)COPYING
Copyright 1999 - 2001 Xu, Ming
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version. This program is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
POSE. See the GNU General Public License for more details. You should
have received a copy of the GNU General Public License along with this
program; if not, write to the Free Software Foundation, Inc., 675 Mass
Ave, Cambridge, MA 02139, USA.
BUGS
Please send bug reports to <xuming@bigfoot.com>
EXAMPLESrename foo food
Change file 'foo' to 'food', just like mv(1) does.
rename-lR *
To lowcase all filenames, directories and filenames and directo‐
ries under subdirectories.
rename -s/abc/xyz/gi *.c
Substitute all 'abc' substrings appeared in C sources files with
'xyz', ignoring case.
rename -vs/.c/.cpp/s *.c
Change C sources suffix to C++ sources suffix, with verbose
information.
rename -s/abc/12345/bi *
Find the last occurrence of 'abc' and replace it with '12345',
ignoring case.
rename-o guest -R /home/custom
change the owner of the file '/home/custom' to 'guest'. The
'guest' should be an effective user in the current system. If
'/home/custom' is a directory, all files in this directory tree
will hand to 'guest'.
rename -s/^[A-Z].*file/nofile/r *
The target substring starts with a capital letter, and ends with
string 'file'. There are 0 or any numbers of characters between
the capital letter and 'file'. The substring, if encountered in
filenames, will be replaced with 'nofile'.
rename -s/^[A-Z].+file/nofile/eg *
Similar to last example, except it uses extended regular expres‐
sion, such as the '+' metacharacter, and replaces all matching
strings with 'nofile'.
NAME(SECTION)