Amir Rachum
Amir Rachum

Reputation: 79645

How to get a list of file names in different lines

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?

Upvotes: 138

Views: 73629

Answers (10)

Anshul Ayushya
Anshul Ayushya

Reputation: 129

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

Upvotes: 0

Vicky
Vicky

Reputation: 1328

This will also do

ls -l | awk '{print $NF}'

Upvotes: -1

honeytechiebee
honeytechiebee

Reputation: 162

Try this:

$ ls | xargs -n num

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

Upvotes: 3

rene
rene

Reputation: 42443

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

Upvotes: 16

Manikandan Rajendran
Manikandan Rajendran

Reputation: 1182

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.

Upvotes: 1

vara
vara

Reputation: 836

Use sed command to list single columns

ls -l | sed 's/\(^[^0-9].\*[0-9]\*:[0-9]\*\) \(.*\)/\2/'

Upvotes: 3

user100766
user100766

Reputation:

ls -1. From the help:

-1 list one file per line

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

Upvotes: 26

Šimon Tóth
Šimon Tóth

Reputation: 36433

ls -1

That is a number, not small L.

Upvotes: 297

Johan Kotlinski
Johan Kotlinski

Reputation: 25739

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

Upvotes: 6

Eelvex
Eelvex

Reputation: 9133

Perhaps:

ls | awk '{print $NF}'

Upvotes: 6

Related Questions