summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/ls/ls.136
-rw-r--r--bin/ls/ls.c22
-rw-r--r--bin/ls/ls.h3
-rw-r--r--bin/ls/print.c11
4 files changed, 51 insertions, 21 deletions
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index dfc7c7ff77b..eec8842bf8c 100644
--- a/bin/ls/ls.1
+++ b/bin/ls/ls.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ls.1,v 1.47 2007/03/03 23:26:12 jmc Exp $
+.\" $OpenBSD: ls.1,v 1.48 2007/05/07 18:39:28 millert Exp $
.\" $NetBSD: ls.1,v 1.14 1995/12/05 02:44:01 jtc Exp $
.\"
.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
@@ -111,8 +111,9 @@ after each that is a FIFO.
.It Fl f
Output is not sorted.
.It Fl g
-Does nothing; kept for compatibility with older versions of
-.Nm ls .
+The same as
+.Fl l ,
+except that the owner is not printed.
.It Fl h
When used with a long format
option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte,
@@ -198,11 +199,19 @@ Multi-column output sorted across the page rather than down the page.
The
.Fl 1 ,
.Fl C ,
+.Fl g ,
.Fl l ,
and
.Fl n
options all override each other; the last one specified determines
-the format used.
+the format used with the exception that if both
+.Fl l
+and
+.Fl g
+are specified,
+.Fl l
+will always override
+.Fl g .
.Pp
The
.Fl c
@@ -446,15 +455,20 @@ printed first:
.Xr symlink 7 ,
.Xr sticky 8
.Sh STANDARDS
-The group field is now automatically included in the long listing for
-files in order to be compatible with the
-.St -p1003.2
-specification.
-.Pp
The
.Nm
-utility is expected to be a superset of the
-.St -p1003.2
+utility is a superset of the
+.St -p1003.1-2004
+specification.
+.Pp
+Historically, the
+.Fl g
+flag was used to specify that the group field be included in long listings.
+The group field is now automatically included in the long listing for
+files and the meaning of the
+.Fl g
+flag has been changed in order to be compatible with the
+.St -p1003.1-2004
specification.
.Sh HISTORY
An
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 12addc1be85..e9156ae39ce 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ls.c,v 1.28 2006/04/13 03:14:18 dhill Exp $ */
+/* $OpenBSD: ls.c,v 1.29 2007/05/07 18:39:28 millert Exp $ */
/* $NetBSD: ls.c,v 1.18 1996/07/09 09:16:29 mycroft Exp $ */
/*
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)ls.c 8.7 (Berkeley) 8/5/94";
#else
-static char rcsid[] = "$OpenBSD: ls.c,v 1.28 2006/04/13 03:14:18 dhill Exp $";
+static char rcsid[] = "$OpenBSD: ls.c,v 1.29 2007/05/07 18:39:28 millert Exp $";
#endif
#endif /* not lint */
@@ -86,6 +86,7 @@ int f_accesstime; /* use time of last access */
int f_column; /* columnated format */
int f_columnacross; /* columnated format, sorted across */
int f_flags; /* show flags associated with a file */
+int f_grouponly; /* long listing format without owner */
int f_humanval; /* show human-readable file sizes */
int f_inode; /* print inode */
int f_listdir; /* list actual directory, not contents */
@@ -145,8 +146,16 @@ ls_main(int argc, char *argv[])
f_column = 1;
f_longform = f_columnacross = f_singlecol = f_stream = 0;
break;
+ case 'g':
+ f_longform = 1;
+ if (f_grouponly != -1)
+ f_grouponly = 1;
+ f_numericonly = 0;
+ f_column = f_columnacross = f_singlecol = f_stream = 0;
+ break;
case 'l':
f_longform = 1;
+ f_grouponly = -1; /* -l always overrides -g */
f_numericonly = 0;
f_column = f_columnacross = f_singlecol = f_stream = 0;
break;
@@ -197,8 +206,6 @@ ls_main(int argc, char *argv[])
case 'f':
f_nosort = 1;
break;
- case 'g': /* Compatibility with 4.3BSD. */
- break;
case 'h':
f_humanval = 1;
break;
@@ -241,6 +248,13 @@ ls_main(int argc, char *argv[])
argv += optind;
/*
+ * If both -g and -l options, let -l take precedence.
+ * This preserves compatibility with the historic BSD ls -lg.
+ */
+ if (f_grouponly == -1)
+ f_grouponly = 0;
+
+ /*
* If not -F, -i, -l, -p, -S, -s or -t options, don't require stat
* information.
*/
diff --git a/bin/ls/ls.h b/bin/ls/ls.h
index 2c1c65310d1..fc4f140aeb4 100644
--- a/bin/ls/ls.h
+++ b/bin/ls/ls.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ls.h,v 1.7 2003/08/06 19:09:09 tedu Exp $ */
+/* $OpenBSD: ls.h,v 1.8 2007/05/07 18:39:28 millert Exp $ */
/* $NetBSD: ls.h,v 1.7 1995/03/21 09:06:33 cgd Exp $ */
/*
@@ -41,6 +41,7 @@ extern long blocksize; /* block size units */
extern int f_accesstime; /* use time of last access */
extern int f_flags; /* show flags associated with a file */
+extern int f_grouponly; /* long listing format without owner */
extern int f_humanval; /* show human-readable file sizes */
extern int f_inode; /* print inode */
extern int f_longform; /* long listing format */
diff --git a/bin/ls/print.c b/bin/ls/print.c
index 44f49df0c6f..e5fac1b56b2 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print.c,v 1.24 2005/06/15 17:47:17 millert Exp $ */
+/* $OpenBSD: print.c,v 1.25 2007/05/07 18:39:28 millert Exp $ */
/* $NetBSD: print.c,v 1.15 1996/12/11 03:25:39 thorpej Exp $ */
/*
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)print.c 8.5 (Berkeley) 7/28/94";
#else
-static char rcsid[] = "$OpenBSD: print.c,v 1.24 2005/06/15 17:47:17 millert Exp $";
+static char rcsid[] = "$OpenBSD: print.c,v 1.25 2007/05/07 18:39:28 millert Exp $";
#endif
#endif /* not lint */
@@ -104,9 +104,10 @@ printlong(DISPLAY *dp)
dp->s_block, howmany(sp->st_blocks, blocksize));
(void)strmode(sp->st_mode, buf);
np = p->fts_pointer;
- (void)printf("%s %*u %-*s %-*s ", buf, dp->s_nlink,
- sp->st_nlink, dp->s_user, np->user, dp->s_group,
- np->group);
+ (void)printf("%s %*u ", buf, dp->s_nlink, sp->st_nlink);
+ if (!f_grouponly)
+ (void)printf("%-*s ", dp->s_user, np->user);
+ (void)printf("%-*s ", dp->s_group, np->group);
if (f_flags)
(void)printf("%-*s ", dp->s_flags, np->flags);
if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))