Can ls output in CSV format with directory and file columns?
I need a recursive directory listing like ls -R, but in CSV format.
I want separate columns for the directory and filename.
12 Answers
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.
ls CAN list contents in csv format using ls -mand can do so recursively using ls -Rm