Resolved sudo not working when deleting multiple files through terminal

Discussion in 'macOS' started by doynton, Oct 24, 2015.

  1. doynton macrumors 6502

    Joined:
    Oct 19, 2014
    #1
    I'm trying to write a script to delete things I don't need to save space and am having problems with the -delete parameter on the find command - it isn't actually deleting.

    For example :

    sudo find /System/Library/Speech/Voices -depth 1 -not -name 'SamanthaCompact.SpeechVoice' -delete

    The command completes without error but doesn't actually delete anything.

    Running it without sudo I get the "Permission denied" message for the directories I'm trying to delete.

    I have SIP disabled if that makes a difference. Any ideas what am I doing wrong?

    Code:
    adams-mbp:~ adam$ sudo find /System/Library/Speech/Voices -depth 1 -not -name 'SamanthaCompact.SpeechVoice' -delete
    Password:
    adams-mbp:~ adam$ find /System/Library/Speech/Voices -depth 1 -not -name 'SamanthaCompact.SpeechVoice' -delete
    find: -delete: rmdir(/System/Library/Speech/Voices/Agnes.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Albert.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Alex.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/AliceCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/AlvaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/AmelieCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/AnnaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/BadNews.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Bahh.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Bells.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Boing.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Bruce.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Bubbles.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/CarmitCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Cellos.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/DamayantiCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/DanielCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Deranged.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/DiegoCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/EllenCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/FionaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Fred.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/GoodNews.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Hysterical.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/IoanaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/JoanaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Junior.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/KanyaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/KarenCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Kathy.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/KyokoCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/LauraCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/LekhaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/LucianaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/MagedCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/MariskaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Mei-JiaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/MelinaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/MilenaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/MoiraCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/MonicaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/NoraCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Organ.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/PaulinaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Princess.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Ralph.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/SaraCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/SatuCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Sin-jiCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/TessaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/ThomasCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Ting-TingCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Trinoids.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/VeenaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Vicki.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Victoria.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Whisper.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/XanderCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/YeldaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/YunaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/Zarvox.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/ZosiaCompact.SpeechVoice): Permission denied
    find: -delete: rmdir(/System/Library/Speech/Voices/ZuzanaCompact.SpeechVoice): Permission denied
    adams-mbp:~ adam$ 
     
  2. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #2
  3. doynton thread starter macrumors 6502

    Joined:
    Oct 19, 2014
    #3
    Thank you. This works for that example but if the directory had a space in it Xargs tries to do it for the separate parts..

    For example I created a new folder called "untitled folder" in dictionaries and it tries to delete "untitled" and "folder" separately.
    Code:
    adams-mbp:Documents adam$ find /Library/Dictionaries  -depth 1 -not -name 'Apple Dictionary.dictionary' -and -not -name 'French - English.dictionary' -and -not -name 'Multidictionnaire de la langue française.dictionary'  | xargs rm -r
    rm: /Library/Dictionaries/untitled: No such file or directory
    rm: folder: No such file or directory
    adams-mbp:Documents adam$
    Following your suggestion I used rm -r instead of -delete and it seems to work:

    sudo find /Library/Dictionaries -depth 1 \
    -not -name 'Apple Dictionary.dictionary' \
    -and -not -name 'French - English.dictionary' \
    -and -not -name 'Multidictionnaire de la langue française.dictionary' \
    -exec rm -r {} \;
     
  4. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #4

    Your welcome. That is where quoting or using the -print0 with the command comes in handy as shown in the examples on the page I linked too. When you have spaces in a name you need to either use something like rm file\ with\ space.txt or rm "file with space.txt" in the case of the xargs the print0 example works for that. This one reason all my files I create/save never have spaces or special characters in them total PITA when trying to do anything to them on the command line.
     

Share This Page