diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2017-06-27 21:43:47 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2017-06-27 21:43:47 +0000 |
commit | 7169c492918dcafdc3ea004051d9aa8b4c39932e (patch) | |
tree | 03d472860e200de030c49ab648788b3416b0058f /bin/cp | |
parent | 7ada802e7e89cfc3680123bc7f80f7413eccb4f2 (diff) |
add a -v verbose flag to cp, mv, and rm. useful for monitoring progress,
and present on several other systems. some ok, some less ok.
from Job Snijders
Diffstat (limited to 'bin/cp')
-rw-r--r-- | bin/cp/cp.1 | 10 | ||||
-rw-r--r-- | bin/cp/cp.c | 24 | ||||
-rw-r--r-- | bin/cp/utils.c | 6 |
3 files changed, 30 insertions, 10 deletions
diff --git a/bin/cp/cp.1 b/bin/cp/cp.1 index 8573d801ca5..756f8abe8e2 100644 --- a/bin/cp/cp.1 +++ b/bin/cp/cp.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cp.1,v 1.37 2014/03/19 14:42:44 tedu Exp $ +.\" $OpenBSD: cp.1,v 1.38 2017/06/27 21:43:46 tedu Exp $ .\" $NetBSD: cp.1,v 1.9 1995/07/25 19:36:45 jtc Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 @@ -33,7 +33,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd $Mdocdate: March 19 2014 $ +.Dd $Mdocdate: June 27 2017 $ .Dt CP 1 .Os .Sh NAME @@ -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 +Display the source and destination after each copy. .El .Pp For each destination file that already exists, its contents are diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 643d82ed9fa..f999dc789d6 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cp.c,v 1.44 2016/10/14 10:51:57 schwarze Exp $ */ +/* $OpenBSD: cp.c,v 1.45 2017/06/27 21:43:46 tedu Exp $ */ /* $NetBSD: cp.c,v 1.14 1995/09/07 06:14:51 jtc Exp $ */ /* @@ -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 a/bin/cp/utils.c b/bin/cp/utils.c index 6a3c5178647..c9d71986842 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utils.c,v 1.39 2015/12/26 18:11:43 guenther Exp $ */ +/* $OpenBSD: utils.c,v 1.40 2017/06/27 21:43:46 tedu Exp $ */ /* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */ /*- @@ -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); } |