On June 25, 2017 2:06:20 PM GMT+02:00, Job Snijders <j...@instituut.net> wrote: >Dear team, > >This patch adds a -v option to cp(1) for more verbose output. > > $ touch a b; mkdir c > $ cp -v a b c > 'a' -> 'c/a' > 'b' -> 'c/b' > $ cp -rv c d > 'c' -> 'd/' > 'c/a' -> 'd/a' > 'c/b' -> 'd/b'
Pardon my ignorance, but why? Is this a gnu thing? /Alexander > >Kind regards, > >Job > >diff --git bin/cp/cp.1 bin/cp/cp.1 >index 8573d801ca5..d4346d23f1d 100644 >--- bin/cp/cp.1 >+++ bin/cp/cp.1 >@@ -41,14 +41,14 @@ > .Nd copy files > .Sh SYNOPSIS > .Nm cp >-.Op Fl fip >+.Op Fl fipv > .Oo > .Fl R > .Op Fl H | L | P > .Oc > .Ar source target > .Nm cp >-.Op Fl fip >+.Op Fl fipv > .Oo > .Fl R > .Op Fl H | L | P >@@ -145,6 +145,8 @@ use a utility such as > or > .Xr tar 1 > instead. >+.It Fl v >+Explain what is being done. > .El > .Pp > For each destination file that already exists, its contents are >diff --git bin/cp/cp.c bin/cp/cp.c >index 643d82ed9fa..819e02f7be8 100644 >--- bin/cp/cp.c >+++ bin/cp/cp.c >@@ -71,7 +71,7 @@ > PATH_T to = { to.p_path, "" }; > > uid_t myuid; >-int Rflag, fflag, iflag, pflag, rflag; >+int Rflag, fflag, iflag, pflag, rflag, vflag; > mode_t myumask; > > enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; >@@ -88,7 +88,7 @@ main(int argc, char *argv[]) > char *target; > > Hflag = Lflag = Pflag = Rflag = 0; >- while ((ch = getopt(argc, argv, "HLPRfipr")) != -1) >+ while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1) > switch (ch) { > case 'H': > Hflag = 1; >@@ -119,6 +119,9 @@ main(int argc, char *argv[]) > case 'r': > rflag = 1; > break; >+ case 'v': >+ vflag = 1; >+ break; > default: > usage(); > break; >@@ -394,6 +397,9 @@ copy(char *argv[], enum op type, int fts_options) > case S_IFLNK: > if (copy_link(curr, !fts_dne(curr))) > rval = 1; >+ else if (vflag) >+ (void)fprintf(stdout, "'%s' -> '%s'\n", >+ curr->fts_path, to.p_path); > break; > case S_IFDIR: > if (!Rflag && !rflag) { >@@ -415,6 +421,9 @@ copy(char *argv[], enum op type, int fts_options) > if (mkdir(to.p_path, > curr->fts_statp->st_mode | S_IRWXU) < 0) > err(1, "%s", to.p_path); >+ else if (vflag) >+ (void)fprintf(stdout, "'%s' -> '%s'\n", >+ curr->fts_path, to.p_path); > } else if (!S_ISDIR(to_stat.st_mode)) > errc(1, ENOTDIR, "%s", to.p_path); > break; >@@ -426,6 +435,9 @@ copy(char *argv[], enum op type, int fts_options) > } else > if (copy_file(curr, fts_dne(curr))) > rval = 1; >+ if (!rval && vflag) >+ (void)fprintf(stdout, "'%s' -> '%s'\n", >+ curr->fts_path, to.p_path); > break; > case S_IFIFO: > if (Rflag) { >@@ -434,6 +446,9 @@ copy(char *argv[], enum op type, int fts_options) > } else > if (copy_file(curr, fts_dne(curr))) > rval = 1; >+ if (!rval && vflag) >+ (void)fprintf(stdout, "'%s' -> '%s'\n", >+ curr->fts_path, to.p_path); > break; > case S_IFSOCK: > warnc(EOPNOTSUPP, "%s", curr->fts_path); >@@ -441,6 +456,9 @@ copy(char *argv[], enum op type, int fts_options) > default: > if (copy_file(curr, fts_dne(curr))) > rval = 1; >+ else if (vflag) >+ (void)fprintf(stdout, "'%s' -> '%s'\n", >+ curr->fts_path, to.p_path); > break; > } > } >diff --git bin/cp/utils.c bin/cp/utils.c >index 6a3c5178647..2189dd4be1f 100644 >--- bin/cp/utils.c >+++ bin/cp/utils.c >@@ -307,9 +307,9 @@ void > usage(void) > { > (void)fprintf(stderr, >- "usage: %s [-fip] [-R [-H | -L | -P]] source target\n", >__progname); >+ "usage: %s [-fipv] [-R [-H | -L | -P]] source target\n", >__progname); > (void)fprintf(stderr, >- " %s [-fip] [-R [-H | -L | -P]] source ... directory\n", >+ " %s [-fipv] [-R [-H | -L | -P]] source ... directory\n", > __progname); > exit(1); > }