Can ls output in CSV format with directory and file columns?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
9
down vote

favorite
1












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



I want separate columns for the directory and filename.







share|improve this question

















  • 1




    Close voters. This is asked and answered correctly.
    – Elder Geek
    10 hours ago
















up vote
9
down vote

favorite
1












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



I want separate columns for the directory and filename.







share|improve this question

















  • 1




    Close voters. This is asked and answered correctly.
    – Elder Geek
    10 hours ago












up vote
9
down vote

favorite
1









up vote
9
down vote

favorite
1






1





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



I want separate columns for the directory and filename.







share|improve this question













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



I want separate columns for the directory and filename.









share|improve this question












share|improve this question




share|improve this question








edited 11 hours ago









Martin Thornton

2,38531730




2,38531730









asked 13 hours ago









Shailey999

463




463







  • 1




    Close voters. This is asked and answered correctly.
    – Elder Geek
    10 hours ago












  • 1




    Close voters. This is asked and answered correctly.
    – Elder Geek
    10 hours ago







1




1




Close voters. This is asked and answered correctly.
– Elder Geek
10 hours ago




Close voters. This is asked and answered correctly.
– Elder Geek
10 hours ago










1 Answer
1






active

oldest

votes

















up vote
9
down vote













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



find . -type f -printf '%h,%fn'


%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.






share|improve this answer

















  • 1




    Adding quotation marks can at least avoid producing an invalid CSV if a filename contains ,: -printf '"%h","%f"n'.
    – Bakuriu
    2 hours ago










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1062566%2fcan-ls-output-in-csv-format-with-directory-and-file-columns%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
9
down vote













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



find . -type f -printf '%h,%fn'


%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.






share|improve this answer

















  • 1




    Adding quotation marks can at least avoid producing an invalid CSV if a filename contains ,: -printf '"%h","%f"n'.
    – Bakuriu
    2 hours ago














up vote
9
down vote













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



find . -type f -printf '%h,%fn'


%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.






share|improve this answer

















  • 1




    Adding quotation marks can at least avoid producing an invalid CSV if a filename contains ,: -printf '"%h","%f"n'.
    – Bakuriu
    2 hours ago












up vote
9
down vote










up vote
9
down vote









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



find . -type f -printf '%h,%fn'


%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.






share|improve this answer













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



find . -type f -printf '%h,%fn'


%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.







share|improve this answer













share|improve this answer



share|improve this answer











answered 13 hours ago









PerlDuck

3,1101727




3,1101727







  • 1




    Adding quotation marks can at least avoid producing an invalid CSV if a filename contains ,: -printf '"%h","%f"n'.
    – Bakuriu
    2 hours ago












  • 1




    Adding quotation marks can at least avoid producing an invalid CSV if a filename contains ,: -printf '"%h","%f"n'.
    – Bakuriu
    2 hours ago







1




1




Adding quotation marks can at least avoid producing an invalid CSV if a filename contains ,: -printf '"%h","%f"n'.
– Bakuriu
2 hours ago




Adding quotation marks can at least avoid producing an invalid CSV if a filename contains ,: -printf '"%h","%f"n'.
– Bakuriu
2 hours ago












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1062566%2fcan-ls-output-in-csv-format-with-directory-and-file-columns%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What is the equation of a 3D cone with generalised tilt?

Relationship between determinant of matrix and determinant of adjoint?

Color the edges and diagonals of a regular polygon