summaryrefslogtreecommitdiffstats
path: root/bin/cp
diff options
context:
space:
mode:
authorjohan <johan@FreeBSD.org>2002-07-23 00:42:56 +0000
committerjohan <johan@FreeBSD.org>2002-07-23 00:42:56 +0000
commitc464bca234e43e5c9d7076042f3261ce368fbc4e (patch)
tree49671495a38f4cacd1e75c9f73f7e469e9ee79ec /bin/cp
parent7bd1d4e8de5727f9c13675ff5ab143c5dd5bb66e (diff)
downloadFreeBSD-src-c464bca234e43e5c9d7076042f3261ce368fbc4e.zip
FreeBSD-src-c464bca234e43e5c9d7076042f3261ce368fbc4e.tar.gz
Add the -n option, which automatically answers "no" to the overwrite question.
PR: 7828 Suggested by: Daniel O'Connor <doconnor@gsoft.com.au> Approved by: sheldonh (mentor) MFC after: 2 weeks
Diffstat (limited to 'bin/cp')
-rw-r--r--bin/cp/cp.121
-rw-r--r--bin/cp/cp.c14
-rw-r--r--bin/cp/extern.h2
-rw-r--r--bin/cp/utils.c10
4 files changed, 35 insertions, 12 deletions
diff --git a/bin/cp/cp.1 b/bin/cp/cp.1
index c682ae1..5c83a9a 100644
--- a/bin/cp/cp.1
+++ b/bin/cp/cp.1
@@ -47,7 +47,7 @@
.Fl R
.Op Fl H | Fl L | Fl P
.Oc
-.Op Fl f | i
+.Op Fl f | i | n
.Op Fl pv
.Ar source_file target_file
.Nm
@@ -55,7 +55,7 @@
.Fl R
.Op Fl H | Fl L | Fl P
.Oc
-.Op Fl f | i
+.Op Fl f | i | n
.Op Fl pv
.Ar source_file ... target_directory
.Sh DESCRIPTION
@@ -121,6 +121,8 @@ regardless of its permissions.
.Fl f
option overrides any previous
.Fl i
+or
+.Fl n
options.)
.It Fl i
Cause
@@ -136,6 +138,17 @@ the file copy 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 p
Cause
@@ -226,7 +239,9 @@ or fifo's.
.Pp
The
.Fl v
-option is non-standard and its use in scripts is not recommended.
+and
+.Fl n
+options are non-standard and their use in scripts is not recommended.
.Sh SEE ALSO
.Xr mv 1 ,
.Xr rcp 1 ,
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index 2e17f75..5a7834e 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -86,8 +86,8 @@ static char emptystring[] = "";
PATH_T to = { to.p_path, emptystring, "" };
-int iflag, pflag, fflag;
-static int Rflag, rflag, vflag;
+int fflag, iflag, nflag, pflag, vflag;
+static int Rflag, rflag;
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
@@ -103,7 +103,7 @@ main(int argc, char *argv[])
char *target;
Hflag = Lflag = Pflag = 0;
- while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1)
+ while ((ch = getopt(argc, argv, "HLPRfinprv")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -122,11 +122,15 @@ main(int argc, char *argv[])
break;
case 'f':
fflag = 1;
- iflag = 0;
+ iflag = nflag = 0;
break;
case 'i':
iflag = 1;
- fflag = 0;
+ fflag = nflag = 0;
+ break;
+ case 'n':
+ nflag = 1;
+ fflag = iflag = 0;
break;
case 'p':
pflag = 1;
diff --git a/bin/cp/extern.h b/bin/cp/extern.h
index 9f7ca4a..72484f2 100644
--- a/bin/cp/extern.h
+++ b/bin/cp/extern.h
@@ -41,7 +41,7 @@ typedef struct {
} PATH_T;
extern PATH_T to;
-extern int fflag, iflag, pflag;
+extern int fflag, iflag, nflag, pflag, vflag;
__BEGIN_DECLS
int copy_fifo(struct stat *, int);
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index a10daa9..364f983 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -87,7 +87,11 @@ copy_file(FTSENT *entp, int dne)
*/
if (!dne) {
#define YESNO "(y/n [n]) "
- if (iflag) {
+ if (nflag) {
+ if (vflag)
+ printf("%s not overwritten\n", to.p_path);
+ return (0);
+ } else if (iflag) {
(void)fprintf(stderr, "overwrite %s? %s",
to.p_path, YESNO);
checkch = ch = getchar();
@@ -300,7 +304,7 @@ usage(void)
{
(void)fprintf(stderr, "%s\n%s\n",
-"usage: cp [-R [-H | -L | -P]] [-f | -i] [-pv] src target",
-" cp [-R [-H | -L | -P]] [-f | -i] [-pv] src1 ... srcN directory");
+"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src target",
+" cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src1 ... srcN directory");
exit(EX_USAGE);
}
OpenPOWER on IntegriCloud