#StackBounty: #linux #macos #unix #rm How to delete a directory in MacOS from the command line?

Bounty: 100

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 Restart and Recovery Mode

$ 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.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.