Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Mar 1998 16:51:16 -0500 (EST)
From:      Max Euston <meuston@jmrodgers.com>
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/6140: Add '-H' and '-P' options to ls(1), fix man pages.
Message-ID:  <199803262151.QAA17425@gw.jmrodgers.com>

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

>Number:         6140
>Category:       bin
>Synopsis:       Add '-H' and '-P' options to ls(1), fix man pages.
>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:   Thu Mar 26 14:00:01 PST 1998
>Last-Modified:
>Originator:     Max Euston
>Organization:
>Release:        FreeBSD 2.2.5-STABLE i386
>Environment:

	2.2.5-STABLE

>Description:

	The ls(1) command should be able to use the '-H' and '-P'
options.  The code change is trivial, but the man pages needed
some more work.  This change does not break any existing behavior,
but allows for some useful aliases:

	alias l='/bin/ls -Hl'

	This allows me (on my system) to do 'l /usr/src' and see
the files in that subdirectory and not "/usr/src -> /var/src".  I
can still do 'l -P /usr/src' to find the info for "/usr/src" and
'l -d /usr/src' to find the info for "/var/src".

This change is more consistant with the existing use of the '-H'
and '-P' options (it can be argued that the ls(1) command DOES an
implicit (partial) walk of the directory tree, since it shows the
items in a directory and not just the directory itself).

>How-To-Repeat:
>Fix:

diff -ur /usr/src/bin/ln/symlink.7 ./ln/symlink.7
--- /usr/src/bin/ln/symlink.7	Wed Jun 18 21:09:09 1997
+++ ./ln/symlink.7	Thu Mar 26 16:28:46 1998
@@ -200,6 +200,8 @@
 the
 .Nm ls
 command follows symbolic links named as arguments if the
+.Fl H
+or
 .Fl L
 option is specified,
 or if the
@@ -207,16 +209,13 @@
 .Fl d
 or
 .Fl l
-options are not specified.
-(If the
-.Fl L
-option is specified,
+options are not specified.  (The
 .Nm ls
-always follows symbolic links.
-.Nm Ls
-is the only command where the
+command is the only command where the
+.Fl H
+and
 .Fl L
-option affects its behavior even though it is not doing a walk of
+options affect its behavior even though it is not doing a walk of
 a file tree.)
 .Pp
 The
@@ -394,23 +393,19 @@
 To maintain compatibility with historic systems,
 the
 .Nm ls
-command never follows symbolic links unless the
-.Fl L
-flag is specified.
-If the
+command acts a little differently.  If you do not specify the
+.Fl F ,
+.Fl d or
+.Fl l
+options,
+.Nm ls
+will follow symbolic links specified on the command line.  If the
 .Fl L
 flag is specified,
 .Nm ls
 follows all symbolic links,
 regardless of their type,
 whether specified on the command line or encountered in the tree walk.
-The
-.Nm ls
-command does not support the
-.Fl H
-or
-.Fl P
-options.
 .Sh SEE ALSO
 .Xr chflags 1 ,
 .Xr chgrp 1 ,


diff -ur /usr/src/bin/ls/ls.1 ./ls/ls.1
--- /usr/src/bin/ls/ls.1	Fri Feb 20 15:32:41 1998
+++ ./ls/ls.1	Fri Mar 20 11:42:06 1998
@@ -43,7 +43,7 @@
 .Nd list directory contents
 .Sh SYNOPSIS
 .Nm ls
-.Op Fl ACFLRTacdfgikloqrstu1
+.Op Fl ACFHLPRTacdfgikloqrstu1
 .Op Ar file ...
 .Sh DESCRIPTION
 For each operand that names a
@@ -75,7 +75,7 @@
 .Ql \&.
 and
 .Ql \&.. .
-Always set for the super-user.
+\& Always set for the super-user.
 .It Fl C
 Force multi-column output; this is the default when output is to a terminal.
 .It Fl F
@@ -85,10 +85,27 @@
 an at sign (@) after each symbolic link,
 an equals sign (=) after each socket,
 and a vertical bar (|) after each that is a
-.Tn FIFO . 
+.Tn FIFO .
+.It Fl H
+Symbolic links on the command line are followed.  This option is assumed if
+none of the
+.Fl F ,
+.Fl d ,
+or
+.Fl l
+options are specified.
 .It Fl L
-If argument is a symbolic link, list the file or directory the link references
-rather than the link itself.
+If argument is a symbolic link, list the object the link references
+rather than the link itself.  This option cancels the
+.Fl P
+option.
+.It Fl P
+If argument is a symbolic link, list the link itself rather than the
+object the link references.  This option cancels the
+.Fl H
+and
+.Fl L
+options.
 .It Fl R
 Recursively list subdirectories encountered.
 .It Fl T
@@ -100,8 +117,7 @@
 .It Fl c
 Use time when file status was last changed for sorting or printing.
 .It Fl d
-Directories are listed as plain files (not searched recursively) and
-symbolic links in the argument list are not indirected through.
+Directories are listed as plain files (not searched recursively).
 .It Fl f
 Output is not sorted.
 .It Fl g
@@ -115,7 +131,7 @@
 For each file, print the file's file serial number (inode number).
 .It Fl k
 If the 's' option is specified, print the file size allocation in kilobytes,
-not blocks.
+not blocks.  This option overrides the environment variable BLOCKSIZE.
 .It Fl l
 (The lowercase letter ``ell.'')  List in long format. (See below.)
 If the output is to a terminal, a total sum for all the file
@@ -162,12 +178,20 @@
 the format used.
 .Pp
 The
-.Fl c ,
+.Fl c
 and
 .Fl u
 options override each other; the last one specified determines
 the file time used.
 .Pp
+The
+.Fl H,
+.Fl L
+and
+.Fl P
+options override each other (either partially or fully); they
+are applied in the order specified.
+.Pp
 By default,
 .Nm ls
 lists one entry per line to standard
@@ -343,3 +367,6 @@
 function is expected to be a superset of the
 .St -p1003.2
 specification.
+.Sh BUGS
+To maintain backward compatibility, the relationships between the many
+options is quite complex.


diff -ur /usr/src/bin/ls/ls.c ./ls/ls.c
--- /usr/src/bin/ls/ls.c	Fri Feb 20 15:32:41 1998
+++ ./ls/ls.c	Mon Mar 23 11:40:37 1998
@@ -82,7 +82,6 @@
 int f_listdir;			/* list actual directory, not contents */
 int f_listdot;			/* list files beginning with . */
 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_recursive;		/* ls subdirectories also */
@@ -91,7 +90,6 @@
 int f_singlecol;		/* use single column output */
 int f_size;			/* list size in short listing */
 int f_statustime;		/* use time of last mode change */
-int f_dirname;			/* if precede with directory name */
 int f_timesort;			/* sort by time vice name */
 int f_type;			/* add type character for non-regular files */
 
@@ -131,7 +129,7 @@
 		f_listdot = 1;
 
 	fts_options = FTS_PHYSICAL;
-	while ((ch = getopt(argc, argv, "1ACFLRTacdfgikloqrstu")) != -1) {
+	while ((ch = getopt(argc, argv, "1ACFHLPRTacdfgikloqrstu")) != -1) {
 		switch (ch) {
 		/*
 		 * The -1, -C and -l options all override each other so shell
@@ -161,9 +159,17 @@
 		case 'F':
 			f_type = 1;
 			break;
+		case 'H':
+			fts_options |= FTS_COMFOLLOW;
+			break;
 		case 'L':
 			fts_options &= ~FTS_PHYSICAL;
 			fts_options |= FTS_LOGICAL;
+			break;
+		case 'P':
+			fts_options &= ~FTS_COMFOLLOW;
+			fts_options &= ~FTS_LOGICAL;
+			fts_options |= FTS_PHYSICAL;
 			break;
 		case 'R':
 			f_recursive = 1;



diff -ur /usr/src/bin/ls/util.c ./ls/util.c
--- /usr/src/bin/ls/util.c	Wed Mar 26 12:55:19 1997
+++ ./ls/util.c	Thu Mar 19 15:03:03 1998
@@ -68,6 +68,6 @@
 void
 usage()
 {
-	(void)fprintf(stderr, "usage: ls [-1ACFLRTacdfikloqrstu] [file ...]\n");
+	(void)fprintf(stderr, "usage: ls [-1ACFHLPRTacdfikloqrstu] [file ...]\n");
 	exit(1);
 }

>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?199803262151.QAA17425>