Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What does the $ mean

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help!
View previous topic :: View next topic  
Author Message
pk_fox
LXF regular


Joined: Wed Apr 13, 2005 2:38 pm
Posts: 292
Location: Surrey, UK

PostPosted: Mon Sep 16, 2013 9:12 am    Post subject: What does the $ mean Reply with quote

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 ?
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8457
Location: Warrington, UK

PostPosted: Mon Sep 16, 2013 9:57 am    Post subject: Reply with quote

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

although it's more common to use double parentheses for this
Code:
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:
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)
Back to top
View user's profile Send private message
pk_fox
LXF regular


Joined: Wed Apr 13, 2005 2:38 pm
Posts: 292
Location: Surrey, UK

PostPosted: Mon Sep 16, 2013 10:25 am    Post subject: Reply with quote

Thanks Nelz, any ideas as to how I can populate said file ?
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8457
Location: Warrington, UK

PostPosted: Mon Sep 16, 2013 11:06 am    Post subject: Reply with quote

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:
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)
Back to top
View user's profile Send private message
pk_fox
LXF regular


Joined: Wed Apr 13, 2005 2:38 pm
Posts: 292
Location: Surrey, UK

PostPosted: Mon Sep 16, 2013 3:19 pm    Post subject: Reply with quote

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:
dd if=/dev/urandom of=10g.img bs=1G count=10


Thanks that will do nicely.
Back to top
View user's profile Send private message
ferrari
LXF regular


Joined: Tue May 03, 2005 12:09 pm
Posts: 127

PostPosted: Mon Sep 16, 2013 11:14 pm    Post subject: Reply with quote

Nice explanation of a sparse file Nelz. Smile
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help! All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast