Overview for truncate

How to create a file of a certain size in Linux using terminal (bash)

Sometimes we need to create files (actually generate them) for testing purposes or for checking our scripts or programs, working with file size limits. In linux you don't have program any script; bash is good enough to meet your requirements to achieve your goal. I will show you, how to generate files of any size you need in my Solus system (don't be afraid, all examples are working on every GNU/Linux based systems and distributions);

Creating a file of an approximate size

This is the fastest way to generate a file using truncate command:

$ truncate -s 2M edustorage.txt

We aimed to 2M big filesize, but let's see, what is precize filesize of this generated one:

dima@edustorage ~/test/yobany $ ls -l
total 0
-rw-rw-r-- 1 dima dima 2097152 Apr 28 11:55 edustorage.txt

Read more

Written by Administrator on Tuesday April 28, 2020