134

I want to get a list of all the files in a directory, like with ls, so that each filename will be on a seperate line, without the extra details supplied by ls -l. I looked at ls --help and didn't find a solution. I tried doing

ls -l | cut --fields=9 -d" "

but ls doesn't use a fixed number of spaces between columns. Any idea on how to do this, preferably in one line?

Amir Rachum
  • 76,817
  • 74
  • 166
  • 248

10 Answers10

289

ls -1

That is a number, not small L.

Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
  • 5
    i see this in the documentation: cross -x, commas -m, horizontal -x, long -l, single-column -1, verbose -l, vertical -C i'm not sure how they came up with some of these. – Alexander Taylor Oct 21 '15 at 22:50
26

ls -1. From the help:

-1 list one file per line

Works on cygwin and FreeBSD, so it's probably not too GNU-specific.

jhwist
  • 15,201
  • 3
  • 40
  • 47
15

solution without pipe-ing :-)

 ls --format single-column

Note that the long options are only supported on the GNU coreutils where BSD ls only supports the short arguments -1

rene
  • 41,474
  • 78
  • 114
  • 152
6

Perhaps:

ls | awk '{print $NF}'
Eelvex
  • 8,975
  • 26
  • 42
5

ls | cat ... or possibly, ls -1

Johan Kotlinski
  • 25,185
  • 9
  • 78
  • 101
3

Use sed command to list single columns

ls -l | sed 's/\(^[^0-9].\*[0-9]\*:[0-9]\*\) \(.*\)/\2/'
nhahtdh
  • 55,989
  • 15
  • 126
  • 162
vara
  • 816
  • 3
  • 12
  • 29
3

Try this:

$ ls | xargs -n num

Here num is number of columns you want to list in.

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
1

first you can use this. it will display the one file per line.

ls -l | sed 's/(.* )(.*)$/\2/'

or else you can use thus

find . -maxdepth 1 | sed 's/.///'

both the things are the same.

Manikandan Rajendran
  • 1,142
  • 1
  • 8
  • 9
0

This is also working: echo -e "\n$(ls)"

Anshul Ayushya
  • 131
  • 5
  • 21
-1

This will also do

ls -l | awk '{print $NF}'
Vicky
  • 1,298
  • 1
  • 16
  • 33