Why does ls() sometimes list the files with one line per file and sometimes it puts two files in one line?

Hi, the question is basically already in the headline.

I have a list of files in the working directory

I’ll put it in an answer, because my text has too many characters

Now, if I do


the files are listed, as they should be, with one file per line.
But if I do for example


“Namen” is the following:

12,5Hz - Mkapsel - mitOel_1.CSV 30Hz - Roga2 - mitOel_1 - Mikro.CSV
12,5Hz - Roga - mitOel_1 - Mikro.CSV 30Hz - Roga2 - mitOel_1 - Vibr.CSV
12,5Hz - Roga - mitOel_1 - Vibr.CSV 40Hz - Mkapsel - mitOel_1.CSV
12,5Hz - Roga2 - mitOel_1 - Mikro.CSV 40Hz - Roga - mitOel_1 - Mikro.CSV
12,5Hz - Roga2 - mitOel_1 - Vibr.CSV 40Hz - Roga - mitOel_1 - Vibr.CSV
20Hz - Mkapsel - mitOel_1.CSV 40Hz - Roga2 - mitOel_1 - Mikro.CSV
20Hz - Roga - mitOel_1 - Mikro.CSV 40Hz - Roga2 - mitOel_1 - Vibr.CSV
20Hz - Roga - mitOel_1 - Vibr.CSV 50Hz - Mkapsel - mitOel_1.CSV
20Hz - Roga2 - mitOel_1 - Mikro.CSV 50Hz - Roga - mitOel_1 - Mikro.CSV
20Hz - Roga2 - mitOel_1 - Vibr.CSV 50Hz - Roga - mitOel_1 - Vibr.CSV
25Hz - Mkapsel - mitOel_1.CSV 50Hz - Roga2 - mitOel_1 - Mikro.CSV
25Hz - Roga - mitOel_1 - Mikro.CSV 50Hz - Roga2 - mitOel_1 - Vibr.CSV
25Hz - Roga - mitOel_1 - Vibr.CSV 60Hz - Mkapsel - mitOel_1.CSV
25Hz - Roga2 - mitOel_1 - Mikro.CSV 60Hz - Roga - mitOel_1 - Mikro.CSV
25Hz - Roga2 - mitOel_1 - Vibr.CSV 60Hz - Roga - mitOel_1 - Vibr.CSV
30Hz - Mkapsel - mitOel_1.CSV 60Hz - Roga2 - mitOel_1 - Mikro.CSV
30Hz - Roga - mitOel_1 - Mikro.CSV 60Hz - Roga2 - mitOel_1 - Vibr.CSV
30Hz - Roga - mitOel_1 - Vibr.CSV

Why is that? And what can I do to get the supposed “one file per line” output?

(I left out the top three and the bottom two lines where it just says stuff about my system. I don’t think those are relevant)

still to many characters


thats the list

Which version of Octave and which operating system do you use?

1 Like

Octave: 6.4.0
Windows 10 Pro

Does the same still happen with Octave 7.1.0?

1 Like

Can you post the output of


help ls says

If the optional output LIST is requested then ‘ls’ returns a
character array with one row for each file/directory name.

You can try the dir() command. It returns a structure array.

1 Like

The function ls eventually uses a system-specific function for producing a directory listing.

For interest, what is the output of ls_command on your machine?

On my Linux PC it is ls -C -F. Now that I know it is using ls I can check the documentation for that executable (man ls) and see that there is an option -1 to have only one file displayed per line.

Or as was suggested above, use f = dir () to return a struct array of the files and fnames = {f.name} to get a cell array of strings containing the filenames.


Thanks for all suggestions. It took a while to get the newest Version on my PC. (IT Admin has to do it etc etc… doesn’t matter)

With the newest Octave Version it works even less the way I want it to work.

I now use


This seems to work the way I want it to.

Thanks again

Could you please be more specific in what isn’t working as expected?

(OT: There are also .zip or .7z versions of Octave for Windows that you could probably unpack without admin privileges.)

Edit: Another possible caveat with the approach using glob: The glob function might not work correctly with file names containing non-ASCII characters on Windows. Consider using __wglob__ on that platform instead. (But keep in mind that this is an undocumented internal function that might change behavior without prior notice.)
Using dir should be working with non-ASCII characters, and it is a documented function.