Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iBookG4user

macrumors 604
Original poster
Jun 27, 2006
6,595
2
Seattle, WA
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.
 

mkrishnan

Moderator emeritus
Jan 9, 2004
29,776
15
Grand Rapids, MI, USA
So I tried to delete it using sudo rm -r

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.
 

iBookG4user

macrumors 604
Original poster
Jun 27, 2006
6,595
2
Seattle, WA
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.

Thanks, that worked!
 

mkrishnan

Moderator emeritus
Jan 9, 2004
29,776
15
Grand Rapids, MI, USA
My mistake...I never tried deleting directories without the -d so I thought it was necessary...thanks!

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.
 

chkdg8

macrumors 6502
Oct 24, 2007
250
0
Just a quick question. When you rm a file through terminal, does it just skip the trash all together?
 

chkdg8

macrumors 6502
Oct 24, 2007
250
0

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.
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
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.

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.
 

Notsmart

macrumors newbie
Apr 8, 2011
1
0
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!!!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.