From Newsgroup: alt.os.linux
On Sun, 08 Mar 2026 09:41:33 +0800, Woozy Song wrote:
Lew Pitcher wrote:
On Sat, 07 Mar 2026 15:32:22 +0100, J.O. Aho wrote:
On 07/03/2026 13.39, Woozy Song wrote:
in Downloads directory, I can type something like
ls -rtl *pdf
works as expected, but if I try
ls -rtl *html
or
dir *html
I get this error:
ls: invalid option -- 'y'
Try 'ls --help' for more information.
I would guess you have a file which name begins with '-y'
you could try: find ~/Downloads -name "*html"
or you can: ls ~/Downloads | grep html$
or
ls -- *html
(but programs aren't obliged to recognize the '--' option
and POSIX doesn't mandate it for ls(1), so check before using)
or
ls ./*html
(which /does/ satisfy the POSIX requirements, and avoids
argument flag parsing by prefixing the filename expansion
values with a relative path based in the current directory)
but I am typing single hyphen not two
This is under Debian, bash version 5.2.37
ls version 9.7
As others have already pointed out, you have a file that
matches the *html glob, and starts with "-y". Something
like
-you.html
or
-yhtml
Now, file globbing is done by the shell, before it invokes
the named program, so the shell expands your
ls -rtl *html
into something like
ls -rtl -you.html
and ls sees the leading -y of the first filename as an
invalid flag argument.
With
ls -rtl -- *html
the shell will still expand the command by file globbing,
but now into
ls -rtl -- -you.html
and ls sees the -- flag, and processes the arguments
following it as filenames
With
ls -rtl ./*html
the shell will still expand the command by file globbing,
but now into
ls -rtl ./you.html
and ls does /not/ see any flagged arguments after the -rtl,
and processes everything that follows as filenames
Does that answer the question?
--
Lew Pitcher
"In Skills We Trust"
Not LLM output - I'm just like this.
--- Synchronet 3.21d-Linux NewsLink 1.2