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
This commit is contained in:
+18
-3
@@ -47,7 +47,7 @@
|
|||||||
.Fl R
|
.Fl R
|
||||||
.Op Fl H | Fl L | Fl P
|
.Op Fl H | Fl L | Fl P
|
||||||
.Oc
|
.Oc
|
||||||
.Op Fl f | i
|
.Op Fl f | i | n
|
||||||
.Op Fl pv
|
.Op Fl pv
|
||||||
.Ar source_file target_file
|
.Ar source_file target_file
|
||||||
.Nm
|
.Nm
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
.Fl R
|
.Fl R
|
||||||
.Op Fl H | Fl L | Fl P
|
.Op Fl H | Fl L | Fl P
|
||||||
.Oc
|
.Oc
|
||||||
.Op Fl f | i
|
.Op Fl f | i | n
|
||||||
.Op Fl pv
|
.Op Fl pv
|
||||||
.Ar source_file ... target_directory
|
.Ar source_file ... target_directory
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
@@ -121,6 +121,8 @@ regardless of its permissions.
|
|||||||
.Fl f
|
.Fl f
|
||||||
option overrides any previous
|
option overrides any previous
|
||||||
.Fl i
|
.Fl i
|
||||||
|
or
|
||||||
|
.Fl n
|
||||||
options.)
|
options.)
|
||||||
.It Fl i
|
.It Fl i
|
||||||
Cause
|
Cause
|
||||||
@@ -136,6 +138,17 @@ the file copy is attempted.
|
|||||||
.Fl i
|
.Fl i
|
||||||
option overrides any previous
|
option overrides any previous
|
||||||
.Fl f
|
.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.)
|
options.)
|
||||||
.It Fl p
|
.It Fl p
|
||||||
Cause
|
Cause
|
||||||
@@ -226,7 +239,9 @@ or fifo's.
|
|||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fl v
|
.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
|
.Sh SEE ALSO
|
||||||
.Xr mv 1 ,
|
.Xr mv 1 ,
|
||||||
.Xr rcp 1 ,
|
.Xr rcp 1 ,
|
||||||
|
|||||||
+9
-5
@@ -86,8 +86,8 @@ static char emptystring[] = "";
|
|||||||
|
|
||||||
PATH_T to = { to.p_path, emptystring, "" };
|
PATH_T to = { to.p_path, emptystring, "" };
|
||||||
|
|
||||||
int iflag, pflag, fflag;
|
int fflag, iflag, nflag, pflag, vflag;
|
||||||
static int Rflag, rflag, vflag;
|
static int Rflag, rflag;
|
||||||
|
|
||||||
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
|
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ main(int argc, char *argv[])
|
|||||||
char *target;
|
char *target;
|
||||||
|
|
||||||
Hflag = Lflag = Pflag = 0;
|
Hflag = Lflag = Pflag = 0;
|
||||||
while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1)
|
while ((ch = getopt(argc, argv, "HLPRfinprv")) != -1)
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'H':
|
case 'H':
|
||||||
Hflag = 1;
|
Hflag = 1;
|
||||||
@@ -122,11 +122,15 @@ main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
fflag = 1;
|
fflag = 1;
|
||||||
iflag = 0;
|
iflag = nflag = 0;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
iflag = 1;
|
iflag = 1;
|
||||||
fflag = 0;
|
fflag = nflag = 0;
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
nflag = 1;
|
||||||
|
fflag = iflag = 0;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
pflag = 1;
|
pflag = 1;
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ typedef struct {
|
|||||||
} PATH_T;
|
} PATH_T;
|
||||||
|
|
||||||
extern PATH_T to;
|
extern PATH_T to;
|
||||||
extern int fflag, iflag, pflag;
|
extern int fflag, iflag, nflag, pflag, vflag;
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
int copy_fifo(struct stat *, int);
|
int copy_fifo(struct stat *, int);
|
||||||
|
|||||||
+7
-3
@@ -87,7 +87,11 @@ copy_file(FTSENT *entp, int dne)
|
|||||||
*/
|
*/
|
||||||
if (!dne) {
|
if (!dne) {
|
||||||
#define YESNO "(y/n [n]) "
|
#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",
|
(void)fprintf(stderr, "overwrite %s? %s",
|
||||||
to.p_path, YESNO);
|
to.p_path, YESNO);
|
||||||
checkch = ch = getchar();
|
checkch = ch = getchar();
|
||||||
@@ -300,7 +304,7 @@ usage(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
(void)fprintf(stderr, "%s\n%s\n",
|
(void)fprintf(stderr, "%s\n%s\n",
|
||||||
"usage: cp [-R [-H | -L | -P]] [-f | -i] [-pv] src target",
|
"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src target",
|
||||||
" cp [-R [-H | -L | -P]] [-f | -i] [-pv] src1 ... srcN directory");
|
" cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src1 ... srcN directory");
|
||||||
exit(EX_USAGE);
|
exit(EX_USAGE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user