2

In Linux how can I create a large file with a given text or hex pattern (Like DEADBEEFDEADBEEFDEADBEEF ....)

I know dd can be used to create large files but it doesn't write desired text or hex pattern

dd if=/dev/urandom of=/tmp/bigfile bs=blocksize count=size

or

dd if=/dev/zero of=/tmp/bigfile bs=blocksize count=size

Quickly create a large file on a Linux system?

How to create a file with a given size in Linux?

katta
  • 245
  • 1
  • 4
  • 11

2 Answers2

7
while true ; do printf "DEADBEEF"; done | dd of=/tmp/bigfile bs=blocksize count=size iflag=fullblock
Community
  • 1
  • 1
Chirlo
  • 5,989
  • 1
  • 29
  • 45
-1

If your intention is to achieve a scrambled data and not random.

shuf folder/* | dd of=target.txt bs=1K count=2048

to get a 2MB sample file which you can then shorten or invoke the command above again with different numbers for count

folder/* will contain files with your patterns

Or as an alternative you can have your hexadecimal values stored in a single file in separate lines and use shuf to shuffle them based on your need and fill them

shuf -n 100 source.txt | dd of=target.txt bs=1K count=2048

Or you can just dump it in dd as

dd if=source.txt of=target.txt bs=1K count=2048

Shuffle Documentation

Srini V
  • 11,045
  • 14
  • 66
  • 89