Shell – What does the “ls -1” command do

lsosxshell

In my current directory, I execute the command:
ls -1 and it gives a list of the current directory contents.

In the same directory, I repeat the command: ls and it gives me the same result, with perhaps a different formatted output.

Finally, I try to find out about the available commands by typing ls --help and the output is:

usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]

It looks like the last option is 1 (#1). Can someone explain what the ls -1 does and how it's different to the standard ls command?

Best Answer

Yes, the formatting of the output is the only difference between ls -1 and ls without any options.

From the ls manual on my system:

 -1      (The numeric digit "one".) Force output to be one entry per line.
         This is the default when output is not to a terminal.

This is also a POSIX option to the ls utility.

The manual for ls on your system is bound to say something similar (see man ls).

Related: