Skip to content

<tt>rename(1)</tt>

I've heard certain of you (and I'm looking at you here, ) that, though you mostly prefer a Unix command shell to a DOS prompt, you kind of miss the parsing of * that happened under DOS (for instance, mv *.txt *.htm moved all the .txt files to <same thing>.htm–or whatever DOS uses that means mv; I've never owned any Microsoft software). Well, one of my dumbest users, the one who called me earlier today claiming that a file had “disappeared” when, in fact, he'd just moved it using tab completion and left off a piece of the filename (then proceeded to overwrite a bunch of files as he did the same thing across a sequence of files), pointed this out:

RENAME(1)           Linux Programmer's Manual           RENAME(1)

NAME
       rename - Rename files

SYNOPSIS
       rename from to file...

DESCRIPTION
       rename  will  rename  the specified files by replacing the
       first occurrence of from in their name by to.

       For example, given the files foo1, ..., foo9, foo10,  ...,
       foo278, the commands

              rename foo foo0 foo?
              rename foo foo0 foo??

       will  turn  them  into  foo001,  ..., foo009, foo010, ...,
       foo278.

       And
              rename .htm .html *.htm

       will fix the extension of your html files.

SEE ALSO
       mv(1)

                          1 Januari 2000                RENAME(1)

It is Linux-specific, rather than being a POSIX thing, but it exists, and I have to admit it's slightly more concise than my for i in *.txt ; do j=`echo $i | sed -e 's,txt$,htm'` ; echo $i-\>$j ; mv $i $j ; done.

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*