MacOS – Run script for delete HD

applescriptmacosrootterminal

Is there a way to run a script on a Mac that literally will do
( sudo rm -rf / )?

I need to schedule a complete wipe of my hard drive on next Friday at 6PM. I'm not very familiar with scripts so there's no clear answer for me. Can I run a script that doesn't involve me to grant the sudo password? I do have my root user password.

Best Answer

Just create a launch daemon with

sudo touch /Library/LaunchDaemons/user.local.rm.plist
sudo chown root:wheel /Library/LaunchDaemons/user.local.rm.plist
sudo chmod 644 /Library/LaunchDaemons/user.local.rm.plist

Open an editor:

sudo nano /Library/LaunchDaemons/user.local.rm.plist

and edit in the following content :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>user.local.rm</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/rm</string>
        <string>-rf</string>
        <string>/</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>18</integer>
        <key>Minute</key>
        <integer>00</integer>
        <key>Weekday</key>
        <integer>5</integer>
    </dict>
</dict>
</plist>

Load the launch daemon with:

sudo launchctl load /Library/LaunchDaemons/user.local.rm.plist

This will remove almost any file and folder of your internal disk next friday. My virtual machine stopped working with an empty root folder and (according to the status bar) ~6 GB of disk space occupied. Finally it may be less though and the "6 GB" was just the last reportable value.

This will not erase (=overwrite with random data) your files and folders completely: any decent data recovery tool will probably restore almost all previous content.

In El Capitan this only works if SIP is disabled!