Small patch to add -a to cp

David Frascone frasconebulk at gmail.com
Mon Feb 11 22:16:19 UTC 2008


This small patch adds the -a (archive) flag to cp.  Personally, I use cp -a
all the time, and I miss it on BSD.  This makes cp share the common -a flag
with rsync and other file manipulation utilities.

Comments, flames, etc welcome.

-Dave
-------------- next part --------------
Index: bin/cp/cp.1
===================================================================
RCS file: /usr/FreeBSD/cvsup/src/bin/cp/cp.1,v
retrieving revision 1.39
diff -u -r1.39 cp.1
--- bin/cp/cp.1	2 Nov 2006 19:10:05 -0000	1.39
+++ bin/cp/cp.1	6 Feb 2008 16:45:48 -0000
@@ -116,6 +116,9 @@
 or
 .Xr pax 1
 instead.
+.It Fl a
+Archive mode:  The same as 
+.Fl rpP
 .It Fl f
 For each existing destination pathname, remove it and
 create a new file, without prompting for confirmation
Index: bin/cp/cp.c
===================================================================
RCS file: /usr/FreeBSD/cvsup/src/bin/cp/cp.c,v
retrieving revision 1.59
diff -u -r1.59 cp.c
--- bin/cp/cp.c	26 Dec 2007 08:32:20 -0000	1.59
+++ bin/cp/cp.c	11 Feb 2008 21:43:36 -0000
@@ -102,7 +102,7 @@
 	char *target;
 
 	Hflag = Lflag = Pflag = 0;
-	while ((ch = getopt(argc, argv, "HLPRfilnprv")) != -1)
+	while ((ch = getopt(argc, argv, "HLPRafilnprv")) != -1)
 		switch (ch) {
 		case 'H':
 			Hflag = 1;
@@ -119,6 +119,10 @@
 		case 'R':
 			Rflag = 1;
 			break;
+		case 'a':
+			Pflag = pflag = rflag = 1;
+			Hflag = Lflag = 0;
+			break;
 		case 'f':
 			fflag = 1;
 			iflag = nflag = 0;
Index: bin/cp/utils.c
===================================================================
RCS file: /usr/FreeBSD/cvsup/src/bin/cp/utils.c,v
retrieving revision 1.52
diff -u -r1.52 utils.c
--- bin/cp/utils.c	7 Oct 2006 12:14:50 -0000	1.52
+++ bin/cp/utils.c	6 Feb 2008 16:43:50 -0000
@@ -429,8 +429,8 @@
 {
 
 	(void)fprintf(stderr, "%s\n%s\n",
-"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-lpv] source_file target_file",
-"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-lpv] source_file ... "
+"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file target_file",
+"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file ... "
 "target_directory");
 	exit(EX_USAGE);
 }


More information about the freebsd-current mailing list