Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Unix Executable File Deletion

I know this subject has been discussed before because I've read alot of the material on this board, but I'm having no luck with my particular problem.


I believe that my WD Backup HD has been loading these locked files onto my iMac HD. They all seem to be related to Walmart, they're all locked, and when I attempt to delete them, some begin getting deleted, but within seconds I'm told that one of them, "", is not unlockable. And of course, they all seem to reappear anyway.


The problem is, there's over 10000 files....over 10000 today and over 10000 yesterday. So, I can't individually change the extension to get them deleted -- there's too many. And, I don't know how to use Terminal to delete that many -- only to delete one at a time.


Any ideas?


Much thanks.


Mo

PS I disconnected the WD so that it couldn't download any more files.

iMac, Mac OS X (10.6.8)

Posted on Mar 7, 2013 5:45 PM

Reply
12 replies

Mar 8, 2013 2:03 PM in response to zehutiman

Since the Terminal is a "do it now, no second chance" type of action, you should backup the drive first so you can restore it if necessary.


1) Open the Terminal app.


2) Type


sudo rm


with a space after the rm and stop.


3) Drag and drop the folder containing these files into the Terminal window. It's path will be added to the end of the text you typed.


4) Since a space will automatically be added to the end, backspace once. Now type


/*


You'll end up with a string something like:


sudo rm /Users/username/Desktop/Skys/*


The asterisk means everything in that folder, so make sure there's no files or subfolders in it you need to keep.


5) Press return. Terminal will ask for your admin password. It is not returned on screen as you type it, so make sure to enter it correctly. Press return again.


6) If you've entered things correctly, Terminal will simply move to the next command prompt and all files and folders within the folder you selected will go bye-bye.

Mar 8, 2013 3:30 PM in response to Kurt Lang

Well, here's what happened:


First, you'll have to forgive my newness with the iMac, but I couldn't see how to "move" all the files into a folder. I created a new folder and, was able to copy all the files (10000+), but that's not the same as moving them, right?


I followed your instructions (which were excellent, btw), but for only a handful of files that I copied into the new folder I created, just to see how it all worked. This is the response I got:


Maurice-Fairleys-iMac:~ zehutiman$ sudo rm /Users/zehutiman/Desktop/Special/*

override rwxr-xr-x zehutiman/staff uchg for /Users/zehutiman/Desktop/Special/logo@198.jpg? y


I had to answer "y" for each file. Obviously, I can't do that for all 10000+ files.


So, I've gotta ask: 1) How do i move the files instead of just copying them, and...


2) How do I avoid being asked if I wish to "override," for each file?


Thanks, once again.


Mo

Mar 8, 2013 3:52 PM in response to zehutiman

I created a new folder and, was able to copy all the files (10000+), but that's not the same as moving them, right?

Right. You're just getting copies of the same files in more than one place.

1) How do i move the files instead of just copying them

You can just leave them where they are if everything in the folder they're currently in are junk anyway. But they should only copy if they're being dragged and dropped to a different drive or partition. Otherwise, they should move. Though again, there's no reason to do that if you want to pitch everything. The only other reason they would copy if on the same drive is that they all have permissions that don't allow you to move them.

2) How do I avoid being asked if I wish to "override," for each file?

My goof. Forgot to add an argument (option). It should be


sudo rm -R


The -R is followed by a space. Then continue on as above with step three. The -R option (abbreviated) tells the remove command (rm) to just do it, don't ask me.


With a lot of files/folders to remove, the prompt may sit and appear to do nothing for a bit. It is working. It just won't move to the next prompt until the command it complete.

Mar 8, 2013 5:28 PM in response to Kurt Lang

Hi Kurt


>>The -R option (abbreviated) tells the remove command (rm) to just do it, don't ask me.


-R Attempt to remove the file hierarchy rooted in each file

argument. The -R option implies the -d option. If the -i

option is specified, the user is prompted for confirmation

before each directory's contents are processed (as well as

before the attempt is made to remove the directory). If the

user does not respond affirmatively, the file hierarchy

rooted in that directory is skipped.


-f Attempt to remove the files without prompting for confirma-

tion, regardless of the file's permissions. If the file does

not exist, do not display a diagnostic message or modify the

exit status to reflect an error. The -f option overrides any

previous -i options.


>>they should only copy if they're being dragged and dropped to a different drive or partition. Otherwise, they should move.


but these are locked - "override rwxr-xr-x zehutiman/staff uchg"

so Finder will only copy

Mar 8, 2013 7:31 PM in response to andyBall_uk

Hi Andy,


Yes, I know what the manual for rm states for the -R switch. As I noted, I was abbreviating (in a loose way). It does, in effect, do that. Without the switch you have confirm deletion of every single file and folder. With it, you don't.


Whoop! Also yes. While thinking about my replies, I completely forgot the OP mentioned the files were all locked. So they of course will only copy.

Mar 9, 2013 5:10 AM in response to Kurt Lang

The -R option is meant to apply the command, in this instance rm, recursively to every file ("the flle hierarchy") within a folder. In other words, it's meant for rming folders, and the -i, which is really an independent option, would be used only in this instance when you wish to be asked to confirm the rm command for the folder named in the path. With both the -i option and the -R option, you would be asked for confirmation before a folder is removed, but after confirming all the files contained within that folder would be removed.


The command sudo rm -R /Users/username/Desktop/Skys/ since it does not contain the -i option, will recursively remove every file within the folder /Users/username/Desktop/skys/ I don't think the * wildcard option is even necessary here, since the -R will accomplish that.


Without the switch (the -R switch) you have confirm deletion of every single file and folder. With it, you don't.

Since, the -i option is not being used in the above command, the -R option has nothing to do with confirming. It's just that without it, the rm command will not work on a folder. (See EDITED)


For example, a very simple test: I create an untitled folder on the Desktop and try to rm it without the -R option.


*****$ rm /Users/*****/Desktop/untitled\ folder

rm: /Users/*****/Desktop/untitled folder: is a directory


Adding the -R option removes it immediately without complaint.


EDITED:


The OP wrote:
2) How do I avoid being asked if I wish to "override," for each file?

I think sudo rm -rf /Users/username/Desktop/Skys/


Would accomplish that. No?


Didn't know that without the -i the OP would have been asked for confirmation. Surprised to learn that.


Message was edited by: WZZZ

Mar 9, 2013 5:10 AM in response to zehutiman

Gents, thanks for the help.


I played around with your suggestions, and I had some success; but, most of the time was getting the following:


rm: /Volumes/My Book/wd smartware.swstor/8D730024-8085-11E2-A06A-D49A20E7E9B0/Desktop/My Documents/Pinnacle Studio/My Projects/MY MOVIE/OBJ/2BAD03C4: is a directory


When i tried to find subfolders, there weren't many, so I was back to square one; all these files that my WD dumped back onto my HD are from years ago when I created them on a PC.


Interestingly enough, I was able to trash many of the subfolders, never getting stopped by the "" file is locked, etc. -- that always stopped my progress yesterday.


And, if nothing more, I learned alot about the Terminal, so thanks. I was once pretty fluent with DOS, but that doesn't help me with the mac 🙂


I deleted approximately 190,000 files!

Mar 9, 2013 5:24 AM in response to zehutiman

Can you try


sudo rm -rf /Users/username/Desktop/Skys/


I think that should get everything without asking for any confirmation. If you need to know the path to use for that folder, just drag the folder you want to remove into terminal and then only copy it (don't hit return) in order to paste it into the above command. Then clear terminal for a new command. This will give you the proper path to insert after sudo rm -rf And, very important, there must be a space after -rf.


Or even easier, just enter sudo rm -rf leave a space and drag that folder into the terminal window.





Message was edited by: WZZZ

Mar 9, 2013 6:38 AM in response to Kurt Lang

No offense taken, and, likewise, I didn't mean any. I should have assumed you already know all this, but the ensuing comments weren't all that clear to me. In any case, I would have thought the OP could have been given sudo rm -rf right from the start. I should think that would have nuked everything, regardless of the locked uchg flag or Permissions? (Was reading too quickly at first and now I understand why, with the given command, the OP was being asked to confirm.) Was there some reason you didn't want to use that?

Mar 9, 2013 6:44 AM in response to WZZZ

In any case, I would have thought the OP could have been given sudo rm -rf right from the start. ... Was there some reason you didn't want to use that?

No, I just kind of brain glossed over those that more common use of switches. 😊 I do know r (or R) means recursive, and are equivalent, so entering it as uppercase is actually pointless.


I did completely forget that locked files will not be removed using the f switch (remove without confirmation). In order for the deletion to occur without skipping the locked items, you have to add the sudo command. So it should have been:


sudo rm -rf /path/*


Must have been a slow brain day for me yesterday. 😐 Fortunately, none of my previous commands were harmful. They just wouldn't finish removing everything.

Unix Executable File Deletion

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.