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.

5
  • There may be open files still in use that prevent removal of directories. The lsof command may not be reliable; read the man page for limitations and bugs. So try closing all applications first.
    – sawdust
    Commented Jul 13, 2019 at 8:05
  • discussions.apple.com/thread/250487426
    – ipegasus
    Commented Jul 16, 2019 at 3:37
  • communities.apple.com/es/thread/250487384
    – ipegasus
    Commented Jul 16, 2019 at 3:38
  • It seems you have done everything that was ever advised for such problems. So try repairing the disk using Disk Utility. The command is perhaps "Run First Aid..." under the File menu.
    – harrymc
    Commented Jul 16, 2019 at 6:38
  • Hi, try make each file and directory there readable, writeable etc with something like sudo chmod a+xrw -R your_Main_dir, then to remove with sudo rm -rf your_Main_dir. It should work if related to read access (if you cannot read it you may not delete it). Else you can try to rsync with /dev/null deleting the origin directory files (search for it)... The interesting point is to understand why you cannot delete and what exactly you cannot: I remember something like if you cannot read a directory really you cannot read the files inside...).
    – Hastur
    Commented Jul 18, 2019 at 13:48

2 Answers 2

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

1
  • Thanks but it does not seem to have anything mounted $ df "/Users/jordan/.Trash/delete_dir" | sed -nE -e' s|^.+% +(/.*$)|\1|p' / $
    – ipegasus
    Commented Jul 17, 2019 at 20:54

You must log in to answer this question.

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