Terminal command to delete a folder filed with locked files?

Discussion in 'Mac Applications and Mac App Store' started by iBookG4user, Jun 27, 2007.

  1. macrumors 604

    iBookG4user

    Joined:
    Jun 27, 2006
    Location:
    Seattle, WA
    #1
    I was helping a friend by reformatting his pc and reinstalling windows because it was slow, when I was downloading the drivers for it on my MacBook Pro (didn't have access to the router since it's downstairs and his pc didn't have a wireless card), it downloaded a folder filled with locked files, it comes several folders deep and all of the files are locked, fun. So I tried to delete it using sudo rm -r, but it says I don't have sufficient privileges, anyone know a command I can use to delete it all? I'd rather not do it by hand, that'd take forever.
     
  2. macrumors 68020

    theBB

    Joined:
    Jan 3, 2006
    #2
  3. Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #3
    No, I think you just need to add an f -- the r makes it recursive (so it can delete a folder and files); the f overrides permissions.

    sudo rm -rf

    I don't think there should be anything deleterious resulting from doing that. Just be careful to rm -rf the right thing -- there aren't any limits to what it can delete.
     
  4. thread starter macrumors 604

    iBookG4user

    Joined:
    Jun 27, 2006
    Location:
    Seattle, WA
    #4
    Thanks, that worked!
     
  5. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #5
    -rf is sufficient. No need for the -d switch.
     
  6. macrumors 603

    OutThere

    Joined:
    Dec 19, 2002
    Location:
    NYC
    #6
    My mistake...I never tried deleting directories without the -d so I thought it was necessary...thanks!
     
  7. Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #7
    I think you use the d switch if you want to delete an empty directory? But I'm not even sure about that. Maybe I'm confabulating from the days of rmdir nonsense.

    EDIT: I read back on the -d flag. According to the man page, -d unlinks even non-empty directories when a superuser does it (meaning that sudo rm -df should delete a non-empty directory). I'm a little confused about any consequences for not unlinking the internal files individually, i.e. if there is any adverse impact of sudo rm -df vs. sudo rm -rf. In any event, though, -rf seems safer, since it does actually bother to delete each file.
     
  8. macrumors 6502

    Joined:
    Oct 24, 2007
    Location:
    Coral Springs, Florida
    #8
    Just a quick question. When you rm a file through terminal, does it just skip the trash all together?
     
  9. Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #9
    Yes.
     
  10. macrumors 6502

    Joined:
    Oct 24, 2007
    Location:
    Coral Springs, Florida
    #10
    Thank you angelwatt. I just wanted to know the ins and outs of proper file removal and or deletion because I was doing Empty Trash Securely for the past six months. Although this process takes an extremely long time with large files, I went back to trashing normally because 1. I'm the only user and 2. I don't have ultra secret NSA files on my mac that requires secure deletion. Now that I know that a deleted file's space will eventually get erased by something else, I'm all good in knowing that terminal deletes just as good.
     
  11. Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #11
    In case you ever need it there's also a srm command that does a secure removal, which is the same as a secure empty trash, I think. Do a "man srm" to see the other options, like for using only a 1-pass or 7-pass erase rather than the default 35-pass, which is overkill for most people.
     
  12. macrumors newbie

    Joined:
    Apr 8, 2011
    #12
    Cannot Delete Folder

    I was unzipping files I had copied from a CD-ROM and had to abort midstream. I now have the incomplete files on my flash drive and cannot delete them. The individual files are locked, and I can delete them individually, but that would take forever. I emptied a few folders of the files, but I cannot delete the folders. The folders do not indicate they are locked when I press command+I. I tried sudo rm -rf. The first time, it asked for a password so I entered my admin password, but nothing happened. I tried it again, even adding the -d switch, but now the message is:

    rm: illegal option -- /
    usage: rm [-f | -i] [-dPRrvW] file ...
    unlink file

    How can I get rid of these folders? I cannot reformat the flash drive because I have several other files on it that I need. THANK YOU!!!!
     

Share This Page