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
head -c 50MB /dev/zero > testfile.txt

Using dd command

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

 

Source: https://www.ostechnix.com/create-files-certain-size-linux/

Similar Posts:

Leave a Reply

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