Removing a File Once It's Opened - for Security and Easy Cleanup
Once a process has opened a file (), UNIX won't delete the file until the process closes it. (The rm command only removes a link to the file from a directory, not the file itself.)
I've heard arguments () about whether removing a file while it's open is a good idea. If you want to run a set of commands from a file, but not let anyone else read the list of commands you're using, you can write a shell script that removes itself before doing anything else. (You should be aware that if you use a filesystem mounted by NFS (), NFS will just rename the "removed" file to a hidden filename () like nfsXXXXX.)
Here's a simple self-removing shell script:
%cat doit
rm doit # by now, shell has opened this file; we can remove it ls doit make bigprog ... %sh doit
ls: doit not found cc -target sun4 -c routine.c ...
Here's a more typical script that opens and removes a file in /tmp ():
exec <&- |
% |
---|
- JP