How do I list one filename per output line in Linux?

fixxxer picture fixxxer · Oct 8, 2010 · Viewed 171.5k times · Source

I'm using ls -a command to get the file names in a directory, but the output is in a single line.

Like this:

.  ..  .bash_history  .ssh  updater_error_log.txt

I need a built-in alternative to get filenames, each on a new line, like this:

.  
..  
.bash_history  
.ssh  
updater_error_log.txt

Answer

Bert F picture Bert F · Oct 8, 2010

Use the -1 option (note this is a "one" digit, not a lowercase letter "L"), like this:

ls -1a

First, though, make sure your ls supports -1. GNU coreutils (installed on standard Linux systems) and Solaris do; but if in doubt, use man ls or ls --help or check the documentation. E.g.:

$ man ls
...
       -1     list one file per line.  Avoid '\n' with -q or -b