How to get a list of file names in different lines


Unix Problem Overview

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?

Unix Solutions

Solution 1 - Unix

ls -1

That is a number, not small L.

Solution 2 - Unix

ls -1. From the help:

> -1 list one file per line

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

Solution 3 - Unix

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

Solution 4 - Unix


ls | awk '{print $NF}'

Solution 5 - Unix

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

Solution 6 - Unix

Use sed command to list single columns

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

Solution 7 - Unix

Try this:

$ ls | xargs -n num

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

Solution 8 - Unix

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.

Solution 9 - Unix

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

Solution 10 - Unix

This will also do

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


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmir RachumView Question on Stackoverflow
Solution 1 - Unix┼áimon TóthView Answer on Stackoverflow
Solution 2 - UnixjhwistView Answer on Stackoverflow
Solution 3 - UnixreneView Answer on Stackoverflow
Solution 4 - UnixEelvexView Answer on Stackoverflow
Solution 5 - UnixJohan KotlinskiView Answer on Stackoverflow
Solution 6 - UnixvaraView Answer on Stackoverflow
Solution 7 - UnixhoneytechiebeeView Answer on Stackoverflow
Solution 8 - UnixManikandan RajendranView Answer on Stackoverflow
Solution 9 - UnixAnshul AyushyaView Answer on Stackoverflow
Solution 10 - UnixVickyView Answer on Stackoverflow