Search code examples
linuxshellunixfindls

How to use find command to get csv


I am using the following command:

$ find /mnt/DCS_01 -size +10000k -exec ls -sd {} +
26412032 /mnt/DCS_01/file.mp3
26412032 /mnt/DCS_01/file2.mp3

I am trying to write this as a csv file. Is there a way to get the output as comma-separated, so I can write it to a text file, for example:

$ find /mnt/DCS_01 -size +10000k -exec ls -sd {} + "csv" > file.txt

Solution

  • With -printf :

    find /mnt/DCS_01 -size +10000k -printf '%k,"%p"\n'
    

    Read about printf :

    man find | less +/'-printf format'