How to create multiple files with random data with bash

前端 未结 3 1446

How do I create multiple files (More than 20k, I need these files to run a test for syncying) with random data in OS X? I used a previously answered question (How Can I Create

3条回答
  •  花落未央
    2021-02-04 13:04

    The reason your approach doesn't work is that the default suffix for split (2 alphabetic characters) isn't a big enough namespace for twenty thousand files. If you add a couple of options:

    dd if=/dev/random bs=1 count=40000 | split -b 2 -d -a 5
    

    (where -d means "use digits, not alphabetic characters, for the suffix" and -a 5 means "use suffixes of length 5"), it ought to work fine - I tested it with /dev/urandom (for speed) on a GNU/Linux machine without problems.

    Note that this is much faster than the for-loop approach of the other answers (2.5 seconds versus 43 seconds for Carl Norum's answer on my machine).

提交回复
热议问题