Program to delete locked, Trashed files

rharder

Do not read this sign.
An earlier thread hilited the "chflags" command that could unlock those pesky locked files that cannot be deleted. You can make a little program that will unlock the trashed files.

You'll need to make a shell script, so open up Terminal and make a file called something like <em>DeleteLockedFiles.command</em>. Be sure to end the filename with ".command" and have no spaces in the name. Make your file look like this:
Code:
#!/bin/sh
chflags -R nouchg ~/.Trash/*
chflags -R nouchg /Trash
rm -Rf ~/.Trash/*
rm -Rf /Trash/*

You'll then need to make sure the file can be executed so enter the following from the command prompt:
Code:
chmod +x <em>filename</em>

Now you can double-click the file in the Finder and delete whatever locked files are available to you in those two directories.

Enjoy, and thanks to all those who contributed the tips that made up this file.

-Rob
 
Would anyone be able to refresh my memory on how to create text files from the command line? I know it's pretty simple... it involves something like '>' and then typing the name of the file you want to call it, doesn't it?
 
The simplest way is:
cat > new_file_name

Then paste in your text.
Press control-D on a blank line to finish.
If you want to edit anything on a previous line, though, you're out of luck. You'll have to use a real editor for that.
 
The script listed above didn't work for me and I figured out why: I have several disk partitions (an extra one called "Scratch". You need to add commands to handle the trash folders on those partitions as well.

I also added a folder called Nuke into which I can throw troublesome files. My script looks like this:

#!/bin/sh
chflags -R nouchg ~/.Trash/*
chflags -R nouchg /Trash/*
chflags -R nouchg /Volumes/Scratch/Trash/*
chflags -R nouchg /Volumes/Scratch/Nuke/*
rm -Rf ~/.Trash/*
rm -Rf /Trash/*
rm -Rf /Volumes/Scratch/Trash/*
rm -Rf /Volumes/Scratch/Nuke/*
 
You mean you drag files to your Nuke folder to have them destroyed, for lack of a better word?

-Rob
 
Originally posted by rharder
You mean you drag files to your Nuke folder to have them destroyed, for lack of a better word?
No, sorry. I knew the Nuke folder would be confusing. I just find it usefull to have a folder to hold these locked files outside of the trash. I'm odd. Just ignore the Nuke thing.
 
I have used DropScript to create a couple of applications that can handle these locked files. One clears the locks and the other destroys them outright. To use them, you drag the file (or a folder holding the files) onto the app.

You can get the apps <a href="http://www.divnull.com/products.html#Drop">here</a>. Let me know if you have a problem with them.
 
I have also the problem with deleting locked files.
I want to be able to delete the without going to the terminal. Could somebody please help me. The best way would be if there could be a nice keyboard combo when you empty the trash. If there are some locked files or files you don«t got the permisions to it would prompt you with administrator password.

 
Back
Top