What does the $ mean

The place to post if you need help or advice

Moderators: ChrisThornett, LXF moderators

What does the $ mean

Postby pk_fox » Mon Sep 16, 2013 8:12 am

Hi all, just been googling for some help on generating a large binary file for use in testing a programme I'm writing and came across this

dd if=/dev/zero of=10g.img bs=1000 count=0 seek=$[1000*1000*10]

I know what the DD command does but what is the $ in the seek parameter ( also I ran this and it produced zilch ) how can the count = 0 ?
User avatar
pk_fox
LXF regular
 
Posts: 292
Joined: Wed Apr 13, 2005 1:38 pm
Location: Surrey, UK

Postby nelz » Mon Sep 16, 2013 8:57 am

If substitutes the result of the calculation in the brackets, try
Code: Select all
echo $[1000*1000*10]

although it's more common to use double parentheses for this
Code: Select all
echo $(( 1000*1000*10 ))

which is why you couldn't find it in the bash man page.

You can use variables in here too
Code: Select all
X=10
echo $(( X * 10 ))


This command produces a sparse file, it is more common to see it used with count=1 but 0 works. The seek option tells dd to start that far into the file, so all the preceding space has to be created.

A sparse file uses only the space needed by the data it holds, so while ls -l 10g.img will show a large file, du -h 10g.img will show the disk space it actually occupies. This is often used when creating is a disk image for a virtual machine, the size shown by ls will remain constant while the space it uses increases as you use it. This provides a faster virtual disk than allowing the disk file to grow as it is used, which often leads to substantial fragmentation.

I'm not sure how it will suit your needs as the file contains no data until you add it.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8499
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby pk_fox » Mon Sep 16, 2013 9:25 am

Thanks Nelz, any ideas as to how I can populate said file ?
User avatar
pk_fox
LXF regular
 
Posts: 292
Joined: Wed Apr 13, 2005 1:38 pm
Location: Surrey, UK

Postby nelz » Mon Sep 16, 2013 10:06 am

That ll depends on what you want in it. The file is there as a 10G file right now, just not using 10G of disk space. If your programs needs a 10G file with 10G of data already in it, you don't want a sparse file.

Code: Select all
dd if=/dev/urandom of=10g.img bs=1G count=10
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8499
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby pk_fox » Mon Sep 16, 2013 2:19 pm

nelz wrote:That ll depends on what you want in it. The file is there as a 10G file right now, just not using 10G of disk space. If your programs needs a 10G file with 10G of data already in it, you don't want a sparse file.

Code: Select all
dd if=/dev/urandom of=10g.img bs=1G count=10


Thanks that will do nicely.
User avatar
pk_fox
LXF regular
 
Posts: 292
Joined: Wed Apr 13, 2005 1:38 pm
Location: Surrey, UK

Postby ferrari » Mon Sep 16, 2013 10:14 pm

Nice explanation of a sparse file Nelz. :)
ferrari
LXF regular
 
Posts: 142
Joined: Tue May 03, 2005 11:09 am


Return to Help!

Who is online

Users browsing this forum: theocl and 0 guests