You are not logged in.

#1 2014-09-20 12:06:24

Bailando
Member
From: Hungary
Registered: 2013-08-19
Posts: 133
Website

ls utility lister doesn't work correctly

ls file lister utility doesn't work correctly if current directory contains filenames beginning with "-" sign.
If I use plain command "ls" it works fine, however when I try "ls *.*" I get an error message:

ls: invalid option -- '0'
Try 'ls --help' for more information.

Offline

#2 2014-09-20 12:16:27

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: ls utility lister doesn't work correctly

You can use `--' to signal end of options, in particular, `ls -- *`. This is a universally applicable trick.


This silver ladybug at line 28...

Offline

#3 2014-09-20 12:52:47

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,737
Website

Re: ls utility lister doesn't work correctly

Alternatively, you can include the current directory in the path.
e.g.

ls ./-0

Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#4 2014-09-20 22:19:48

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: ls utility lister doesn't work correctly

What is the benefit of 'ls *.*' over 'ls'?
I can't reproduce your problem. Can you post an example ls output of said directory?
Is your 'ls' aliased to something?

Offline

#5 2014-09-20 23:21:20

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,737
Website

Re: ls utility lister doesn't work correctly

'ls *.*' lists files with extensions.

Try the following:

touch ./-0.txt
ls *.*

Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#6 2014-09-21 05:35:59

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: ls utility lister doesn't work correctly

Fun fact: Chet Ramey (the Bash maintainer) puts a file named "-i" in the bash source, to pass "-i" to rm / cp by passing "*" to it.


This silver ladybug at line 28...

Offline

#7 2014-09-21 19:39:18

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: ls utility lister doesn't work correctly

WorMzy wrote:

'ls *.*' lists files with extensions.

Try the following:

touch ./-0.txt
ls *.*

Sigh. Of course.
I don't know what was I thinking.

I should have posted the files I created to test it:

$ ls
-1  -2  -3  4  5  6

<shakes head>

Offline

Board footer

Powered by FluxBB