summaryrefslogtreecommitdiffstats
path: root/bin/mv
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2002-03-22 07:45:36 +0000
committerobrien <obrien@FreeBSD.org>2002-03-22 07:45:36 +0000
commit6295b3bfe1dca423c3e2bd92ddd960095ef1d3e6 (patch)
treeeacac83c7a9252e02285f1cc8245259528fd246a /bin/mv
parent7b860ddffdc4cfd214cf139353bc6f59317676c5 (diff)
downloadFreeBSD-src-6295b3bfe1dca423c3e2bd92ddd960095ef1d3e6.zip
FreeBSD-src-6295b3bfe1dca423c3e2bd92ddd960095ef1d3e6.tar.gz
Add the -n option, which automatically answers "no" to the overwrite question.
Diffstat (limited to 'bin/mv')
-rw-r--r--bin/mv/mv.115
-rw-r--r--bin/mv/mv.c18
2 files changed, 27 insertions, 6 deletions
diff --git a/bin/mv/mv.1 b/bin/mv/mv.1
index b73c644..d9a42bd 100644
--- a/bin/mv/mv.1
+++ b/bin/mv/mv.1
@@ -43,7 +43,7 @@
.Nd move files
.Sh SYNOPSIS
.Nm
-.Op Fl f | Fl i
+.Op Fl f | Fl i | Fl n
.Op Fl v
.Ar source target
.Nm
@@ -81,6 +81,8 @@ path.
.Fl f
option overrides any previous
.Fl i
+or
+.Fl n
options.)
.It Fl i
Cause
@@ -96,6 +98,17 @@ the move is attempted.
.Fl i
option overrides any previous
.Fl f
+or
+.Fl n
+options.)
+.It Fl n
+Do not overwriting an existing file.
+(The
+.Fl n
+option overrides any previous
+.Fl f
+or
+.Fl i
options.)
.It Fl v
Cause
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index 9aaea066..1777a64 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -68,7 +68,7 @@ static const char rcsid[] =
#include "pathnames.h"
-int fflg, iflg, vflg;
+int fflg, iflg, nflg, vflg;
int copy(char *, char *);
int do_move(char *, char *);
@@ -85,15 +85,19 @@ main(int argc, char *argv[])
int ch;
char path[PATH_MAX];
- while ((ch = getopt(argc, argv, "fiv")) != -1)
+ while ((ch = getopt(argc, argv, "finv")) != -1)
switch (ch) {
case 'i':
iflg = 1;
- fflg = 0;
+ fflg = nflg = 0;
break;
case 'f':
fflg = 1;
- iflg = 0;
+ iflg = nflg = 0;
+ break;
+ case 'n':
+ nflg = 1;
+ fflg = iflg = 0;
break;
case 'v':
vflg = 1;
@@ -172,7 +176,11 @@ do_move(char *from, char *to)
#define YESNO "(y/n [n]) "
ask = 0;
- if (iflg) {
+ if (nflg) {
+ if (vflg)
+ printf("%s not overwritten\n", to);
+ return (0);
+ } else if (iflg) {
(void)fprintf(stderr, "overwrite %s? %s", to, YESNO);
ask = 1;
} else if (access(to, W_OK) && !stat(to, &sb)) {
OpenPOWER on IntegriCloud