How to get a list of file names in different lines
UnixLsUnix 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
Perhaps:
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}'