LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2008, 02:31 AM   #1
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Rep: Reputation: 15
Create file of 2 GB


Hi Guys,

I wanted to create a 2 GB file on the currenct directory. with any values but its size shld be 2 GB.

How can i create a 2 GB file through scripting and check its size shld go till 2 GB.
 
Old 09-01-2008, 02:55 AM   #2
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
i am not sure if this is what you wanted
Quote:
dd if=/dev/urandom of=/tmp/2gbfile count=4M
 
Old 09-01-2008, 02:59 AM   #3
mohans.grd@gmail.com
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Rep: Reputation: 0
Lightbulb Hi Swapna

Quote:
Originally Posted by Swapna173 View Post
Hi Guys,

I wanted to create a 2 GB file on the currenct directory. with any values but its size shld be 2 GB.

How can i create a 2 GB file through scripting and check its size shld go till 2 GB.

Easy way to create 2gb file

Go to that current directoy
#dd if=/dev/zero of=filename bs=1024 count=2GB
 
Old 09-01-2008, 03:00 AM   #4
mohans.grd@gmail.com
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Rep: Reputation: 0
Easy way to create 2gb file

Go to that current directoy
#dd if=/dev/zero of=filename bs=1024 count=2GB
 
Old 09-01-2008, 03:35 AM   #5
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by mohans.grd@gmail.com View Post
Easy way to create 2gb file

Go to that current directoy
#dd if=/dev/zero of=filename bs=1024 count=2GB
this command is creating file of size more than 2 GB. How can i restrict to 2 GB exactly.
 
Old 09-01-2008, 03:40 AM   #6
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
now, now, read a bit.
Quote:
man dd
or play around with the commands
Quote:
dd if=/dev/zero of=filename bs=1024 count=100
dd if=/dev/zero of=filename bs=1024 count=1000
dd if=/dev/zero of=filename bs=1024 count=10000
dd if=/dev/zero of=filename bs=1024 count=200000
Analyse the output, hopefully you will understand.

Last edited by w3bd3vil; 09-01-2008 at 03:43 AM.
 
Old 09-01-2008, 04:27 AM   #7
mohans.grd@gmail.com
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Rep: Reputation: 0
dd if=/dev/zero of=filename bs=1024 count=2M
 
Old 09-01-2008, 04:28 AM   #8
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by w3bd3vil View Post
now, now, read a bit.

or play around with the commands

Analyse the output, hopefully you will understand.


Hey thanks.

This one worked.
 
Old 09-01-2008, 05:03 AM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Look at the "seek" option of dd. Since you don't care about it being zeroed out or have psuedorandom numbers, creating a file by using an offset will be quicker.
Code:
 dd bs=1024 count=1 seek=$((1024*1024*2-1)) if=/dev/zero of=dummyfile
This will seek to 1024 bytes shy of 2GB and write one 1024 byte block to finish.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create File Shell Syntax and pass data to the file FirstBorn Linux - General 22 07-31-2008 09:48 PM
how to create a new file including content from reading another file !? silverhand Programming 2 10-06-2007 04:33 PM
how to create file with a specific file size markraem Linux - Software 7 08-22-2007 06:38 PM
Create video file with same parameters from other file? gbowden Linux - Software 1 04-30-2007 05:28 PM
Create header file for existing .c file hk_michael Programming 5 02-25-2005 05:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration