NAME

mved - carefully rename multiple files


SYNOPSIS

 usage: mved [options] src dst
 options:
   -h   - Print the help message then exit
   -m   - Print the manpage then exit
   -w   - Print the manpage in html format then exit
   -r   - Print the manpage in nroff format then exit
   -n   - Don't rename anything. Just print commands
   -f   - Force dangerous actions (Check with -n first!)
   -q   - Don't print skipping or unlinking messages
   -v   - Print equivalent mv commands (implied by -d)
   -d   - Print debugging messages
   -b # - Set depth of quote characters to check (default 4)

DESCRIPTION

mved renames multiple files. The src argument is a filename glob specifying the set of files to rename. The dst argument is a pattern specifying the new names for the set of files. The src argument can contain all of the normal shell globbing constructs (?, * and [...]) as well as = which is a synonym for *. If any normal shell globbing constructs are used, they must be quoted to prevent the shell from performing filename expansion. This is not necessary when the only construct used is =. There are two styles of dst argument. One allows = to represent the text matching the (positionally) corresponding glob construct in the src argument. The other allows =#= (where # is an integer) to represent the text matching the #-th glob construct in the src argument. The two styles cannot be mixed.

mved creates new links to the existing files. If the -v verbose option is supplied, the corresponding mv commands are printed. If any of them fail, they are all unlinked and the operation is aborted. If all were successful, the original files are unlinked.

Before renaming any files, mved checks for any dubious consequences. If a source filename is equal to its corresponding destination filename, that (redundant) renaming operation is skipped. The user is informed unless the -q quiet option is supplied. If a source filename is equal to some other destination filename, mved gets nervous and exits unless the -f force option is supplied. If the same filename is a destination for multiple source filenames, mved exits unless the -f force option is supplied. If any file to be created already exists, mved exits unless the -f force option is supplied. When forced, mved will unlink any existing destination files. The user will be informed unless the -q quiet option is supplied.


OPTIONS

-h
Print the help message then exit.
-m
Print the manpage then exit. This is equivalent to executing man mved but this works even when the manpage isn't installed properly.
-w
Print the manpage in html format then exit. This lets you install the manpage in html format with a command like:
  mkdir -p /usr/local/share/doc/mved/html &&
  mved -w > /usr/local/share/doc/mved/html/mved.1.html
-r
Print the manpage in nroff format then exit. This lets you install the manpage properly with a command like:
  mved -r > /usr/local/share/man/man1/mved.1
-n
Don't rename anything. Just print the corresponding mv commands and (and possibly rm commands) then exit.
-f
Force mved to obey even when it doesn't like what you are doing. If you force mved to rename a file to an existing file, the existing file will be unlinked first. Never use this without using -n first to see what you are telling mved to do and verifying that it is what you really, really want to do.
-q
Don't print ``Skipping filename'' messages when a source filename matches it's corresponding destination filename. Don't print ``Unlinking filename'' messages when forced to unlink existing files.
-v
Print corresponding mv commands when renaming each file. Implied by the -d option.
-d
Print debugging messages that show the src and dst arguments before and after translation from filename globs into regular expressions. Also print corresponding mv commands when renaming each file.
-b #
Specify how many backslashes to count backwards when determining whether or not special characters are quoted. The default is 4 which should be more than you'll ever need (unless you have files with consecutive backslashes in their names - shudder).

EXAMPLES

mved =.c~ bak/=.c.bak
    mv a.c~ bak/a.c.bak
    mv b.c~ bak/b.c.bak
    mv c.c~ bak/c.c.bak
mved '*.[ch]' save-=.=
    mv a.c save-a.c
    mv a.h save-a.h
    mv b.c save-b.c
    mv b.h save-b.h
mved save-=.= =.=
    mv save-a.c a.c
    mv save-a.o a.o
    mv save-b.c b.c
    mv save-b.o b.o
mved note= note=.txt
    mv note1 note1.txt
    mv note2 note2.txt
    mv note3 note3.txt
mved '[0-9][0-9][0-9][0-9][0-9][0-9]*' 19=5==6=-=3==4=-=1==2==7=
    mv 191299-app.log 1999-12-19-app.log
    mv 211299-app.log 1999-12-21-app.log
    mv 251299-app.log 1999-12-25-app.log
    mv 281299-app.log 1999-12-28-app.log

RETURNS

mved returns 0 (zero) upon success, 1 (one) upon failure. Upon failure, no files will have been renamed.


BUGS

Hard links are used so it is impossible to mved files from one file system to another. Use mv for this. Then rename with mved. This is not really a bug. It is a safety feature.

Doesn't handle patterns containing pipe '|' characters because this character is used as the regular expression separator.

Presumably, there are as yet unknown bugs and they will presumably cost files. My advice is to always use -n first, never use -f, and always keep backups.


COPYING

Released under the terms of the GPL (http://www.gnu.org/copyleft/gpl.html)


HISTORY

Many years ago on a MIPS far away, there was a program called mved that renamed multiple files using =. It was very useful but I haven't seen it since.


SEE ALSO

link(2), unlink(2), mv(1), rm(1)


AUTHOR

20030901 raf <raf@raf.org>


URL

http://raf.org/mved/