Remove all files in current dir safely

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-12-03

There is a risk that rm can remove parent directories .. if unused carelessly.

Safe on all systems

$ rm * (this skips hidden dot files. It is totally safe)

Usually safe, but watch out

rm .* deletes hidden files in current directory. At least on macos, it doesn't go near ..

Even if it did go near .. it is usually OK because rm without any options does not touch directories.

But then there is danger that rm was remapped to rm -rf and then the .. directory is at risk.

Therefore interactive mode is your friend: rm -i .* when you are uncertain.