cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 741 Views

File creation

I need a command that will create a file of a specific size. For example,
if I need a file that's 1500 bytes in size, I would like to be able to execute a
command that will create a file exactly 1500 bytes in size - regardless
of its content. If I need a file that's 23007 bytes in size, I would like to be
able to execute a command that will create a file exactly 23007 bytes in size -
again, regardlesss of the file's contents. So on, and so on!

After the file is created, and I run the "ls -l filename" command, I need to be
able to see that number in the column that indicates the file size.

Got any ideas????

Trevor "Red Hat Evangelist" Chandler
2 Replies
shura
Flight Engineer
Flight Engineer
  • 666 Views

Hello @Trevor 

Nice question.

It is 'mkfile' Solaris ( and some other distributives ) utility, which usually used to create swap files. For your example:

mkfile /tmp/test 23007

There is no 'mkfile' utility available in Red Hat Enterprise Linux.
Alternative for 'mkfile' in Red Hat Enterprise Linux is 'dd' command. For your example:

dd < /dev/zero > /tmp/test count=23007B

ls -l /tmp/test
-rw-r--r--. 1 root root 23007 Nov 17 14:19 /tmp/test

TM
Flight Engineer Flight Engineer
Flight Engineer
  • 658 Views

Hi @shura,

You dd command did not work on my Rocky Linux 9.2. It complained with dd: invalid number: ‘23007B’.

I modified yours and used instead

dd if=/dev/zero of=/tmp/test bs=1B count=23007

Regards,

Tshimanga

Join the discussion
You must log in to join this conversation.