Home > Tips and tricks > Preventing the accidental rm -rf /

Preventing the accidental rm -rf /

July 6th, 2006 Patrick

Eons ago when I started to explore Linux and F/OSS as an enthousiastic newbie, I made the mistake, twice, of accidentally typing in:


[root@server ~]# rm -rf /

While what I actually wanted to do was:


[root@server ~]# rm -rf ./

The consequences of such a mistake are severe since you literally deleted the entire filesystem. To prevent this from happening there is a neat little trick:


[root@server ~]# touch -- /-i

When you (accidentally) try to delete the root filesystem / you will be asked by the rm command to confirm your action. This way there is a safety that prevents you from deleting the root filesystem without any questions asked.

Categories: Tips and tricks Tags:
Comments are closed.