This is a shell script for Bash, called ‘rm_secure’. I use it as frontal for the rm command. It stores the deleted files in an archive in the user’s directory. A command-line option allows the user to view the content of this archive, and another option permits the restoration of the deleted files.

in /etc/profile, so this script will be called by Bash in the place of the true rm command.

You can use the ‘–nosecure’ or ‘-n’ option to delete a file without archiving it. This is useful when you decide to erase huge amount of files in recursive directories (for example a package you have tested but find uninteresting).

I use a cron job to deleted the archived files every day (running as root job).

in /etc/profile, which erase the archive each time the user exits the shell. (I’ve not fully tested this)

Obviously this tips doesn’t secure the deletion of files or directories by a file-manager, but I find it quite usefull, especially when doing administrative jobs as root (‘rm tmp/ *’ in place of ‘rm tmp/*’ …)

OPTIND is a special variable for Bash. Here’s an excerpt of the bash man page :

OPTIND The index of the next argument to be processed by the getopts
builtin command (see SHELL BUILTIN COMMANDS below).
[...]
getopts optstring name [args]
getopts is used by shell procedures to parse positional parame‐
ters. optstring contains the option characters to be recog‐
nized; if a character is followed by a colon, the option is
expected to have an argument, which should be separated from it
by white space. The colon and question mark characters may not
be used as option characters. Each time it is invoked, getopts
places the next option in the shell variable name, initializing
name if it does not exist, and the index of the next argument
to be processed into the variable OPTIND. OPTIND is initial‐
ized to 1 each time the shell or a shell script is invoked.
When an option requires an argument, getopts places that argu‐
ment into the variable OPTARG. The shell does not reset OPTIND
automatically; it must be manually reset between multiple calls
to getopts within the same shell invocation if a new set of
parameters is to be used.
When the end of options is encountered, getopts exits with a
return value greater than zero. OPTIND is set to the index of
the first non-option argument, and name is set to ?.
getopts normally parses the positional parameters, but if more
arguments are given in args, getopts parses those instead.
[...]