Deleting Files
Deleting Files
Deleting Files
"Hey Linux, can you just delete this file please?"
"Sure thing bud, a program is using it, it's ok, I will just unlink the inode anyway, the program can still access it until it closes the file"
This is honestly one of my favorite features of the linux filesystem. As a dev it makes things like replacing and hot-reloading plugins way easier.
It turns out you can kind of get the same functionality on Windows if you rename the open file and place the new one with the original name, but it's a bit of a hack.
Windows won't let you rename a file that's being used either.
It turns out you can kind of get the same functionality on Windows if you rename the open file and place the new one with the original name, but it's a bit of a hack.
Only if you don't have OneDrive working. In that case, you have to wait for it to sync or it won't go through.
Anytime I have an issue at work where I can't change or delete a file, it's a 50/50 split between Excel and OneDrive being the cause
the mpv player does that too for the cache folder. It's configurable and documented
Hmm. So are the blocks freed up for overwriting on file close, then?
In case anyone is interested, there's a powertoy called file locksmith that will show what's using it and let you kill it: https://learn.microsoft.com/en-us/windows/powertoys/file-locksmith
"Time to see who's stopping me from deleting this file... svchost??? Goddamn it!"
just kill it
Probably the indexing service, it's always the indexing service.
Well, it could be an executable disguising itself as svchost. Pretty common for malware or video game cheats to name their executables svchost.exe to hide from anti-virus/anticheat
I'm in this picture and I don't like it. I was trying to diagnose a prod server crashing this very Wednesday and seeing the lines of svchost.exe is so fucking maddening... I'm glad ProcessExplorer was there to give some useful fucking info, at least.
Powertoys seems to be the only thing keeping windows somewhat usable, I have no idea why they don't include it in the build.
I discovered powertoys only recently, and it's a pretty cool set of tools. From color picker, tiling window manager to regex file renames or copy/paste tools, it has a lot of QoL features.
If you have to be on windows, i.e due ro work, I recommend not sleeping on it.
Now the question is if I can install it on my work computer without IT getting pissy
Why isn't this in their OS instead of unwanted AI
The performance view thing that comes with windows also allows searching for file handles but it's not very user friendly. Also not possible without admin rights if I remember correctly
You can use the built-in tool resmon.exe to do the same
back in the XP days, I used a software called "Unlocker" just for this problem. It probably still exists, I don't know, because since Windows 7, the easiest way to find out what process locks a file is to open Resource Monitor (Start search: resmon) and on the CPU tab, using the "Associated handles" list, you can search for the file name and see the process in question (and kill it).
So yeah, Resource Monitor is a useful tool on Windows.
There's a collection of free little utilities called Microsoft PowerToys, including the file unlocker thing. Why would they not include these into base kit Windows is beyond me.
not including PowerToys inside basic package is a fucking choice. Win11 is literally unusable without it in many aspects.
I feel like it's a testing ground for new features for them, but not sure why some aren't yet integrated. Best guess: the PowerToys team has less red tape and checks to go through than the Windows team to allow for faster iteration, but that means that integrating the features wouldn't be just the click of a button since they'd have to adapt it to fit the Windows style. But this is just a wild guess.
Why would they not include these into base kit Windows is beyond me.
Some of them felt a bit buggy when I last time used Windows, maybe they aren't fully ready to ship (like Samsung's Good Lock apps?). And most features didn't do quite what I imagined it to do, but that's probably a "me problem".
Because they want to include things with ads now.
The bugs and horribly slow hardware that caused the locks in NT/XP have slowly disappeared, by win 10, I rarely had any files I couldn't delete if I, worst case, made explorer reload. It used to happent o be every other day in the late 90s
Actually on windows 7 I found out how to get which process is locking one file.
You open the resources manager (task manager has a link to it)
Inside you can see how much each process uses on cpu, network and stuff.
And there is a tab where all used files for each process is listed. You can search for specific files.
Yeah there's a Microsoft sysinternals utility where you can drag a file into to fetch that info for you.
Makes zero sense there isn't a >Details in the error notification that tells you the damned process in Windows.
Not only that, but you can actually search all active processes to see which handles they keep references to. Just search the name of your file and it will show you the processes which use it
Right? I get that it's "alarming" to users to see weird stuff, but just hide it under a little expandable thing.
Well duh, Microsoft respects privacy
Me: I've close the program, now please delete the file
Windows: ok, give me half an hour, it's not easy to delete 500 MB
... And the file is back open somehow. Only now the program throws an error when Windows launches, yet still leeches resources.
Here's an incredibly animated chart of how poorly I'm doing. Note that I seem to throttle the operation every 5 seconds or so.
Explanation? No, no. Haha. No. We don't do anything like that.
Oh you think because you closed the program it's released the file? Think again chump!
Hey Linux, sudo rm -rf /
sigh I'm surrounded by idiots.
"Sure thing boss" you fucking moron.
I did that once on my Macbook Air a while ago by mistake. The system's completely fucked and I had to reinstall it.
"Hey Microsoft, i want to safely remove this hard drive so i don't corrupt my data"
"Nope, it's being used by another program"
"I shut down every program, nothing is open, please eject my Hard drive"
"Nope, It's being used by another program"
**Proceed to just yank the cord out of the computer and flick off the screen.
Process explorer, threads and handles tool, search the file name.
Kill the process or at least you know who now.
Some Windows apps do handle it properly. For example, if you have an archive open in 7-zip and try to delete it, Windows Explorer should correctly tell you that it's open in 7-Zip. I'm not sure why it doesn't work that way for all apps.
Windows doesn't even tell you if Explorer itself has a folder open... how the hell does 7-Zip do it?
Shout out to my MVP Notepad++ telling the file has been deleted by another process and letting me decide if I want to keep it open anyway. Fantastic feature. I literally could not do my job without its ability to leave log files alone so they can be written to while I'm still browsing them.
I like Notepad++. It can handle anything you throw at it.
I switched to Linux (Fedora with KDE) and I like KWrite for similar reasons.
Different user
Same thing whenever I try to unplug a USB, Win10, on my desktop. There have been times where I plugged in one, opened a file, closed it within seconds, did the safely remove thing, and then I get the whole quick song and dance about some program still using it because of how sluggish it is to actually end what's using it in the background.
Also, my phone's keyboard software was bugging out and replaced "song" with "incest" for no discernable and wanted to replace the next word "and" with "rape incest". Not related, but fuck Gboard and that weird glitch where it'll replace words with random shit for no reason.
There are good keyboard apps on F-Droid...
I have yet to find one that can properly do Chinese and/or Japanese and I'm too dumb to make one. That's the only thing holding me back.
OK, WTAF on those word replacements. I'd be freaking out about malware.
That's what happens when they train it on bad porn sites.
I cannot remember what it's done in the past, but I've definitely had much more tame occurrences of this. Same with holding the delete key and having the thing think that the first letter of a word doesn't exist from time to time.
Probably a couple of minor bugs that g••gle doesn't care to fix.
Reason 3756 why Windows is slopware
Linux fuser for the win
I've never fused Linux before, is it difficult?
Or stay with the basics and use lsof.
Either way, not coming with that tool by default and forcing every usage of the file to lock it is a really stupid pair of mistakes.
"Hey can I rent this apartment?"
"Let me check... Seems like it's already occupied"
"Omg who is occupying it?"
"Let me print out their name and contact details for you"
Ah yes, great analogy. My computer with the operating system I installed and the files I own and want to modify certainly is the same as going to some strangers apartment and trying to buy it.
We don't want to invade the privacy of... the software... right?
your printer works?!
Touché
Bad analogy.
This would be more like the property management having a record of what apartments are rented, and having a second list of who is renting apartments (but not which one), and the landlord wanting to know who is renting apartment 420 so they can draw up eviction papers.
The user probably wasn't running as admin (elevated) while deleting the file, so as far as the system knows, he may not be allowed to know which process is accessing the file.
That only applies in this situation if the requestor is also the owner of the building, as in the OP it is assumed the requestor owns the computer.
(On a multi-user system it is unlikely running Windows.)
It's one of the things that made me prefer using Linux a long long time ago. It's nice to be able to rename, move, and delete files while they are used.
Mac does the same thing (as others have said) and you can at least sudo lsof
and find it, but somehow filesystem access now is worse than Windows 95 era Excel spreadsheet file handles that never worked.
Here's what an operating system is peeps: Something that handles files and programs that live on top of it. That's it.
How is it none of them can't do their basic function anymore?
Same command works on Linux. Its a real saver sometimes.
You can also specify a path.
Files, hardware / peripherals and programs. The distinction can get a bit blurry what with drivers and the fact that Linux exposes most of the hardware via the filesystem.
Same on Mac except it’s an external drive that some mystery program is using.
same with my kobo. It VERY rarely ejects it. It will just say "unable to eject. force eject?"
On macos, that program is sometimes just Finder trying to calculate folder size
I’ve never seen that before. Finder is usually smart enough to close any of its windows showing its files/folders before unmounting.
omg
Meanwhile on Linux: /boot successfully deleted
I once deleted /dev/null Do not recommend. You’d be surprised how much of the system needs it.
I once deleted /dev/urandom. I didn't want uncertainty in my life.
Well, I was on for a surprise.
How? I could've sworn it wasn't even a "real" file. I thought the file system just had special rules for interacting with that name.