Brian v Brian v - 1 year ago 99
Bash Question

Making folders with mkdir and pbpaste

I am using terminal to create folders with the mkdir command. I know that something like

cat folders.txt | xargs mkdir

will work but I want to take what is in the clipboard and make the folders from that list.

I am currently using this:

pbpaste | xargs mkdir

The problem I am having is that it works with one line but when I use an entire list I get an error of "File name too long" with the filename looking like XXX\rXXX\rXXX\rXXX\rXXX etc.

Answer Source

You seem to have carriage returns instead of linefeeds in your clipboard. Try replacing them:

pbpaste | tr '\r' '\n' | xargs mkdir
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download