The Code
Let's start with this variant, which I found as the
result of a Google search:
% more ~/bin/trash
#!/bin/sh
# script to send removed files to trash directory
mv $1 ~/.trash/
You should recognize the path to the Bourne shell, the comment, and
the mv command. Let's take a look
at that $1. This is known as a
positional parameter and specifically refers
to the first parameter of the trash command. Since
the mv commands takes filenames as parameters, the
command:
mv $1 ~/.trash/
is really saying, mv the first filename, whatever
it happens to be, to a directory called .trash
in the user's home directory (represented by the
shell shortcut of ~). This move operation is our
custom "recycle."
Before this script can do anything, it must be set as executable:
% chmod +x ~/bin/trash
And I must create that trash directory for it to use:
% mkdir ~/.trash
Note that I've chosen to create a hidden trash
directory; any file or directory that begins with the
. character is hidden from normal listings. This
really only reduces clutter, though, as you can see these files by
passing the -a switch to ls. If
you also include the F switch, directory names
will end with a /:
% ls -aF ~
.cshrc .history .trash/
bin/ images/ myfile