2

Quote from Using BSD jot

Most every Linux system comes with GNU seq (a utility to generate sequences of numbers or characters). However, a much older utility – and more flexible one – is the underutilized and unknown utility, jot. Every BSD system, including MacOS X, will come with jot (and not with seq).

(...)

In fact, to generate a large file (5Gb in this case), try this:

jot -r -c -s '' $(( 1024 * 1024 * 5 )) > file.5gb

When I try this out it generates a 5 MB file.

jot -r -c -s '' $(( 1024 * 1024 * 5 )) > file.5gb
du -sh file.5gb
5.0M    file.5gb

What does this command exactly do? How to specify size, for example 2 GB file? Is this the recommended way to generate random content files on macOS? Do you use other tools for random content files?

seq can't generate random content. Is this correct?

4

The example is slightly wrong and the result is correct. Let me explain.

The $(( 1024 * 1024 * 5 )) is simply a sum, but it will only work under the sh shell environment. For example:

sh
echo $(( 1024 * 1024 * 5))
5242880

That part sorted, back to jot. The -r is for "random data" and that should be what you find in the file.

The -c is shorthand for, and the same as using -w %c. While I'm not exactly sure what %c means, it does seem to produce a single byte of random data. You could swap out the -c for -b x and you would get the same size file but it would contain just the x repeated.

Next is -s '' which means no line returns. Without this there would be a line return after each character (or random data). Your file should also be twice as big.

The next part is $(( 1024 * 1024 * 5 )). This is the amount of "data" to produce. As shown above, that sum makes the number 5242880 (which is only 5MiB) and that is how large the file will be plus 1 byte for the trailing line return. For example:

sh
jot -r -c -s '' $(( 1024 * 1024 * 5 )) > file.5mb
ls -al file.5mb
-rw-r--r--  1 tigger  tigger  5242881  2 Apr 15:39 file.5mb
  • The -c (or -w %c) is a printf like construct. If one does not use it, one gets a stream of numbers. With it, one gets a stream of characters whose ASCII codes are those numbers. – Bob Eager Jul 12 '17 at 17:40
  • seq cannot generate random content. – Bob Eager Jul 12 '17 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.