我将如何转换:
$ find . -ls > /tmp/files.txt
这给了我类似的东西:
908715 40 -rwxrwxr-x 1 david staff 16542 Nov 15 14:12 ./dump_info.py
908723 0 drwxr-xr-x 2 david staff 68 Nov 20 17:35 ./metadata
转换成CSV输出?它看起来像:
908715,40,-rwxrwxr-x,1,david,staff,16542,Nov 15 14:12,./dump_info.py
908723,0,drwxr-xr-x,2,david,staff,68,Nov 20 17:35,./metadata
这是标题示例,文件名中带有空格:
652640,80,-rw-rw-r--,1,david,staff,40036,Nov,6,15:32,./v_all_titles/V Catalog Report 11.5.xlsx
最佳答案
在命令行中输入会有点长,但是它会在文件名中正确保留空格(并用引号引起来!)
find . -ls | python -c '
import sys
for line in sys.stdin:
r = line.strip("\n").split(None, 10)
fn = r.pop()
print ",".join(r) + ",\"" + fn.replace("\"", "\"\"") + "\""
'