Hi all, This patch adds a -v option to mv(1) for more verbose output.
$ touch a $ mv -v a b 'a' -> 'b' $ mkdir c $ mv -v b c 'b' -> 'c/b' $ mv -v c d 'e' -> 'd' And here is an example of the output of the situation mentioned in the 'caveats' section in the manpage: $ touch f g; mkdir -p d/f $ mv -v f g d mv: rename f to d/f: Is a directory 'g' -> 'd/g' $ echo $? 1 Kind regards, Job diff --git bin/mv/mv.1 bin/mv/mv.1 index cb6c9d92673..fc8e642017e 100644 --- bin/mv/mv.1 +++ bin/mv/mv.1 @@ -103,6 +103,8 @@ The option overrides any previous .Fl f options. +.It Fl v +Explain what is being done. .El .Pp The diff --git bin/mv/mv.c bin/mv/mv.c index 003aca59e87..fa8654b50e4 100644 --- bin/mv/mv.c +++ bin/mv/mv.c @@ -51,7 +51,7 @@ extern char *__progname; -int fflg, iflg; +int fflg, iflg, vflg; int stdin_ok; extern int cpmain(int argc, char **argv); @@ -71,7 +71,7 @@ main(int argc, char *argv[]) int ch; char path[PATH_MAX]; - while ((ch = getopt(argc, argv, "if")) != -1) + while ((ch = getopt(argc, argv, "ifv")) != -1) switch (ch) { case 'i': fflg = 0; @@ -81,6 +81,9 @@ main(int argc, char *argv[]) iflg = 0; fflg = 1; break; + case 'v': + vflg = 1; + break; default: usage(); } @@ -208,8 +211,11 @@ do_move(char *from, char *to) * message to standard error, and do nothing more with the * current source file... */ - if (!rename(from, to)) + if (!rename(from, to)) { + if (vflg) + (void)fprintf(stdout, "'%s' -> '%s'\n", from, to); return (0); + } if (errno != EXDEV) { warn("rename %s to %s", from, to); @@ -339,6 +345,10 @@ err: if (unlink(to)) warn("%s: remove", from); return (1); } + + if (vflg) + (void)fprintf(stdout, "'%s' -> '%s'\n", from, to); + return (0); } @@ -362,14 +372,17 @@ mvcopy(char *from, char *to) _exit(1); } + if (vflg) + (void)fprintf(stdout, "'%s' -> '%s'\n", from, to); + return (0); } void usage(void) { - (void)fprintf(stderr, "usage: %s [-fi] source target\n", __progname); - (void)fprintf(stderr, " %s [-fi] source ... directory\n", + (void)fprintf(stderr, "usage: %s [-fiv] source target\n", __progname); + (void)fprintf(stderr, " %s [-fiv] source ... directory\n", __progname); exit(1); }