man-pages/man1/rename.ul.1.html
2021-03-31 01:06:50 +01:00

217 lines
4.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of RENAME</TITLE>
</HEAD><BODY>
<H1>RENAME</H1>
Section: User Commands (1)<BR>Updated: June 2011<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
rename - rename files
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>rename</B>
[options]
<I>expression replacement file</I>...
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>rename</B>
will rename the specified files by replacing the first occurrence of
<I>expression</I>
in their name by
<I>replacement</I>.
<A NAME="lbAE">&nbsp;</A>
<H2>OPTIONS</H2>
<DL COMPACT>
<DT id="1"><B>-s</B>,<B> --symlink</B>
<DD>
Do not rename a symlink but its target.
<DT id="2"><B>-v</B>,<B> --verbose</B>
<DD>
Show which files were renamed, if any.
<DT id="3"><B>-n</B>,<B> --no-act</B>
<DD>
Do not make any changes; add
<B>--verbose</B>
to see what would be made.
<DT id="4"><B>-o</B>,<B> --no-overwrite</B>
<DD>
Do not overwrite existing files. When
<B>--symlink</B>
is active, do not overwrite symlinks pointing to existing targets.
<DT id="5"><B>-i</B>,<B> --interactive</B>
<DD>
Ask before overwriting existing files.
<DT id="6"><B>-V</B>,<B> --version</B>
<DD>
Display version information and exit.
<DT id="7"><B>-h</B>,<B> --help</B>
<DD>
Display help text and exit.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>EXAMPLES</H2>
Given the files
<I>foo1</I>, ..., <I>foo9</I>, <I>foo10</I>, ..., <I>foo278</I>,
the commands
<DL COMPACT><DT id="8"><DD>
<P>
<PRE>
rename foo foo00 foo?
rename foo foo0 foo??
</PRE>
<P>
</DL>
will turn them into
<I>foo001</I>, ..., <I>foo009</I>, <I>foo010</I>, ..., <I>foo278</I>.
And
<DL COMPACT><DT id="9"><DD>
<P>
<PRE>
rename .htm .html *.htm
</PRE>
<P>
</DL>
will fix the extension of your html files.
Provide an empty string for shortening:
<DL COMPACT><DT id="10"><DD>
<P>
<PRE>
rename '_with_long_name' '' file_with_long_name.*
</PRE>
<P>
</DL>
will remove the substring in the filenames.
<A NAME="lbAG">&nbsp;</A>
<H2>WARNING</H2>
The renaming has no safeguards by default or without any one of the options
<B>--no-overwrite</B>,
<B>--interactive</B>
or
<B>--no-act</B>.
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.
<A NAME="lbAH">&nbsp;</A>
<H2>INTERACTIVE MODE</H2>
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:
<DL COMPACT><DT id="11"><DD>
<P>
<PRE>
sh -c 'stty -icanon min 1; &quot;$0&quot; &quot;$@&quot;; stty icanon' rename -i from to files
</PRE>
<P>
</DL>
<A NAME="lbAI">&nbsp;</A>
<H2>EXIT STATUS</H2>
<DL COMPACT><DT id="12"><DD>
<DL COMPACT>
<DT id="13"><B>0</B>
<DD>
all requested rename operations were successful
<DT id="14"><B>1</B>
<DD>
all rename operations failed
<DT id="15"><B>2</B>
<DD>
some rename operations failed
<DT id="16"><B>4</B>
<DD>
nothing was renamed
<DT id="17"><B>64</B>
<DD>
unanticipated error occurred
</DL>
</DL>
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+mv">mv</A></B>(1)
<A NAME="lbAK">&nbsp;</A>
<H2>AVAILABILITY</H2>
The rename command is part of the util-linux package and is available from
<A HREF="https://www.kernel.org/pub/linux/utils/util-linux/.">https://www.kernel.org/pub/linux/utils/util-linux/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="18"><A HREF="#lbAB">NAME</A><DD>
<DT id="19"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="20"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="21"><A HREF="#lbAE">OPTIONS</A><DD>
<DT id="22"><A HREF="#lbAF">EXAMPLES</A><DD>
<DT id="23"><A HREF="#lbAG">WARNING</A><DD>
<DT id="24"><A HREF="#lbAH">INTERACTIVE MODE</A><DD>
<DT id="25"><A HREF="#lbAI">EXIT STATUS</A><DD>
<DT id="26"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="27"><A HREF="#lbAK">AVAILABILITY</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:26 GMT, March 31, 2021
</BODY>
</HTML>