3

I have a directory with millions of files. I've just learned millions are orphaned and I need to unlink them. I'd like to start with an array of all files in a single text file (csv ideally). Can you help?

I was going to do an ls and just save the terminal output to a file, but I figure there's a more elegant way.

How can I make something like ls > log.csv end up looking like

file1.txt,file2.txt, ... fileN.txt?

Mike Lyons
  • 1,748
  • 2
  • 20
  • 33
Ryan
  • 14,682
  • 32
  • 106
  • 179
  • This one looks similar: http://stackoverflow.com/questions/2764051/joining-multiple-lines-into-one-with-bash – procleaf Nov 15 '12 at 11:57
  • @leafei, wow. That's awesome. Trying this now: `ls -1 | tr "\\n" "," > log.csv` – Ryan Nov 15 '12 at 12:42

1 Answers1

7

Try doing this :

printf '%s\n' *.txt | paste -sd "," - > log.csv

or

printf '%s,' *.txt > log.csv

or

printf '"%s",' *.txt > log.csv

if you have special characters like spaces in filenames.

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223