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

Using head command

head -c 50MB /dev/urandom > testfile.txt
head -c 50MB /dev/zero > testfile.txt

Using dd command

dd if=/dev/urandom of=testfile.txt bs=50MB count=1



Similar Posts:

    None Found

Leave a Reply

Your email address will not be published. Required fields are marked *