0

I am trying to make directories from a very simple text file list (folders.txt) that looks like this:

Homesteader_Droopy_1954
Car_of_Tomorrow_1951
Dixieland_Droopy_1954
Doggone_Tired_1949
Drag_A_Long_Droopy_1954
Droopys_Double_Trouble_1951

Using this command:

cat folders.txt | xargs mkdir

But it keeps spitting out an error that looks like this:

mkdir: Homesteader_Droopy_1954\rCar_of_Tomorrow_1951\rDixieland_Droopy_1954\rDoggone_Tired_1949\rDrag_A_Long_Droopy_1954\rDroopys_Double_Trouble_1951: File name too long

Any idea why it's adding a \r at each new line, and how to get it to stop doing that, and just make the folders?

OS: Mac Catalina 10.15.7 - zsh 5.7.1

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
DasKraut
  • 123
  • 9
  • 1
    Not your problem, btw, but avoid `cat file | ...`; it's more efficient to just use ` – Charles Duffy May 11 '23 at 00:26
  • (using NULs instead of newlines is important there -- xargs behavior is a lot more complex/unintuitive than people think, and it can be very surprising when you have spaces, quotes, &c in your file or directory names) – Charles Duffy May 11 '23 at 00:27
  • 1
    ...the error message does imply that the old-Apple style of file may well be what you have, btw. Normally for Windows-style files xargs would treat it as a file `Homesteader_Droopy_1954\r`, then a second file `Car_of_Tomorrow_1951\r` as a second file instead of one big long name. – Charles Duffy May 11 '23 at 00:29
  • 1
    (btw, when I say `CR` that's also called `\r`, and a `LF` is also called `\n`, so `CRLF` in one notation is `\r\n` in the other; Windows uses CRLF between lines, pre-OSX Apple systems used CR only, and UNIXy systems including modern MacOS use LF only) – Charles Duffy May 11 '23 at 00:31
  • @CharlesDuffy your second "old Apple style" command worked! You should post it as an answer. `tr '\r' '\0' – DasKraut May 11 '23 at 00:46

0 Answers0