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

Reduce size using truncate command

Run for a second:

yes "some text" > testfile.txt

Reduce size using truncate:

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
Read the rest