3

I would like to know how to delete a directory on my MacBook. I have tried several methods such as moving it to the Trash -> Empty Trash, via the command sudo rm -rf, restarting the computer in diagnostic mode and checking the disk with Disk Utility.

These are some of the commands used so far for trying to delete the directory:

rm

$ sudo rm -rf delete_dir
  rm: delete_dir/npm/cache/content-v2/sha512/18/del: Directory not empty
  rm: delete_dir/npm/cache/content-v2/sha512/18: Directory not empty
  rm: delete_dir/npm/cache/content-v2/sha512: Directory not empty
  rm: delete_dir/npm/cache/content-v2: Directory not empty
  rm: delete_dir/npm/cache: Directory not empty
  rm: delete_dir/npm: Directory not empty
  rm: delete_dir: Directory not empty

lsof

$ lsof | grep delete_dir
$ 

rm via inode number

$ cd delete_dir/npm/cache/content-v2/sha512/18/
$ ls -i del/..
  1376336 del/
$ find . -inum 1376336 -exec rm -rfi {} \;
  examine files in directory ./del? y
  remove ./del? y
  rm: ./del: Directory not empty

Via terminal in Recovery Mode, After Running First Aid with Disk Utility

$ mv delete_dir/npm/cache/content-v2/sha512/18/del /tmp/delete_dir 
$ rm -rf /tmp/delete_dir
  rm: delete_dir: Directory not empty
$ cd /tmp/delete_dir
$ ls -lhia
total 0
    1376336 drwxrwxr-x  3 root    staff    96B Jul 14 11:11 ./
12906575931 drwx------  3 jordan  staff    96B Jul 14 20:27 ../

Thank you.

2 Answers2

1

In case it helps anyone, the problem was related to a disk issue reported via Disk Utility -> First aid, and also via the command: 'fsck_apfs'.

I was able to delete the folder via:

  1. Moving the undeletable folder to /tmp/
  2. Installing the latest version of MacOS by joining the Beta program
  3. Done, the folder no longer exists after installing the latest version of MacOS. And first aid returns a successful response.

Another untested alternative that probably should work is:

  1. Backing up important files
  2. Formatting the disk.
  3. Reinstalling the current version of macOS and restoring the Backup
0

Check if the directory is mounted, using this line:

df "/path/to/any/dir/you/need" | sed -nE -e' s|^.+% +(/.*$)|\1|p'

as suggested in this Q/A

In case you find a mount point, umount the directory then remove with the commands you have already used above sudo rm -rf

GabrieleMartini
  • 624
  • 1
  • 7
  • 23