How do I delete a file using Terminal?

Discussion in 'macOS' started by Sal Collaziano, Nov 6, 2008.

  1. Sal Collaziano macrumors regular

    Joined:
    Nov 7, 2007
    Location:
    Royal Palm Beach, FL
    #1
    I need to delete a file that I cannot access via Finder. Is there a command that I can use in terminal to delete it? I cannot access the folder the file exists in via Finder..

    The file is in /usr/local/

    Thanks in advance...
     
  2. kg9ov macrumors member

    Joined:
    Feb 12, 2005
    Location:
    In front of a computer...
  3. vandozza macrumors 6502a

    vandozza

    Joined:
    Jun 14, 2006
    Location:
    Australia
    #3
    the command that you want is "rm", but do be very careful with this :)

    rm /usr/local/filename

    in the terminal type -
    man rm

    for more information.
     
  4. Sal Collaziano thread starter macrumors regular

    Joined:
    Nov 7, 2007
    Location:
    Royal Palm Beach, FL
    #4
    Thank you.. I'm actually trying:

    rm -d -f /usr/local/foldername

    ...with no luck. I'm getting permission denied errors.. Any other ideas?

    Thanks in advance...
     
  5. smukkebenne macrumors member

    Joined:
    Dec 19, 2006
    Location:
    Somewhere pretty
  6. Sal Collaziano thread starter macrumors regular

    Joined:
    Nov 7, 2007
    Location:
    Royal Palm Beach, FL
    #6
    Okay. I think I'm making progress here.. Now it says, "Directory not empty"...

     
  7. deltaiscain macrumors regular

    Joined:
    Jul 24, 2008
    #7
    oh, and to delete a folder, type rmdir and the filepath
     
  8. Sal Collaziano thread starter macrumors regular

    Joined:
    Nov 7, 2007
    Location:
    Royal Palm Beach, FL
    #8
    ...still getting permission denied.. Do I have to login as somebody else? I'm the only person who's ever used this computer...

     
  9. vandozza macrumors 6502a

    vandozza

    Joined:
    Jun 14, 2006
    Location:
    Australia
  10. Sal Collaziano thread starter macrumors regular

    Joined:
    Nov 7, 2007
    Location:
    Royal Palm Beach, FL
    #10
    Yes. I enter a password and then get "Directory not empty"... Strange?

     
  11. vandozza macrumors 6502a

    vandozza

    Joined:
    Jun 14, 2006
    Location:
    Australia
    #11
    "cd" into the directory
    "ls" to list contents
    "rm" individual files?

    then try to remove the directory again?

    sorry i can't help much!
     
  12. ergdegdeg Moderator emeritus

    ergdegdeg

    Joined:
    Oct 13, 2007
    #12
    sudo rm -r foldername
    deletes folder and all contents. be careful with it!
     
  13. Sal Collaziano thread starter macrumors regular

    Joined:
    Nov 7, 2007
    Location:
    Royal Palm Beach, FL
    #13
    This was working on directories inside the folder - but not the regular files...

    This worked.. Thank you. I appreciate all the advice I received in this discussion. Hopefully it'll serve many down the road. :)
     
  14. eightysjoe, Apr 22, 2013
    Last edited: Apr 22, 2013

    eightysjoe macrumors newbie

    Joined:
    Mar 6, 2013
    #14
    Hey guys. I know this is an old thread, but I found it while trying to figure out one of my own problems and it seems like it is going to lead me in the right direction.

    I allowed one of my friends to use my external drive to copy some stuff I had on there. He has a PC that is apparently infected with a .scr virus.

    Obviously the file isn't going to mess up anything on my macbook, but I'm not sure about my Toshiba external hard drive. It has already made a bunch of useless copies of random nonsensical files on my drive and I want to get rid of it before it messes up any of the information I have on there.

    I tried sudo rm -r /volumes/volumename/filename and got the password prompt. Then it returned 'override rwxrwxrwx _unknown/_unknown arch,uchg,hidden for /volumes/[volumename]/[filename]?'

    Any ideas on how to continue on from here? Or what I may have done wrong?

    I appreciate any and all help

    EDIT

    Also, I responded yes to the override and it returned 'Operation not permitted'

    Sorry to leave that part out originally.
     
  15. ScoobyMcDoo macrumors 65816

    Joined:
    Nov 26, 2007
    Location:
    Austin, TX
    #15
    In that message you can see "uchg", which is the "user immutable" flag. I don't think it will let you delete it with that flag. To turn it off, use the chflags command:

    Code:
    chflags nouchg <filename>
    You might also want to know about the -f flag for the rm command. It will answer "yes" to all of the questions so you don't get prompted. For example

    Code:
    sudo rm -rf /
    will delete all files on your system without asking for any confirmation. So obviously be very careful with this command.

    To learn more about these commands as well as most commands available through the shell there is the "man" command:

    Code:
    man rm
    man chflags
    
     
  16. eightysjoe macrumors newbie

    Joined:
    Mar 6, 2013
    #16
    You made my life so much easier. Thank you for the help!
     
  17. Fishrrman macrumors G3

    Joined:
    Feb 20, 2009
    #17
    An easy way to delete or move invisible files is to get ahold of "Path Finder" (a finder substitute utility).

    It has an option to make all the invisible files/folders visible (can be quickly toggled on and off).

    Choose to make everything visible, then manipulate the files you need to work on.
    Then, just choose to make normally-invisible files, invisible again.
     

Share This Page