From 92582195dad1af4e9e5e1be8f7a58503fd3c076a Mon Sep 17 00:00:00 2001 From: mharo Date: Sun, 29 Aug 1999 08:21:16 +0000 Subject: add verbose flag --- bin/mv/mv.1 | 6 ++++++ bin/mv/mv.c | 24 +++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'bin/mv') diff --git a/bin/mv/mv.1 b/bin/mv/mv.1 index be97d80..efec25d 100644 --- a/bin/mv/mv.1 +++ b/bin/mv/mv.1 @@ -44,9 +44,11 @@ .Sh SYNOPSIS .Nm mv .Op Fl f | Fl i +.Op Fl v .Ar source target .Nm mv .Op Fl f | Fl i +.Op Fl v .Ar source ... directory .Sh DESCRIPTION In its first form, the @@ -95,6 +97,10 @@ the move is attempted. option overrides any previous .Fl f options.) +.It Fl v +Cause +.Nm +to be verbose, showing files after they are moved. .El .Pp It is an error for either the diff --git a/bin/mv/mv.c b/bin/mv/mv.c index 6db4192..5f0f28b 100644 --- a/bin/mv/mv.c +++ b/bin/mv/mv.c @@ -60,11 +60,12 @@ static const char rcsid[] = #include #include #include +#include #include #include "pathnames.h" -int fflg, iflg; +int fflg, iflg, vflg; int copy __P((char *, char *)); int do_move __P((char *, char *)); @@ -82,7 +83,7 @@ main(argc, argv) int ch; char path[MAXPATHLEN]; - while ((ch = getopt(argc, argv, "fi")) != -1) + while ((ch = getopt(argc, argv, "fiv")) != -1) switch (ch) { case 'i': iflg = 1; @@ -92,6 +93,9 @@ main(argc, argv) fflg = 1; iflg = 0; break; + case 'v': + vflg = 1; + break; default: usage(); } @@ -188,8 +192,11 @@ do_move(from, to) } } } - if (!rename(from, to)) + if (!rename(from, to)) { + if (vflg) + printf("%s -> %s\n", from, to); return (0); + } if (errno == EXDEV) { struct statfs sfs; @@ -299,6 +306,8 @@ err: if (unlink(to)) warn("%s: remove", from); return (1); } + if (vflg) + printf("%s -> %s\n", from, to); return (0); } @@ -309,7 +318,7 @@ copy(from, to) int pid, status; if ((pid = fork()) == 0) { - execl(_PATH_CP, "mv", "-PRp", from, to, NULL); + execl(_PATH_CP, "mv", vflg ? "-PRpv" : "-PRp", from, to, NULL); warn("%s", _PATH_CP); _exit(1); } @@ -350,8 +359,9 @@ copy(from, to) void usage() { + (void)fprintf(stderr, "%s\n%s\n", - "usage: mv [-f | -i] source target", - " mv [-f | -i] source ... directory"); - exit(1); + "usage: mv [-f | -i] [-v] source target", + " mv [-f | -i] [-v] source ... directory"); + exit(EX_USAGE); } -- cgit v1.1