so me and my friend are having a contest. He says he has a way to fill up a LOT of HDD space on a linux server without being root. Obviously if you are root you can use DD to do this, but our contest is without root. Any good ways to do it?
As normal user, run:
dd if=/dev/zero of=~/foo bs=1M
That makes an empty (but still space-consuming file) at ~/foo. On my computer, it swelled the file at a rate of 39.9 MB/s (my processor is a 3.0 GHz 64-bit Pentium 4,) although I imagine you could open several terminals and have them all running at once...
If it's command-line only, and you can only have one terminal open at once, do this:
dd if=/dev/zero of=~/foo0 & dd if=/dev/zero of=~/foo1 & dd if=/dev/zero of=~/foo2 & dd if=/dev/zero of=~/foo3
..that oughta fill that hard drive up in a flash.
You do not need root to run dd.
You can do this in many ways. Using
/dev/zero as an infinite source of zeros is something which seems to occur to all of us, allowing things like:
cat /dev/zero > ~/my_huge_partition_filling_file.
cp /dev/zero ~/my_huge_partition_filling_file.
- Or, needlessly complex using dd as a user:
dd if=/dev/zero of=~/my_huge_partition_filling_file bs=512K. (The block size part is optional, but setting it to a value larger than 512 bytes may speed things up do to less overhead).
- Or you can create your own file. Take any file, concattenate it with itself to create a second file of double the size, then repeat that. This is what Terdon's answer does.
- Or you can write a program to write endlessly to a file. This is probably needlessly complex and the standard tools are often faster. Also, it feels 'un-unix-like').
You can also fake a huge file by creating a sparse file.
dd if=/dev/zero of=~/my_seemingly_huge_file skip=99999G will instantly create a very small file, which will seem to be 99999 GB. If you want you can read 99999 GB from it. However in practice it consumes almost no space.
Compare it with a book with removable pages. Usually you have page 1,2,3,4,5,6 .... (end of book). With skip you have page 1,2,3, 99999. (pages 4,5,6,... etc will be inserted when written to, but until that time the book will be very thin).
Finally, before you try any of these: Check where you are writing.
If this is on
/home (e.g. to
/home is mounted on its own partition then all you can do is fill up the space for the homedirs. If someone did something silly like putting /home on the root filesystem then you can fill that to 95%. Most admins will not like that.
(95%, or actually 92.2% because the default settings on most filesystems seem to reserve 5% for root. That means it can be filled to 105%, and as a user filling it would use (100/105)%, or 95.2%)
You can take up all the space in a hard disk by doing something as simple as
echo foo > f1.txt; while true; do cat f1.txt >> f2.txt && cat f2.txt >> f1.txt; done
The files will grow exponentially and will occupy all available space if you let the loop run for a while.
dd solution is much more efficient of course, just pointing out that you most certainly do not need root access.
First: You do not need to be root to use dd or other tools to create big or many files.
But second: You cannot fill up the disk if its formatted with default options, because the most used linux filesystems keep 5% of diskspace reserved for root, so no dumb user can fill up the disk and crash the system, because really important processes cannot write their files (think of sshd, syslogd, etc.)