What is the safest way to empty a directory in *nix?

The safest way is to sit on your hands before pressing Enter.

That aside, you could create an alias like this one (for Bash)

alias rm="pwd;read;rm"

That will show you your directory, wait for an enter press and then remove what you specified with the proper flags. You can cancel by pressing ^C instead of Enter.


Here is a safer way: use ls first to list the files that will be affected, then use command-line history or history substitution to change the ls to rm and execute the command again after you are convinced the correct files will be operated on.


If you want to be really safe, you could create a simple alias or shell script like:

mv $1 ~/.recycle/

This would just move your stuff to a .recycle folder (hello, Windows!).

Then set up a cron job to do rm -rf on stuff in that folder that is older than a week.