Dangerous rm -rf command

Hello All,

I am posting a intresting story which is posted by Mark Brader but actual story is from Mario Wolczko. Original link is here

Thanks,
R. Singh

2 Likes

Here is (part of) one of the scripts passed from a project to us. Gladly we found out readily. Names, places and details of the script have been changed to protect the guilty.....:

var="/some/place"
rm -rf "${vra}/"*

Do not try this at home!

bakunin

1 Like

OUCH!

Took me a couple of seconds to see the typo...

var="/some/place"
rm -rf "${vra}/"*

Does the rm command throw an error when ${vra} does not exist or does it simply proceed with a null byte or something followed by /* erasing everything in its path.

As a beginner in Linux / Bash everything seems to bring up a question.

This has been answered many times before. If the variable vra has not been defined, the command:

rm -rf "${vra}/"*

will invoke rm with one operand for every file in your system's root directory that does not start with a period. The rm command will then attempt to remove every file in the file hierarchies rooted in those pathnames and print a diagnostic message for every file it is unable to remove until you kill that command or wipe out your system.

UNIX and Linux system utilities are generally very happy to try to do whatever you tell them to even if you have told them to do something that could be disastrous. They don't generally try to second guess you and tell you you might be making a mistake.