When I use ls command, then my results get shown in two columns.

Is there a way I can show all the results in a separate row so it is easier for me to copy and paste in excel.

Current situation doesn't help as when copying the results and pasting in excel, two file name show in one row. I would ideally want each file showing in a separate row so it makes it easier to copy/paste to excel.

  • 1
    noting that a filename with a newline in it may be mis-represented. – Jeff Schaller Jun 27 at 17:29

The -1 option ("minus one") of ls will make the utility list the filenames in a single column. This is described in the ls manual.

$ touch fileA 'File B' 'file
> with
> newlines'
$ ls -1
File B
  • This works, and its really straight forward. Appreciate it. – mywayz Jun 27 at 17:31
  • GNU ls appears to replace newlines; AIX ls does not. – Jeff Schaller Jun 27 at 17:47

It's best to not parse ls, although it doesn't really apply in your use case. You can accomplish what you want using printf/shell globbing:

printf '%s\n' *
  • 1
    This is very straight forward and I just tried and it works. Thanks for the help. – mywayz Jun 27 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.