Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Jul 1999 01:14:10 -0500 (CDT)
From:      pckizer@nostrum.com
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/12866: [PATCH] RFE for /bin/ls to add a -n option for showing uid/gid numerically
Message-ID:  <199907290614.BAA05429@hermit.bcs.nostrum.com>

next in thread | raw e-mail | index | archive | help

>Number:         12866
>Category:       bin
>Synopsis:       [PATCH] RFE for /bin/ls to add a -n option for showing uid/gid numerically
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 28 23:20:00 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Philip Kizer
>Release:        FreeBSD 3.2-STABLE i386
>Organization:
Texas A&M University
>Environment:

        FreeBSD hermit.bcs.nostrum.com 3.2-STABLE FreeBSD 3.2-STABLE #0: Wed Jul 28 15:40:30 CDT 1999     root@hermit.bcs.nostrum.com:/opt/src/system/src/sys/compile/Hermit  i386

>Description:

I am familiar with having a '-n' option to /bin/ls on other platforms (i.e.
Solaris/Linux/IRIX/etc) to print uid/gid information numerically in long
(-l) listings rather than performing username/groupname lookups.  I was
unable to find any similar option to /bin/ls or similar programs.  (Unless
I just completely overlooked it).

>How-To-Repeat:

No similar option found on FreeBSD, other OSs output similar to:
% ls -ldn
drwxr-x--x    9 1179     100         4096 Jul 29 00:53 .

>Fix:

Determine if my patch is acceptable, as given, or in concept; and apply in
/usr/src/bin/ls:

--- ls.c-old	Wed Jul 28 15:16:56 1999
+++ ls.c	Wed Jul 28 16:11:55 1999
@@ -100,6 +100,7 @@
 int f_timesort;			/* sort by time vice name */
 int f_type;			/* add type character for non-regular files */
 int f_whiteout;			/* show whiteout entries */
+int f_numbers;			/* show uid/gid numbers rather than names */
 
 int rval;
 
@@ -137,7 +138,7 @@
 		f_listdot = 1;
 
 	fts_options = FTS_PHYSICAL;
-	while ((ch = getopt(argc, argv, "1ABCFHLPRTWabcdfgikloqrstu")) != -1) {
+	while ((ch = getopt(argc, argv, "1ABCFHLPRTWabcdfgiklnoqrstu")) != -1) {
 		switch (ch) {
 		/*
 		 * The -1, -C and -l options all override each other so shell
@@ -209,6 +210,9 @@
 		case 'k':
 			f_kblocks = 1;
 			break;
+		case 'n':
+			f_numbers = 1;
+			break;
 		case 'o':
 			f_flags = 1;
 			break;
@@ -401,6 +405,7 @@
 	char *initmax;
 	int entries, needstats;
 	char *user, *group, *flags, buf[20];	/* 32 bits == 10 digits */
+	char user_num[8], group_num[8];
 
 	/*
 	 * If list is NULL there are two possibilities: that the parent
@@ -512,10 +517,19 @@
 
 			btotal += sp->st_blocks;
 			if (f_longform) {
-				user = user_from_uid(sp->st_uid, 0);
+				if (f_numbers) {
+					snprintf(user_num, sizeof(user_num),
+					    "%d", sp->st_uid);
+					user = user_num;
+					snprintf(group_num, sizeof(group_num),
+					    "%d", sp->st_gid);
+					group = user_num;
+				} 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) {


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907290614.BAA05429>