On 4/16/24 14:30, Toby Kelsey wrote:
The man page doesn't explain this format conflict, while the info page (info '(coreutils) ls invocation' or 'info ls') claims '-f' implies '-1' which is also incorrect: 'ls -1f' gives different output to to 'ls -f'.

Yes, this area of GNU 'ls' a mess. Option order should not matter here.

Option order didn't matter in 7th Edition Unix, where -f overrode -l regardless of whether -f came before or after -l. And option order doesn't matter in FreeBSD, where -f and -l are orthogonal. GNU ls is an odd hybrid of 7th Edition and FreeBSD and messes this up.

Rather than document the hybrid mess, let's bite the bullet and fix it. FreeBSD behavior makes more sense, so let's do that. Proposed patch attached.
From 674a6c262e594102b0485c5ded854c1be5902777 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 16 Apr 2024 15:08:51 -0700
Subject: [PATCH] ls: -f now means -a -U

Problem reported by Toby Kelsey <https://bugs.gnu.org/70418>.
* src/ls.c (decode_switches): -f now simply means -a -U.
(usage): Adjust to match.
---
 NEWS               |  7 +++++++
 doc/coreutils.texi | 14 +++++++-------
 src/ls.c           |  7 +------
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/NEWS b/NEWS
index 21ed3435b..43ce84d7e 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,13 @@ GNU coreutils NEWS                                    -*- outline -*-
   have exited with a "Function not implemented" error.
   [bug introduced in coreutils-8.28]
 
+** Changes in behavior
+
+  ls's -f option now simply acts like -aU, instead of also ignoring
+  some earlier options.  For example 'ls -fl' and 'ls -lf' are now
+  equivalent because -f no longer ignores an earlier -l.  The new
+  behavior is more orthogonal and is compatible with FreeBSD.
+
 ** Improvements
 
   sort operates more efficiently when used on pseudo files with
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 8f7f43ea0..2c6c8b68b 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -8150,11 +8150,9 @@ sort according to the ctime.  @xref{File timestamps}.
 @opindex -f
 @cindex unsorted directory listing
 @cindex directory order, listing by
-Produce an unsorted directory listing.
-This is like @option{--sort=none} (@option{-U}),
-but also enable @option{--all} (@option{-a}),
-while also disabling any previous use of @option{-l}, @option{--color}
-@option{--size}, or @option{--hyperlink}.
+Produce an unsorted listing of all directory entries.
+This is like @option{--all} (@option{-a}) combined
+with @option{--sort=none} (@option{-U}).
 
 @item -r
 @itemx --reverse
@@ -8224,10 +8222,12 @@ sort according to the birth time.
 @opindex --sort
 @opindex none@r{, sorting option for @command{ls}}
 Do not sort; list the files in whatever order they are
-stored in the directory.  (Do not do any of the other unrelated things
-that @option{-f} does.)  This can be useful when listing large
+stored in the directory.  This can be useful when listing large
 directories, where sorting can take some time.
 
+Unlike @option{-f}, this option does not imply @option{--all}
+(@option{-a}).
+
 @item -v
 @itemx --sort=version
 @opindex -v
diff --git a/src/ls.c b/src/ls.c
index f5ac98df7..916d7c050 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1952,11 +1952,6 @@ decode_switches (int argc, char **argv)
         case 'f':
           ignore_mode = IGNORE_MINIMAL; /* enable -a */
           sort_opt = sort_none;         /* enable -U */
-          if (format_opt == long_format)
-            format_opt = -1;            /* disable -l */
-          print_with_color = false;     /* disable --color */
-          print_hyperlink = false;      /* disable --hyperlink */
-          print_block_size = false;     /* disable -s */
           break;
 
         case FILE_TYPE_INDICATOR_OPTION: /* --file-type */
@@ -5466,7 +5461,7 @@ Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.\n\
   -D, --dired                generate output designed for Emacs' dired mode\n\
 "), stdout);
       fputs (_("\
-  -f                         do not sort, enable -aU, disable -ls --color\n\
+  -f                         same as -a -U\n\
   -F, --classify[=WHEN]      append indicator (one of */=>@|) to entries WHEN\n\
       --file-type            likewise, except do not append '*'\n\
 "), stdout);
-- 
2.44.0

Reply via email to