Operating System - HP-UX
1829404 Members
2193 Online
109991 Solutions
New Discussion

Re: Script to create 1000 files of size 1kb each

 
SOLVED
Go to solution
gibsonsamuel
New Member

Script to create 1000 files of size 1kb each

Could some one provide me a script to create 1000 files of size 1kb each on a unix machine.
Thanks a lot in advance.
7 REPLIES 7
G. Vrijhoeven
Honored Contributor
Solution

Re: Script to create 1000 files of size 1kb each

Hi,

I would go for something like this:

COUNT=0
while $COUNT < 1000
do
dd if=/dev/null of=/dir/$COUNT bs=1024 count=1
let COUNT='$COUNT ++ 1'
done

But i bet you will get better answers.

Regards,

Gideon
Wim Rombauts
Honored Contributor

Re: Script to create 1000 files of size 1kb each

You could start of by creating 1 file of the size you want, and then do the following :
$ COUNTER=1
$ ORIG_FILE=
$ while [ $COUNTER -lt 1000 ]
do
cp $ORIG_FILE ${ORIG_FILE}_$COUNTER
COUNTER=$COUNTER+1
done
Robert-Jan Goossens_1
Honored Contributor

Re: Script to create 1000 files of size 1kb each

Hi,

How about

# prealloc testfile 10000000
# split -b 10k testfile

Regards,
Robert-Jan
Hein van den Heuvel
Honored Contributor

Re: Script to create 1000 files of size 1kb each


dd if=/dev/zero bs=1024 count=1000 | split -b 1k -a 3 - test



:-)


Hein.

Muthukumar_5
Honored Contributor

Re: Script to create 1000 files of size 1kb each

you can use prealloc() call too for this as,

i=1
while [ i -le 1000 ]
do
prealloc file${i} 1024
let i=i+1
done

it will create files with file1.. file1000 with 1KB size

HTH.
Easy to suggest when don't know about the problem!
gibsonsamuel
New Member

Re: Script to create 1000 files of size 1kb each

Hi Guys,

Thank you all for the support.
I used a perl script as below.

$i = 0;
for ($i =0;$i<1000;$i++){
$cmd = "echo test > testf" . $i ;
system($cmd);
}

I am closing this thread. Thanks again.
gibsonsamuel
New Member

Re: Script to create 1000 files of size 1kb each

I got scripts with many logics.