Linux ls one file per line
Linux list one file per line using ls -1
(Number One)
By default linux ls
command prints file names in a single line.If for some purpose you need to list one file name per line , you can use option -1
ls -1
Add option -a
to list hidden files also
ls -a1
Below is the output of an example:
j@ubuntu:~/tmp$ ls -1
dir1
dir2
file1
file2
j@ubuntu:~/tmp$ ls -1a
.
..
.config
dir1
dir2
file1
file2
j@ubuntu:~/tmp$
Alternatives
ls | cat
OR
ls | xargs -n 1 echo
OR
ls | tr " " "\n"