home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / fileutil / mmv / mmv.man < prev    next >
Text File  |  1990-06-13  |  15KB  |  326 lines

  1. NAME
  2.      mmv - move/copy/append/link multiple files by wildcard patterns
  3.  
  4. SYNOPSIS
  5.      mmv [-m|x|r|c|o|a|l|s] [-h] [-d|p] [-g|t] [-v|n] [from to]
  6.  
  7. DESCRIPTION
  8.      Mmv moves (or copies, appends, or links, as specified) each
  9.      source file matching a from pattern to the target name
  10.      specified by the to pattern.  This multiple action is per-
  11.      formed safely, i.e. without any unexpected deletion of files
  12.      due to collisions of target names with existing filenames or
  13.      with other target names.  Furthermore, before doing any-
  14.      thing, mmv attempts to detect any errors that would result
  15.      from the entire set of actions specified and gives the user
  16.      the choice of either proceeding by avoiding the offending
  17.      parts or aborting.
  18.  
  19.                            The Task Options
  20.  
  21.      Whether mmv moves, copies, appends, or links is governed by
  22.      the first set of options given above.  If none of these are
  23.      specified, the task is given by the command name under which
  24.      mmv was invoked (argv[0]):
  25.  
  26.           command name   default task
  27.  
  28.           mmv            -x
  29.           mcp            -c
  30.           mad            -a
  31.           mln            -l
  32.  
  33.      The task option choices are:
  34.  
  35.      -m : move source file to target name.  Both must be on the
  36.           same device.  Will not move directories.  If the source
  37.           file is a symbolic link, moves the link without check-
  38.           ing if the link's target from the new directory is dif-
  39.           ferent than the old.
  40.  
  41.      -x : same as -m, except cross-device moves are done by copy-
  42.           ing, then deleting source.  When copying, sets the per-
  43.           mission bits and file modification time of the target
  44.           file to that of the source file.
  45.  
  46.      -r : rename source file or directory to target name.  The
  47.           target name must not include a path: the file remains
  48.           in the same directory in all cases.  This option is the
  49.           only way of renaming directories under mmv.
  50.  
  51.      -c : copy source file to target name.  Sets the file modifi-
  52.           cation time and permission bits of the target file to
  53.           that of the source file, regardless of whether the tar-
  54.           get file already exists.  Chains and cycles (to be
  55.           explained below) are not allowed.
  56.  
  57.      -o : overwrite target name with source file.  If target file
  58.           exists, it is overwritten, keeping its original owner
  59.           and permission bits.  If it does not exist, it is
  60.           created, with read-write permission bits set according
  61.           to umask(1), and the execute permission bits copied
  62.           from the source file.  In either case, the file modifi-
  63.           cation time is set to the current time.
  64.  
  65.      -a : append contents of source file to target name.  Target
  66.           file modification time is set to the current time.  If
  67.           target file does not exist, it is created with permis-
  68.           sion bits set as under -o.  Unlike all other options,
  69.           -a allows multiple source files to have the same target
  70.           name, e.g. "mmv -a \*.c big" will append all ".c" files
  71.           to "big".  Chains and cycles are also allowed, so "mmv
  72.           -a f f" will double up "f".
  73.  
  74.      -l : link target name to source file.  Both must be on the
  75.           same device, and the source must not be a directory.
  76.           Chains and cycles are not allowed.
  77.  
  78.      -s : same as -l, but use symbolic links instead of hard
  79.           links.  For the resulting link to aim back at the
  80.           source, either the source name must begin with a '/',
  81.           or the target must reside in either the current or the
  82.           source directory.  If none of these conditions are met,
  83.           the link is refused.  However, source and target can
  84.           reside on different devices, and the source can be a
  85.           directory.
  86.  
  87.      Only one of these option may be given, and it applies to all
  88.      matching files.  Remaining options need not be given
  89.      separately, i.e. "mmv -mk" is allowed.
  90.  
  91.                         Multiple Pattern Pairs
  92.  
  93.      Multiple from -- to pattern pairs may be specified by omit-
  94.      ting the pattern pair on the command line, and entering them
  95.      on the standard input, one pair per line.  (If a pattern
  96.      pair is given on the command line, the standard input is not
  97.      read.) Thus,
  98.  
  99.         mmv
  100.         a b
  101.         c d
  102.  
  103.      would rename "a" to "b" and "c" to "d".  If a file can be
  104.      matched to several of the given from patterns, the to pat-
  105.      tern of the first matching pair is used.  Thus,
  106.  
  107.         mmv
  108.         a b
  109.         a c
  110.  
  111.      would give the error message "a -> c : no match" because
  112.      file "a" (even if it exists) was already matched by the
  113.      first pattern pair.
  114.  
  115.                            The From Pattern
  116.  
  117.      The from pattern is a filename with embedded wildcards: '*',
  118.      '?', '['...']', and ';'.  The first three have their usual
  119.      sh(1) meanings of, respectively, matching any string of
  120.      characters, matching any single character, and matching any
  121.      one of a set of characters.
  122.  
  123.  
  124.      Between the '[' and ']', a range from character 'a' through
  125.      character 'z' is specified with "a-z".  The set of matching
  126.      characters can be negated by inserting a '^' after the '['.
  127.      Thus, "[^b-e2-5_]" will match any character but 'b' through
  128.      'e', '2' through '5', and '_'.
  129.  
  130.      Note that paths are allowed in the patterns, and wildcards
  131.      may be intermingled with slashes arbitrarily.  The ';' wild-
  132.      card is useful for matching files at any depth in the direc-
  133.      tory tree.  It matches the same as "*/" repeated any number
  134.      of times, including zero, and can only occur either at the
  135.      beginning of the pattern or following a '/'.  Thus ";*.c"
  136.      will match all ".c" files in or below the current directory,
  137.      while "/;*.c" will match them anywhere on the file system.
  138.  
  139.      In addition, if the from pattern (or the to pattern) begins
  140.      with "~/", the '~' is replaced with the home directory name.
  141.      (Note that the "~user" feature of csh(1) is not imple-
  142.      mented.) However, the '~' is not treated as a wildcard, in
  143.      the sense that it is not assigned a wildcard index (see
  144.      below).
  145.  
  146.      Since matching a directory under a task option other than -r
  147.      or -s would result in an error, tasks other than -r and -s
  148.      match directories only against completely explicit from pat-
  149.      terns (i.e. not containing wildcards).  Under -r and -s,
  150.      this applies only to "." and "..".
  151.  
  152.      Files beginning with '.' are only matched against from pat-
  153.      terns that begin with an explicit '.'.   However, if -h is
  154.      specified, they are matched normally.
  155.  
  156.      Warning: since the shell normally expands wildcards before
  157.      passing the command-line arguments to mmv, it is usually
  158.      necessary to enclose the command-line from pattern in
  159.      quotes.
  160.  
  161.                             The To Pattern
  162.  
  163.      The to pattern is a filename with embedded wildcard indexes,
  164.      where an index consists of the character '=' followed by a
  165.      string of digits.  When a source file matches a from pat-
  166.      tern, a target name for the file is constructed out of the
  167.      to pattern by replacing the wildcard indexes by the actual
  168.      characters that matched the referenced wildcards in the
  169.      source name.  Thus, if the from pattern is "abc*.*" and the
  170.      to pattern is "xyz=2.=1", then "abc.txt" is targeted to
  171.      "xyztxt.".  (The first '*' matched "", and the second
  172.      matched "txt".) Similarly, for the pattern pair ";*.[clp]"
  173.      -> "=1=3/=2", "foo1/foo2/prog.c" is targeted to
  174.      "foo1/foo2/c/prog".  Note that there is no '/' following the
  175.      "=1" in the to pattern, since the string matched by any ';'
  176.      is always either empty or ends in a '/'.  In this case, it
  177.      matches "foo1/foo2/".
  178.  
  179.      To convert the string matched by a wildcard to either lower-
  180.      case or uppercase before embedding it in the target name,
  181.      insert 'l' or 'u', respectively, between the '=' and the
  182.      string of digits.
  183.  
  184.      The to pattern, like the from pattern, can begin with a "~/"
  185.      (see above).  This does not necessitate enclosing the to
  186.      pattern in quotes on the command line since csh(1) expands
  187.      the '~' in the exact same manner as mmv (or, in the case of
  188.      sh(1), does not expand it at all).
  189.  
  190.      For all task options other than -r, if the target name is a
  191.      directory, the real target name is formed by appending a '/'
  192.      followed by the last component of the source file name.  For
  193.      example, "mmv dir1/a dir2" will, if "dir2" is indeed a
  194.      directory, actually move "dir1/a" to "dir2/a".  However, if
  195.      "dir2/a" already exists and is itself a directory, this is
  196.      considered an error.
  197.  
  198.      To strip any character (e.g. '*', '?', or '=') of its spe-
  199.      cial meaning to mmv, as when the actual replacement name
  200.      must contain the character '=', precede the special charac-
  201.      ter with a '\' (and enclose the argument in quotes because
  202.      of the shell).   This also works to terminate a wildcard
  203.      index when it has to be followed by a digit in the filename,
  204.      e.g. "a=1\1".
  205.  
  206.                           Chains and Cycles
  207.  
  208.      A chain is a sequence of specified actions where the target
  209.      name of one action refers to the source file of another
  210.      action.  For example,
  211.  
  212.      mmv
  213.      a b
  214.      b c
  215.  
  216.      specifies the chain "a" -> "b" -> "c".  A cycle is a chain
  217.      where the last target name refers back to the first source
  218.      file, e.g. "mmv a a".  Mmv detects chains and cycles regard-
  219.      less of the order in which their constituent actions are
  220.      actually given.  Where allowed, i.e. in moving, renaming,
  221.      and appending files, chains and cycles are handled grace-
  222.      fully, by performing them in the proper order.  Cycles are
  223.      broken by first renaming one of the files to a temporary
  224.      name (or just remembering its original size when doing
  225.      appends).
  226.  
  227.                        Collisions and Deletions
  228.  
  229.      When any two or more matching files would have to be moved,
  230.      copied, or linked to the same target filename, mmv detects
  231.      the condition as an error before performing any actions.
  232.      Furthermore, mmv checks if any of its actions will result in
  233.      the destruction of existing files.  If the -d (delete)
  234.      option is specified, all file deletions or overwrites are
  235.      done silently.  Under -p (protect), all deletions or
  236.      overwrites (except those specified with "(*)" on the stan-
  237.      dard input, see below) are treated as errors.  And if nei-
  238.      ther option is specified, the user is queried about each
  239.      deletion or overwrite separately.  (A new stream to
  240.      "/dev/tty" is used for all interactive queries, not the
  241.      standard input.)
  242.  
  243.                             Error Handling
  244.  
  245.      Whenever any error in the user's action specifications is
  246.      detected, an error message is given on the standard output,
  247.      and mmv proceeds to check the rest of the specified actions.
  248.      Once all errors are detected, mmv queries the user whether
  249.      he wishes to continue by avoiding the erroneous actions or
  250.      to abort altogether.  This and all other queries may be
  251.      avoided by specifying either the -g (go) or -t (terminate)
  252.      option.  The former will resolve all difficulties by avoid-
  253.      ing the erroneous actions; the latter will abort mmv if any
  254.      errors are detected.  Specifying either of them defaults mmv
  255.      to -p, unless -d is specified (see above).  Thus, -g and -t
  256.      are most useful when running mmv in the background or in a
  257.      shell script, when interactive queries are undesirable.
  258.  
  259.                                Reports
  260.  
  261.      Once the actions to be performed are determined, mmv per-
  262.      forms them silently, unless either the -v (verbose) or -n
  263.      (no-execute) option is specified.  The former causes mmv to
  264.      report each performed action on the standard output as
  265.  
  266.      a -> b : done.
  267.  
  268.      Here, "a" and "b" would be replaced by the source and target
  269.      names, respectively.  If the action deletes the old target,
  270.      a "(*)" is inserted after the the target name.  Also, the
  271.      "->" symbol is modified when a cycle has to be broken: the
  272.      '>' is changed to a '^' on the action prior to which the old
  273.      target is renamed to a temporary, and the '-' is changed to
  274.      a '=' on the action where the temporary is used.
  275.  
  276.      Under -n, none of the actions are performed, but messages
  277.      like the above are printed on the standard output with the
  278.      ": done." omitted.
  279.  
  280.      The output generated by -n can (after editing, if desired)
  281.      be fed back to mmv on the standard input (by omitting the
  282.      from -- to pair on the mmv command line).  To facilitate
  283.      this, mmv ignores lines on the standard input that look like
  284.      its own error and "done" messages, as well as all lines
  285.      beginning with white space, and will accept pattern pairs
  286.      with or without the intervening "->" (or "-^", "=>", or
  287.      "=^").  Lines with "(*)" after the target pattern have the
  288.      effect of enabling -d for the files matching this pattern
  289.      only, so that such deletions are done silently.  When feed-
  290.      ing mmv its own output, one must remember to specify again
  291.      the task option (if any) originally used to generate it.
  292.  
  293.      Although mmv attempts to predict all mishaps prior to per-
  294.      forming any specified actions, accidents may happen.  For
  295.      example, mmv does not check for adequate free space when
  296.      copying.  Thus, despite all efforts, it is still possible
  297.      for an action to fail after some others have already been
  298.      done.  To make recovery as easy as possible, mmv reports
  299.      which actions have already been done and which are still to
  300.      be performed after such a failure occurs.  It then aborts,
  301.      not attempting to do anything else.  Once the user has
  302.      cleared up the problem, he can feed this report back to mmv
  303.      on the standard input to have it complete the task.  (The
  304.      user is queried for a file name to dump this report if the
  305.      standard output has not been redirected.)
  306.  
  307. EXIT STATUS
  308.      Mmv exits with status 1 if it aborts before doing anything,
  309.      with status 2 if it aborts due to failure after completing
  310.      some of the actions, and with status 0 otherwise.
  311.  
  312. SEE ALSO
  313.      mv(1), cp(1), ln(1), umask(1)
  314.  
  315. AUTHOR
  316.      Vladimir Lanin
  317.      lanin@csd2.nyu.edu
  318.  
  319. BUGS
  320.      If the search pattern is not quoted, the shell expands the
  321.      wildcards.  Mmv then (usually) gives some error message, but
  322.      can not determine that the lack of quotes is the cause.
  323.  
  324.      To avoid difficulties in semantics and error checking, mmv
  325.      refuses to move or create directories.
  326.