Cannot delete file in OS X

5

2

I have a file in trash, and I cannot delete it. Before you ask me to STFW, no, the file is not locked :-/

The file is a symbolic link to nothing (target is deleted). Here is the output of ls -lO on that file:

lrwxrwxrwx  1 1000  _lpoperator  uappnd,nodump,opaque,compressed 22 Apr  3  2009 fly.pdf -> stuff.pdf

The output of rm is

$ sudo rm fly.pdf
rm: fly.pdf: No such file or directory

However the file does exist, which can be confirmed by ls or by opening trash in Finder. If I empty trash using the menu, it plays that sound and nothing happens. If I try securely empty trash, it complains about not having permission. So I'm stuck... Any suggestion?

BTW, the file in question is in the trash of a volume called "Shared", which is not the boot volume.

UPDATE: @bug pointed out that this may be caused by my link being opaque, and suggested to delete it in a chroot jail. I tried that, and chroot gave me a segmentation fault. Here is what I did for that: I enabled root following this, and followed @bug's answer and this to create the chroot jail. Chroot gave me

# chroot /Volumes/Shared
Segmentation fault: 11

MetroWind

Posted 2012-02-01T00:55:18.607

Reputation: 511

Just tried it within linux, created a symlink, removed the target, no complaints when deleting the link afterwards. strange problem :/ – Baarn – 2012-02-01T01:15:19.767

Exactly. In my mind sym links are just regular files, so I'm kinda confused... – MetroWind – 2012-02-01T01:17:48.500

@Darksair I think if you use rm -rf it will probably also work. :) – tftd – 2012-02-02T16:44:30.320

@TheDevil: No I tried, and it didn't :-, which was pretty weird... – MetroWind – 2012-02-02T16:45:38.300

Answers

3

Chflags has an option -h to not follow links (which I constantly ignored...).

# chflags -h noopaque,nouappnd,dump fly.pdf

And then empty trash.

MetroWind

Posted 2012-02-01T00:55:18.607

Reputation: 511

How would a file get in this state on its own? – Charlie – 2014-03-14T14:13:01.170

0

Try dragging the file to the desktop, open a Terminal window, enter your sudo rm -R then drag the file to the Terminal window.

I've seen this work before and I'd use the -R just in case the file is really a package.

afragen

Posted 2012-02-01T00:55:18.607

Reputation: 101

Here is what happens when I drag that file to anywhere: if the destination is on the same volume as the file in trash, Finder wants to move it. It asks me for password, and then nothing happens (file not moved); if the destination is on a different volume, Finder wants to copy, and it does that. I can delete the newly copied file, but the file in trash remains. And rm -R produces the same output as without the -R. – MetroWind – 2012-02-01T01:47:17.230

Try this sudo rm -ri ~/.Trash then logout and login again. – afragen – 2012-02-01T01:53:28.817

Thanks for the idea. However it doesn't seem to fix it :-( The file in question is in the trash of a volume called "Shared", so I guess I should replace ~/.Trash with /Volumes/Shared/.Trashes, right? Here is the output: http://pastie.org/3292919 (sorry for an external link, I cannot have multi-line code here..., and yes, my UID is 1001 :-p)

– MetroWind – 2012-02-01T02:01:37.870

0

Have you tried unlink? ...

It might be that the symlink is being bypassed because it's opaque. Try removing it from the context of its containing filesystem by setting up a chroot jail:

cd /Volumes/Shared
mkdir bin
sudo cp /bin/zsh /bin/rm ./bin
chroot /Volumes/Shared
cd .Trashes/1001/abroad
sudo rm fly.pdf
sudo rm -r /bin

bug

Posted 2012-02-01T00:55:18.607

Reputation: 161

Thank you for the suggestion. I tried it, and it produces the same output: unlink: fly.pdf: No such file or directory... – MetroWind – 2012-02-01T01:51:55.040

Wait a minute...that's an opaque link! Is your home folder on a different drive/partition than your boot volume? – bug – 2012-02-01T02:25:53.673

The file in question is in the trash of a volume called "Shared", which is not the boot volume, and my home is not on it. What's an opaque link? I tried to remove the opaque flag with chflags, but I couldn't. – MetroWind – 2012-02-01T02:27:40.147

Symlinks marked as opaque act like ordinary files when the filesystem they're on is mounted within another filesystem. I'll edit with a possible solution... – bug – 2012-02-01T02:36:43.993

Chroot complained about not being able to find /bin/zsh, which is my login shell. I also tried sudo chroot -u root /Volumes/Shared rm .Trashes/1001/abroad/fly.pdf, and it complained the same thing about rm. Should I somehow link my /bin and /usr/bin into /Volumes/Shared first? – MetroWind – 2012-02-01T02:52:56.110

Oh, right, how silly of me. The easiest way to do this is actually to just copy the tools you need, since symlinks can't reach outside of a chroot jail. Editing again! – bug – 2012-02-01T03:00:19.940

Ok... I failed. I copied everything including libraries, and chroot gave me a segmentation fault :-<. STFW-ed but couldn't find anything useful... I'll update my post with some detail. – MetroWind – 2012-02-01T03:26:49.780

I must admit I haven't done anything serious with chroot, and I'm not at a machine I have root access to experiment with myself. I'm still intrigued by this problem, though! – bug – 2012-02-01T03:33:40.677

0

Have you tried rm -rf * while in the trash can not sure if it'l work on your link but worth a try its what I use when files in the trash refuse to delete with empty trash

mcgyvrfan121

Posted 2012-02-01T00:55:18.607

Reputation: 92

Thank you for your answer. I tried it, but it still complains about no such file blabla... – MetroWind – 2012-02-01T03:33:57.043