#!/usr/bin/perl -w # Strict use strict; use warnings; # Main program print "Check file before unlink\n"; sleep 1; system("ls $0"); print "Unlinking the file $0\n"; sleep 1; unlink $0; print "Check file after unlink\n"; sleep 1; system("ls $0"); print "File should be now be gone from disk (but still in memory)\n"; print "Try ^Z and check it with 'ls $0' ... (come back with 'fg')\n"; sleep 10; print while ; print "I'm still here, but the original file is long gone.\n"; __END__ foo #### #!/usr/bin/perl -w # Strict use strict; use warnings; use File::Basename; # Main program print "Check file before unlink\n"; sleep 1; system("ls $0; df -k $0"); print "Unlinking the file $0\n"; sleep 1; unlink $0; print "Check file after unlink\n"; sleep 1; system("ls $0; df -k " . dirname($0)); print "File should be now be gone from disk (but still in memory)\n"; print "Try ^Z and check it with 'ls $0' ... (come back with 'fg')\n"; sleep 10; 1 while ; # ensure we use the *DATA filehandle in case perl optimises it away print "I'm still here, but the original file is long gone.\n"; __END__ foo #### $ cp z.pl /ram; perl /ram/z.pl Check file before unlink /ram/z.pl Filesystem 1K-blocks Used Available Use% Mounted on none 100 4 96 4% /ram Unlinking the file /ram/z.pl Check file after unlink ls: /ram/z.pl: No such file or directory Filesystem 1K-blocks Used Available Use% Mounted on none 100 4 96 4% /ram File should be now be gone from disk (but still in memory) Try ^Z and check it with 'ls /ram/z.pl' ... (come back with 'fg') I'm still here, but the original file is long gone. $ df -k /ram Filesystem 1K-blocks Used Available Use% Mounted on none 100 0 100 0% /ram