1834149 Members
4012 Online
110064 Solutions
New Discussion

Re: creating files

 
Sandra R.
Occasional Contributor

creating files

What's the most efficient way to create a larger number of files. Thanks
6 REPLIES 6
Sridhar Bhaskarla
Honored Contributor

Re: creating files

Hi,

If you are trying to create large number of null files, one way is

I=1
LIMIT=1000

while [ $I -le $LIMIT ]
do
touch file.${I}
(( I = $I + 1 ))
done

The above will create 1000 files in the current directory

There may be another efficient way of doing it.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Stefan Farrelly
Honored Contributor

Re: creating files

Same thing - use a loop in a script and use touch, or the prealloc command (prealloc allows you to set the new file to any size whereas touch only creates an empty file).
Im from Palmerston North, New Zealand, but somehow ended up in London...
Robert-Jan Goossens
Honored Contributor

Re: creating files

Hi,

How about this simple one,

# cp /stand/vmunix /tmp/test
# cd /tmp/test
# split -b 10 vmunix

Robert-Jan
Mark Grant
Honored Contributor

Re: creating files

Depends how many is large

"split -l 1 " on a 10000 line file will create 10000 one liners.

Another option would be

while true
do
(( a = a + 1 ))
> newfile.$a
done

Will continually create files until you get bored and press ^C though it will heavily use the machine.
Never preceed any demonstration with anything more predictive than "watch this"
Steven E. Protter
Exalted Contributor

Re: creating files

I would say some kind of loop

while read -r ff
do
touch $ff.tar
done < filelist

How you generate the filelist depends on what you are trying to do.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Michael Schulte zur Sur
Honored Contributor

Re: creating files

Hi,

what do you want to do with so many files, crash the file system? ;-)

Michael