Reputation: 79645
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
Reputation: 162
Try this:
$ ls | xargs -n num
Here num
is number of columns you want to list in.
Upvotes: 3
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
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
Reputation: 836
Use sed command to list single columns
ls -l | sed 's/\(^[^0-9].\*[0-9]\*:[0-9]\*\) \(.*\)/\2/'
Upvotes: 3
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