From 404227c86552cfc826bfba90aca6ae99c1b4bfcf Mon Sep 17 00:00:00 2001 From: deraadt Date: Tue, 1 Apr 1997 22:59:36 +0000 Subject: [PATCH] option 'n' was unused, so let's come up with a feature to use it!!! YEAH!! add -n (numeric uid/gid), fix some man page errors; tv@pobox.com --- bin/ls/ls.1 | 38 +++++++++++++++++++++++++++----------- bin/ls/ls.c | 25 ++++++++++++++++++++----- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/bin/ls/ls.1 b/bin/ls/ls.1 index 4f4b06d0728..f3e35fbbe05 100644 --- a/bin/ls/ls.1 +++ b/bin/ls/ls.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ls.1,v 1.3 1996/06/23 14:20:19 deraadt Exp $ +.\" $OpenBSD: ls.1,v 1.4 1997/04/01 22:59:36 deraadt Exp $ .\" $NetBSD: ls.1,v 1.14 1995/12/05 02:44:01 jtc Exp $ .\" .\" Copyright (c) 1980, 1990, 1991, 1993, 1994 @@ -45,7 +45,7 @@ .Nd list directory contents .Sh SYNOPSIS .Nm ls -.Op Fl ACFLRSTWacdfikloqrstu1 +.Op Fl ACFLRSTWacdfgiklnoqrstu1 .Op Ar file ... .Sh DESCRIPTION For each operand that names a @@ -109,6 +109,9 @@ Directories are listed as plain files (not searched recursively) and symbolic links in the argument list are not indirected through. .It Fl f Output is not sorted. +.It Fl g +Does nothing; kept for compatibility with older versions of +.Xr ls 1 . .It Fl i For each file, print the file's file serial number (inode number). .It Fl k @@ -119,10 +122,14 @@ option, causing the sizes to be reported in kilobytes. (The lowercase letter ``ell.'') List in long format. (See below.) If the output is to a terminal, a total sum for all the file sizes is output on a line before the long listing. +.It Fl n +List in long format as in +.Fl l , +but retain user and group IDs in a numeric format. .It Fl o Include the file flags in a long .Pq Fl l -output +output. .It Fl q Force printing of non-graphic characters in file names as the character `?'; this is the default when output is to a terminal. @@ -155,8 +162,9 @@ output is not to a terminal. The .Fl 1 , .Fl C , +.Fl l , and -.Fl l +.Fl n options all override each other; the last one specified determines the format used. .Pp @@ -178,13 +186,16 @@ File information is displayed with one or more s separating the information associated with the .Fl i , .Fl s , +.Fl l , and -.Fl l +.Fl n options. .Ss The Long Format If the .Fl l -option is given, the following information +or +.Fl n +options are given, the following information is displayed for each file: file mode, number of links, owner name, group name, @@ -197,8 +208,10 @@ number of 512-byte blocks used by the files in the directory is displayed on a line by itself immediately before the information for the files in the directory. .Pp -If the owner or group names are not a known user or group name -the numeric ID's are displayed. +If the owner or group names are not a known user or group name, +or the +.Fl n +option is given, the numeric ID's are displayed. .Pp If the file is a character special or block special file, the major and minor device numbers for the file are displayed @@ -206,9 +219,12 @@ in the size field. If the file is a symbolic link the pathname of the linked-to file is preceded by .Dq \-> . .Pp -The file mode printed under the -l option consists of the -entry type, owner permissions, and group permissions. -The entry type character describes the type of file, as +The file mode printed under the +.Fl l +or +.Fl n +options consists of the entry type, owner permissions, and group +permissions. The entry type character describes the type of file, as follows: .Pp .Bl -tag -width 4n -offset indent -compact diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 7dc75185714..893f65817f3 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ls.c,v 1.6 1997/01/03 22:36:08 millert Exp $ */ +/* $OpenBSD: ls.c,v 1.7 1997/04/01 22:59:38 deraadt Exp $ */ /* $NetBSD: ls.c,v 1.18 1996/07/09 09:16:29 mycroft Exp $ */ /* @@ -47,7 +47,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.6 1997/01/03 22:36:08 millert Exp $"; +static char rcsid[] = "$OpenBSD: ls.c,v 1.7 1997/04/01 22:59:38 deraadt Exp $"; #endif #endif /* not lint */ @@ -96,6 +96,7 @@ int f_longform; /* long listing format */ int f_newline; /* if precede with newline */ int f_nonprint; /* show unprintables as ? */ int f_nosort; /* don't sort output */ +int f_numericonly; /* don't expand uid to symbolic name */ int f_recursive; /* ls subdirectories also */ int f_reversesort; /* reverse whatever sort is used */ int f_sectime; /* print the real time for all files */ @@ -133,7 +134,7 @@ main(argc, argv) f_listdot = 1; fts_options = FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "1ACFLRSTWacdfgikloqrstu")) != -1) { + while ((ch = getopt(argc, argv, "1ACFLRSTWacdfgiklnoqrstu")) != -1) { switch (ch) { /* * The -1, -C and -l options all override each other so shell @@ -149,6 +150,12 @@ main(argc, argv) break; case 'l': f_longform = 1; + f_numericonly = 0; + f_column = f_singlecol = 0; + break; + case 'n': + f_longform = 1; + f_numericonly = 1; f_column = f_singlecol = 0; break; /* The -c and -u options override each other. */ @@ -392,6 +399,7 @@ display(p, list) int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser; int entries, needstats; char *user, *group, buf[20]; /* 32 bits == 10 digits */ + char nuser[12], ngroup[12]; char *flags = NULL; /* @@ -452,10 +460,17 @@ display(p, list) btotal += sp->st_blocks; if (f_longform) { - user = user_from_uid(sp->st_uid, 0); + if (f_numericonly) { + snprintf(nuser, 12, "%u", sp->st_uid); + snprintf(ngroup, 12, "%u", sp->st_gid); + user = nuser; + group = ngroup; + } else { + user = user_from_uid(sp->st_uid, 0); + group = group_from_gid(sp->st_gid, 0); + } if ((ulen = strlen(user)) > maxuser) maxuser = ulen; - group = group_from_gid(sp->st_gid, 0); if ((glen = strlen(group)) > maxgroup) maxgroup = glen; if (f_flags) { -- 2.20.1