It Happened: Steam Does the "rm -rf /*" on Linux

Share

In 2015, Steam accidentally deleted all of a user's files on Linux due to a bug in a Bash script.

A Github issue titled "Moved ~/.local/share/steam. Ran steam. It deleted everything on system owned by user. #3671" opened by "keyvin" on "Jan 14, 2015." It reads: Edit: Please stop posting stupid image memes or unhelpful messages. This interferes with Valve's ability to sift through the noise and see if anyone can figure out what triggers it. This may not be a common problem because I change all sorts of configuration about my system. The script in question does something in a really, really stupid way, but it probably doesn't trigger the fail scenario for every system because... Original Bug: I am not sure what happened. I moved the folder in the title to a drive mounted under /media/user/BLAH and symlinked /home/user/.local/steam to the new location. I launched steam. It did not launch, it offered to let me browse, and still could not find it when I pointed to the new location. Steam crashed. I restarted it. It re-installed itself and everything looked great. Until I looked and saw that steam had apparently deleted everything owned by my user recursively from the root directory. Including my 3tb external drive I back everything up to that was mounted under /media. Everything important, for the most part, was in the cloud. It is a huge hassle, but it is not a disaster. If there is the chance that moving your steam folder can result in recursively deleting everything in the directory tree you should probably just throw up an error instead of trying to point to other stuff. Or you know, allow the user to pick an install directory initially like on windows. My system is ubuntu 14.04, and the drive I moved it to was ntfs if its worth anything. Under the text, various emoji reactions with counts totally over one hundred can be seen.
A screenshot of the Github issue in which Steam deleted all of a user's files on Linux.

Why It Happened?

Moved ~/.local/share/steam. Ran steam. It deleted everything on system owned by user.

rm -rf "$STEAMROOT/"* could be evaluated as rm -rf "/"* if $STEAMROOT is empty

https://github.com/ValveSoftware/steam-for-linux/issues/3671#issuecomment-70159084 (accessed 2025-02-19)

The cause of the issue seemed to be in the way the zeroth argument passed by the shell was handled.

I believe the issue starts on line 19:

# figure out the absolute path to the script being run a bit
# non-obvious, the ${0%/*} pulls the path out of $0, cd's into the
# specified directory, then uses $PWD to figure out where that
# directory lives - and all this in a subshell, so we don't affect
# $PWD

STEAMROOT="$(cd "${0%/*}" && echo $PWD)"
STEAMDATA="$STEAMROOT"

This probably returns as empty which mean: rm -rf "$STEAMROOT/"* is the same ass rm -rf "/"*.

https://github.com/ValveSoftware/steam-for-linux/issues/3671#issuecomment-70161790 (accessed 2025-03-06)

Essentially, what has happened was that they wrote rm -rf "${0%/*}/*" to delete all files in the directory where a program was installed. If $0 (the zeroth argument) was /folder/program, then "${0%/*}" would evaluate to /folder. However, if $0 was just program, then "${0%/*}" would be an empty string "" , which means rm -rf "${0%/*}/*" evaluates to rm -rf /*, and that's how all files get deleted.

Written by Noel Santos.

About the Author

I'm a self-taught Brazilian programmer graduated in IT from a FATEC. In a world of increasingly complex and essential computers, I decided to use my technical expertise in hardware, desktop applications, and web technologies to create an informative resource to make PC's easier to understand.

View Comments