7

I need to delete a folder otherwise my mac won't boot. How can I do this in recovery mode or whatever it's called using Terminal commands?

Tony Friz
  • 181

2 Answers2

10

Boot into recovery mode, mount volume, and open Terminal

  1. Boot to recovery mode by holding CommandR right after starting your Mac before the Apple logo appears.

  2. Go into Disk Utility and check that your target disk volume is mounted. Mount it if it's not already mounted.

  3. Close Disk Utility, and open Terminal from Utilities menu.

Removing files from Terminal

Enter cd /Volumes then ls to list all mounted volumes.

Enter, e.g., cd Volume_Name/Users/<username>/path/to/parent_directory with parent_directory being the directory containing the target directory you want to delete.

Be careful, as you have nothing restricting you from deleting required system files! Unless otherwise necessary, you should only delete files from your home directory (/Volumes/<Volume_Name>/Users/<username>/)

Example: If you want to delete a folder "xyz" in "Macintosh HD" (the example name of your main volume) enter cd "Macintosh HD/Users/username", replacing username with your user name.

Then enter ls again to list all files and directories to be sure that you are in the correct working directory.

Then enter rm -r folder_to_delete or rm -rf folder_to_delete

  • -r: Removes a folder and its content recursively.
  • -rf: Removes a folder and its content recursively, attempts to remove the files without prompting for confirmation, regardless of the file’s permissions, and ignore any errors.

Example: If you want to delete a folder "xyz" and all containing files and folders enter: rm -r xyz

user3439894
  • 58,676
klanomath
  • 66,391
  • 9
  • 130
  • 201
  • 4
    @2rs2ts, this did work for me but required me to go first into "Disk Utility" and mount the APFS encrypted volume. Then closing Disk Utility and opening Terminal worked as described here. (macOS Mojave) – Unapiedra May 04 '19 at 19:39
  • I tried that, opened disk utility to mount, I have a file in trash that refuses to delete but even in recovery mode, as root, it says permission denied. What the hell Apple. I tried to repair the disk with disk utility and it says no issues found. – Hackeron Jun 24 '23 at 11:09
  • Any idea why "rm -rf" works (no error and the folder/file disappeared) but the free space stays the same? I've already tried deleting Xcode, Xcode-beta and another big files. – אורי orihpt Jul 03 '23 at 18:14
0

On Apple Silicon they added more security, even after booting into recovery mode and mounting the drive with Disk Utility, it is still impossible to delete ~/.Trash for some reason (other files can be deleted though).

The only solution I could find was to run csrutil disable in the terminal, rebooting, deleting the relevant files and then re-enabling csr back in recovery mode.

The reason I had to do this was for some reason I stopped being able to empty my trash, saying the file is "In Use" (even in safe mode).