1

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.

3

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!

  • 1
    What version of OS X was in the VM and if 10.11 was SIP enabled? – user3439894 Aug 30 '16 at 21:11
  • @user3439894 It was 10.11 and SIP was disabled! – klanomath Aug 30 '16 at 21:12
  • with crontab maybe : mv etc/fstab/ /etc/fstab.bak; shutdown -t5 -h now that will work? gosh i reaaaally need to lookup somewhere to learn how to script lol – Rafael UP Sep 2 '16 at 7:34
-1

You can probably do this in a script- if you can do it on the command line then you can do it in a script, too. But it seems messy- not sure how much will actually get erased before the system just hangs. Wonder what will be left behind.

I'm curious what problem you're trying to solve here (other than erasing a disk at a specified time)... Are you reinstalling an OS when you're done? If you can setup a NetBoot server then you can create a NetInstall or NetRestore image that will auto-erase a specific volume name.

Another idea is to just delete the user account, assuming the data you're concerned about is contained within the user's home directory.

-1

Same answer as klanomath.

If you're paranoid, you could replace rm by srm for a secure remove but it can take a lot of extra-time.

In the klanomath .plist file, you can write:

<key>ProgramArguments</key>
<array>
    <string>/usr/bin/srm</string>
    <string>-r</string>
    <string>-m</string>
    <string>/</string>
</array>
  • 1
    srm doesn't work. I have tested it. With srm you can only delete distinctive files and globbing (like srm ... /*.*) in the launch daemon doesn't work. – klanomath Aug 30 '16 at 21:28
  • Additionally the path to srm is /usr/bin/srm! – klanomath Aug 30 '16 at 21:35
  • srm your_folder_path doesn't work but, as I wrote it, you must add the -r for recursive. It works on my side. – Nibor Ndj Aug 30 '16 at 22:31

You must log in to answer this question.

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