我想使用以下命令将文件夹的大小输出到 json 文件
tree -d -JL 3 --charset utf-8 --du $HOME/share >> discspace.json
但该命令不会输出有效的 json。相反,它输出以下内容:
[
{"type":"link","name":"/home/user/share","contents":[
{"type":"directory","name":"folder1","size":16384,"contents":[
{"type":"directory","name":"folder1_1","size":4096,"contents":[]},
{"type":"directory","name":"folder1_2","size":4096,"contents":[]},
{"type":"directory","name":"folder1_3","size":4096,"contents":[]}>>,<<
]},
{"type":"directory","name":"folder2","size":20480,"contents":[
{"type":"directory","name":"folder2_1","size":4096,"contents":[]},
{"type":"directory","name":"folder2_2","size":8192,"contents":[
{"type":"directory","name":"folder2_2_1","size":4096,"contents":[]}>>,<<
]},
{"type":"directory","name":"folder2_3","size":4096,"contents":[]}>>,<<
]}>>,<<
]},
{"type":"report","size":36881,"directories":9}
]
当验证 json 时,我收到错误,因为使用了太多逗号(我用 标记的逗号>>,<<
)。
哪个命令更好/正确?