ren - Man Page

rename multiple files


ren [ -d | -k | -a ] [ -v ] [path/]search replacement


Ren renames each file in the current directory (or in the path directory, if specified) that matches the search pattern; each matching file's new name is given by the replacement pattern. The multiple rename is performed safely, i.e. without any unexpected deletion of files due to collisions of replacement names with existing names, or with other replacement names. Also, all error checking is done prior to doing any renames, so either all renames are done, or none.

The search pattern is a filename with embedded wildcards, i.e. * and ?, which have their usual meanings of, respectively, matching any string of characters, and matching any single character. The replacement pattern is another filename with embedded wildcard indexes, each of which consists of the character # followed by a digit from 1 to 9. In the new name of a matching file, the wildcard indexes are replaced by the actual characters that matched the referenced wildcards in the original filename. Thus, if the search pattern is "abc*.*.*" and the replacement pattern is "xyz#1.#3", then "abc.txt.doc" is renamed to "xyz.doc" (since the first * matched "", the second matched "txt", and the third matched "doc").

Note that the shell normally expands the wildcards * and ?, which in the case of ren is undesirable. Thus, in most cases it is necessary to enclose the search pattern in quotes, e.g. ren "*.a" #1.b. To strip any of the characters *, ?, and # of their special meaning to ren, as when the actual replacement name must contain the character #, precede the special character with \ (and enclose the argument in qoutes because of the shell).

Note that a path is not allowed in the replacement pattern. Ren does not allow moving files between directories, which facilitates the safety checks next described.

When any two matching files would have to be renamed to the same new filename, ren detects the condition prior to doing any renames and aborts with an error message. Ren also checks if any file deletes would result from the rename, i.e. if some file1 would have to be renamed to file2, and file2 already exists and is not itself being renamed. (Here and below, "delete" really means "unlink".) In such a case, ren asks you (by reading a line from standard input) if you really wish file2 to be deleted. If your answer is negative, file1 is not renamed.

Ren safely performs chain renames, i.e. when file1 is renamed to file2, file2 to file3, file3 to file4, etc, by doing the renames in the proper order. In the case that the chain is a cycle, i.e. filen is renamed back to file1, ren breaks the cycle by using a temporary name.

Files beginning with . are not matched against the search pattern (and thus not renamed) unless the search pattern explicitly begins with '.'. In any case, "." and ".." are never matched.



(verbose): after each rename, the message "file1 -> file2 [(*)]" appears on the standard output. The (*) appears in the case of a deleting rename, i.e. when the old file2 is deleted.


-k, -a: suppress interrogation with regard to deleting renames, and:


(delete): perform all deleting renames silently.


(keep): perform no deleting renames.


(abort): if any deleting renames are detected, abort prior to doing any renames.

See Also



Vladimir Lanin


If the search pattern is not quoted, the shell expands the wildcards. Ren then complains that there are too many arguments (if indeed there are), but can not determine that the lack of quotes is the cause.


May 20, 1988