Advertisements

Category Archives: Trash

how to fix a ‘file in use’ problem

script


Sometimes when you try to eject a disk, unmount a volume or empty the Trash, you get caught out by some app or process that’s using the file and won’t release it. This is usually signalled by a warning dialog telling you the said file is “in use” or is “locked”.

Part of the difficulty of dealing with this problem is that the warning message may not actually tell you which process is hanging on to the file or give you any options on what to do next to solve the problem.

Sounds like a job for a quick bit of bash scripting then!

We’ll write a one-stop script that leverages a few different command line utilities to help us out here. First, our script will call fuser to report the processes using the file. Then it’ll use ps to get those processes’ ID numbers and, after asking us to confirm what we want to do, it’ll feed those to the kill command to quit them and release the file.

The whole script is available here.

To use it, save the script as a plain text file in the root of your home folder (alternatively, save it in an /sbin folder. You can do echo $PATH on the command line to get a list of places you can save it to if you’re not sure).

Secondly, give it executable permissions with

chmod +x <script name>

When the problem strikes, jump into Terminal and type

./<script name>

Add a space, then type or drag the file from Finder onto the command line and hit ‘return’ if necessary. The script will do the rest.

In the image below, I first gave my script (named ‘releaseFile’) exec permissions. Then I called it and chose ‘a’ to quit all processes holding on to the file (in this case, only one process).



fuser



Hope that helps. Enjoy! 🙂


Advertisements

‘delete’ doesn’t send files to Trash

Image

 

If you find deleting a file deletes it immediately without sending it to the Trash first, you may need to fix permisssions on your Trash folder. 

Open Terminal (Applications > Utilities > Terminal.app) and type

ls -alF

Scroll up if necessary to the beginning of the list and you should see a couple of folders whose names begin with a dot.

.Trash
.Trashes

Ignore .Trashes, but look at the permissions on .Trash, they should read like this (also see the pic above):

drwx- – – – – – <your_username> staff (size) (date) .Trash/

Ignore the numbers, but if the permissions are different or the username is not your account username, then do the following:

At the Terminal command prompt, type the following, replacing ‘your_username’ with (yep, you guessed it…) your username.

sudo chown -R your_username .Trash

For example, if my user name is ‘SnowLpd’ I would type
sudo chown -R SnowLpd .Trash

Then press ‘Return’. You will need to enter your password, which will be invisible when you type it (so type carefully). Now go and test your ‘delete’ function to see if the problem is cured. 🙂 

 

Related Posts

why does Trash ask for a password? (Permissions Part 1)

 

 

how to remove a boot.efi file from Trash



Click on the Trash can on the Dock, hold down the ‘option’ key and click the ‘Empty’ button over there on the left side of the window. If this doesn’t do it, the file may be in the .Trash folder of your Time Machine (TM) or some other disk.

To find out if that’s so, follow this procedure:
 
1. Open Terminal.app, copy and paste the following command into the Terminal window
 
defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder
 
Then press ‘Return’.
 
2. Open a Finder window. Navigate to the TM disk starting from its icon in  the left hand column. You should see some greyed out folders called .Trash and .Trashes. Click on these and have a look for the boot.efi file that we’re hunting down.
  
To remove the boot.efi file from the hidden trash, try the following:
 
3. Go back to Terminal and copy and paste the following:
 
sudo rm -rf
 
Do NOT press ‘Return’. Instead, press the Spacebar once, then use your cursor to drag the boot.efi file from the hidden folder in Step 2 and drop it in the Terminal window. Now press ‘Return’. You will be asked for an administrator password and given a warning which you can ignore. Type in your password, but notice that your typing will be invisible, so type carefully.

Press ‘Return’.
 
4. If you typed your password incorrectly, repeat step 3. If you typed it correctly, hopefully, your Trash is empty. 🙂
 
5. The last thing is to hide all the hidden files again, so copy and paste this:
 
defaults write com.apple.finder AppleShowAllFiles FALSE; killall Finder
 
Then press ‘Return’.
 
You can close Terminal now.
 
 
Good luck!

how to fix permissions (Permissions Pt 2)


(This post continues from here on file permission problems.)

Did you know there are two levels of permissions on your mac? User level and system level. Most discussions of fixing permissions only discuss the latter, but you may also need to fix the former (also sometimes called ‘ACLs’) for some problems caused by upgrading Lion on top of Snow Leopard.

4. System Level Permissions
You can safely repair your system level permissions at any time, and doing it once in a while is a good maintenance activity even if you’re not experiencing any problems. It’s also the first thing to do as soon as you notice any problems with apps launching, file access problems, or your computer seems to be running unusually slow.

How to do it:
— 1. Go to Applications > Utilities > Disk Utility.app and double click the app to open it.

— 2. Click your HDD icon in the left column (if you have more than one, click the one that contains your startup disk).

— 3. If it is not already selected, click on the ‘First Aid’ tab. Choose the ‘Repair Disk Permissions’ button near the bottom of the window (see the larger of the two windows in the screenshot above).

— 4. Wait for the process to finish (it could take ten minutes or more), then quit Disk Utility. You can ignore most of the error messages that appear unless they’re in red.

5. User Level Permissions (ACLs)
These permissions apply only to your ‘Home’ folder and its contents, and if you have more than one user you will need to do this procedure for any user experiencing a problem. However, unlike system level permissions, repairing ACLs isn’t something you should do unless there is a specific issue to be solved. Problems that this repair might help with include permission conflicts inherited from an earlier Snow Leopard or Leopard installation, such as Finder always asking for your password when you try to delete, move or copy a file.

To reset the ACLs in Lion: (To reset the ACLs in Leopard/Snow Leopard have a look here.)

— 1. Remove the current ACLs by opening Terminal.app (Applications > Utilities > Terminal.app) and copy and pasting this command:

sudo chmod -RN ~

Press return. You’ll be asked for your password. Notice that when you type it in you won’t see anything on the screen. Press return again. If you get an error message, you probably didn’t type in your password correctly. Repeat this step till its accepted. It will take some time to complete. Then paste this command into Terminal also:

sudo chown -R `id -un` ~

and press return. Enter your password again if necessary.

— 2. Press the Power button on the computer and choose ‘Restart’. When the screen goes blank, hold down the ‘command’ and ‘R’ keys on the keyboard until you hear the start up chime. In the menu bar at the top, choose Utilities > Terminal

— 3. At the Terminal prompt type

resetpassword

Then hit ‘Return’

— 4. Forget about resetting your password; what you’re looking for is your hard disk icon at the top. Hit that, and then from the drop-down menu select your user account.

— 5. Go to the bottom of the dialogue window – leaving all password fields blank – and choose ‘Reset’ under ‘Reset Home Folder Permissions and ACLs’ (see the smaller of the two windows in the screenshot above, inside the red dotted line).

— 6. When the process finishes, quit everything and restart your Mac. 🙂


Related Posts
How to Troubleshoot Your Mac with FT2
can’t create kext cache error
FastTasks – download the free OS X utility app from Applehelpwriter


why does Trash ask for a password? (Permissions Pt 1)



There are several reasons why Trash may ask for your password. Let’s deal with the obvious ones first:

1. FileVault is turned on
Solution: either turn FileVault off, or put up with the behaviour.

2. If you are using an account with ‘Parental Controls’ enabled, the person who set up your account may have denied you permission to delete, modify or move some or all files.
Solution: Speak to mom!

If 1 and 2, aren’t your problem, then you may have some permissions errors.

3. Check Permissions on .Trash
— 1. Open a Terminal window (Applications >Utilities > Terminal.app) and check the permissions by typing/pasting in the following:

ls -al

You should end up with a long list, among which will be the permissions for your .Trash folder. Mine looks like this:

drwx—— 2 SnowLpd staff 68 29 Nov 15:33 .Trash

— 2. What’s important here that the name after the series of ‘drwx’ letters is the same as your user name (my user name, as you can see, is ‘SnowLpd’). If it is, then ignore the rest of this post and go to the post Permissions Pt2.

If the name is not the same, then you need to type this command into Terminal:

sudo chown -R your_username .Trash

Where you replace your_username with (surprise…) your user name, which is also the name of your home folder (note there’s a space both before and after your_username). Thus, for example, if in the previous step it said ‘root’ instead of my username, then I’d type in ‘sudo chown -R SnowLpd .Trash’.

—3. Now press ‘Return’. You will be prompted for your admin password. Type it in, but notice that you won’t see anything as you type, so type carefully. Hit ‘Return’ again. You should be returned to the Terminal prompt pretty quickly. Quit Terminal.app and see if your problems are solved.

4. If your .Trash permissions were OK, then you may need to fix either system permissions or ACL permissions. To do that, go to the next post.



Related Posts
how to fix permissions (Permissions Pt 2)
‘delete’ doesn’t send files to Trash

%d bloggers like this: