1

After turning on Developer mode and installing the Windows Subsystem for Linux, how can I use the rm command in the bash shell running in Administrator mode?

Example:

rm -rf --no-preserve-root C:/Windows/System32
13
  • Try removing the C: part. Linux doesn't use that stuff. (I'm not sure whether the linux subsystem allows that however)
    – user571603
    Mar 20, 2017 at 14:45
  • WARNING: If it worked that command would break Windows ...
    – DavidPostill
    Mar 20, 2017 at 15:19
  • You are looking for /mnt/c/... but see the warning above.
    – DavidPostill
    Mar 20, 2017 at 15:21
  • @DavidPostill Using /mnt/c/ might work while using Unix OS, but will the command work successfully when running in bash on Windows? Because I think Windows doesn't have the equivalent of preserve-root.
    – c2416726
    Mar 20, 2017 at 15:27
  • But.... uh... why? just run format C: from regular cmd
    – undo
    Mar 20, 2017 at 15:27

1 Answer 1

1

How can I use the rm command in the bash shell running in Administrator mode?

Example:

 rm -rf --no-preserve-root C:/Windows/System32

WARNING: Do not attempt the following.

When using bash in WLS you need to address drives by using the mount points, so C:/ becomes /mnt/c/.

However, if you attempt to run the above command corrected as I have described you will Destroy Windows.

While the command runs, you’ll start notice that Windows will revert to default program settings as applications and classic programs are fully or partially deleted from your system. You’ll also notice that customization such as themes and desktop backgrounds will start to drop out. If you haven’t realized it yet, your system is about to die.

Keep reading for all the gory details.


rm -rf / in Windows Subsystem for Linux reveals sharp set of teeth

Don’t run any commands mentioned in this article. They’re intentionally very destructive for your Windows system.

I had a go at running rm ​-rf --no-​preserve-root "/​mnt/c" in the new Windows Subsystem for Linux. I knew I could interact with the full file system and modify and delete files, but I didn’t expect it to be as potent as it turned out to be.

While the command runs, you’ll start notice that Windows will revert to default program settings as applications and classic programs are fully or partially deleted from your system. You’ll also notice that customization such as themes and desktop backgrounds will start to drop out. If you haven’t realized it yet, your system is about to die.

Like when you run this command under a full Linux kernel, the system will usually buckle before it manages to delete every file completely. Files currently loaded by the Windows kernel and files not writable by users in the Administrator user group in Windows will not be deleted. That, however, will still delete large chunks of critical system files and programs in Windows.

Running the above command will delete some 12 000 files in the default Windows installation directory at C:Windows as well as all user files in C:Users and leave your system incapable of booting up again! While you can still carry on working in the session for quite some time, it will eventually stop responding and throw you into a blue screen. Upon restarting, Windows will be missing drivers and other required files.

Running rm ​-rf --no-​preserve-root "/​" will only destroy your installation of the Windows Subsystem for Linux. Running lxrun.exe /uninstall /full /y && lxrun.exe /install /y in the Command Prompt will reinstall it and have you back up and running in Ubuntu in no time. It will not traverse the symlink to the Windows file system in the mount point and start deleting things on your C: drive. Doing so explicitly with the first command I mentioned, will not stop you from gutting your system.

Source rm -rf / in Windows Subsystem for Linux reveals sharp set of teeth

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .