awk '{print $9}' the last ls -l column including any spaces in the file name

Viewed 70429

How would I get awk to output the whole file name in ls -l if some of the files have spaces in them. Usually, I can run this command:

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

That doesn't work if the files have spaces in them. Is it possible to print $9, $10, $11 etc as well somehow?

8 Answers

If you are interested in filenames, then don’t parse ls -l output and use ls -1 (number one, not lowercase L!). It simply outputs one filename per line.

$ touch foo 'bar with spaces' baz
$ ls -1
bar with spaces
baz
foo
Related