[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: The ls command



On 2025-10-30 at 14:32, debian-user@howorth.org.uk wrote:

> The Wanderer <wanderer@fastmail.fm> wrote:
> 
>> On 2025-10-30 at 13:33, Michael wrote:
>> 
>>> The command
>>> 
>>> ls -- *.pdf
>>> 
>>> has been run and a very large number of PDF files has been
>>> listed.
>>> 
>>> It is very difficult to spot any strangely named PDF files.
>>> 
>>> What command should be issued to easily list any strangely named
>>> PDF file ?
>> 
>> Try:
>> 
>> $ ls -- *.pdf | grep ' -'
>> 
>> This should show you any files whose name include a space followed
>> by a dash. The space would be treated as a token separator, and the
>> dash would be treated as the beginning of a new argument to ls.
> 
> err no, ls lists multiple files on a line and this wouldn't pick up
> any file at the start of a line.

In addition to the notes Nicolas George made, I'll point out that the
issue is almost certainly not about the characters at the *start* of a
filename, but about a filename with a space *in* it and a dash *after
that space*.

The command I suggested was aimed primarily at catching files with such
a ' -' sequence in the middle of the name.

I'll admit that it wouldn't catch filenames that start with a '-', or at
least I'm not confident that it would. I suppose something like

# ls -- *.pdf | grep '(^| )-'

would catch both cases.

-- 
   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man.         -- George Bernard Shaw

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: