How to create hundred thousand (100,000) files in a directory with extension of each .jpg
, .c
, .sh
?
The size of each file will be 5kb and each extension will have 33,333 files.
How to create hundred thousand (100,000) files in a directory with extension of each .jpg
, .c
, .sh
?
The size of each file will be 5kb and each extension will have 33,333 files.
There are many ways to do this:
Using head
with a simple for
construct:
for ext in jpg c sh; do head -c 5K /dev/zero >{1..33333}."$ext"; done
Similarly tail -c 5K
would work also.
Using dd
:
for ext in jpg c sh; do dd if=/dev/zero bs=1K count=5 >{1..33333}."$ext"; done
Using truncate
(this would create sparse files):
for ext in jpg c sh; do truncate -s 5K {1..33333}."$ext"; done
All of the above will create files with extensions .sh
, .c
and .jpg
. Each file will be of 5KB and each extension will have 33,333 files.
truncate
- another quick method would be fallocate
. See askubuntu.com/questions/47963/…
fallocate
but it does not take multiple filenames as argument so will be very very slow in this case..hence did not bother to mention it..
This would help :
mkdir my100000files
cd my100000files/
touch aa
Now write anything in aa to make it 1KB to 10KB
for FILE in `seq 00000 33333`; do cp aa $FILE.c; done
Do the same for .sh and jpg