I need a recursive directory listing like ls -R, but in CSV format.

I want separate columns for the directory and filename.

  • 1
    Close voters. This is asked and answered correctly. – Elder Geek Aug 5 '18 at 15:21

ls cannot print data in CSV format, but find can, when given a custom output format:

find . -type f -printf '%h,%f\n'

%h denotes the directory part, %f the filename part. See the manual, especially the section about -printf format.

However, be aware that this won't work properly when your filenames have special characters or a , in them.

  • 5
    Adding quotation marks can at least avoid producing an invalid CSV if a filename contains ,: -printf '"%h","%f"\n'. – Bakuriu Aug 5 '18 at 23:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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