How to create a file of specific size using Linux command line

Run for a second:

yes "some text" > testfile.txt

Reduce size:

truncate -s 50M testfile.txt

Create 50M file using fallocate command

fallocate -l 52428800 testfile.txt

To be more exact using inline arithmetic:

fallocate -l $((50*1024*1024)) > testfile.txt

Using head command

head -c 50MB /dev/urandom > testfile.txt
Read the rest