120

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
  • 67,681
  • 68
  • 159
  • 239

10 Answers10

265

ls -1

That is a number, not small L.

Šimon Tóth
  • 33,420
  • 18
  • 94
  • 135
  • 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
23

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
  • 13,623
  • 3
  • 37
  • 47
12

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
  • 37,946
  • 78
  • 99
  • 132
6

Perhaps:

ls | awk '{print $NF}'
Eelvex
  • 8,397
  • 22
  • 40
5

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

Johan Kotlinski
  • 23,690
  • 9
  • 73
  • 100
3

Use sed command to list single columns

ls -l | sed 's/\(^[^0-9].\*[0-9]\*:[0-9]\*\) \(.*\)/\2/'
nhahtdh
  • 52,949
  • 15
  • 113
  • 149
vara
  • 746
  • 2
  • 10
  • 27
3

Try this:

$ ls | xargs -n num

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

Sam Protsenko
  • 12,371
  • 2
  • 53
  • 69
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,017
  • 1
  • 6
  • 9
0

This will also do

ls -l | awk '{print $NF}'
Vicky
  • 1,150
  • 10
  • 25
0

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

Anshul Ayushya
  • 109
  • 2
  • 12