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.
Yeah, super annoying. In Linux you can rename or move it and the app using it doesn’t care.
Although having the option of listing the app using a file so I can kill the app would also be really nice to have. I’m sure Linux has something for that too, but I don’t know what it is.
That’s actually a thing, but I’m not entirely sure in which cases. Probably only for services and not apps, but I’ve done that myself where deleting a file was impossible, but renaming it and deleting it worked.
Maybe it’s only possible in certain cases, but I can tell you for certain it’s possible with running exe’s and loaded dll’s. I have a CMake step on Windows that does this rename hack so my builds don’t fail if I still have the app running.
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
Yes. On Linux/Unix you don’t delete the file, you just delete it’s name, which is merely a link to the actual file. That’s also the reason why the syscalls name is actually unlink and not delete. As soon as there’s nothing pointing to a file anymore, it is deleted.
As long as a process holds a file handle, there’s still a reference to said file, so it won’t be deleted. That saved me once, when I accidentally deleted a file I wanted to keep: As there still was some process keeping it alive, I could just go to /proc/[process id]/fd/[file descriptor id] and copy it to a safe location.
Good to know, and helps me understand code dealing with filesystems a little better. I’m curious how the kernel keeps track of it all, just a counter maybe?
On Linux/Unix you don’t delete the file, you just delete it’s name, which is merely a link to the actual file.
I don’t know how NTFS does it, but on FAT filesystems the directory table contains the filename along with all the other file metadata (access rights, creation date, size, etc). Only the list of sectors containing the actual data is separate. That means that you can’t have two filenames for the same file on FAT filesystems.
If you want to learn more about this, the data structure UNIX filesystems use, and FAT filesystems lack is called inode.
“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.
Yeah, super annoying. In Linux you can rename or move it and the app using it doesn’t care.
Although having the option of listing the app using a file so I can kill the app would also be really nice to have. I’m sure Linux has something for that too, but I don’t know what it is.
fuser
I can’t remember the other program that’ll do it.
But there’s another one that’ll list all the processes using a file.
Tip of my tongue fuck.
lsof | grep <filename>
That’s the one
You can use PowerToys on windows to see what app is using a particular file
That’s actually a thing, but I’m not entirely sure in which cases. Probably only for services and not apps, but I’ve done that myself where deleting a file was impossible, but renaming it and deleting it worked.
Maybe it’s only possible in certain cases, but I can tell you for certain it’s possible with running exe’s and loaded dll’s. I have a CMake step on Windows that does this rename hack so my builds don’t fail if I still have the app running.
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?
Yes. On Linux/Unix you don’t delete the file, you just delete it’s name, which is merely a link to the actual file. That’s also the reason why the syscalls name is actually
unlink
and notdelete
. As soon as there’s nothing pointing to a file anymore, it is deleted.As long as a process holds a file handle, there’s still a reference to said file, so it won’t be deleted. That saved me once, when I accidentally deleted a file I wanted to keep: As there still was some process keeping it alive, I could just go to
/proc/[process id]/fd/[file descriptor id]
and copy it to a safe location.Good to know, and helps me understand code dealing with filesystems a little better. I’m curious how the kernel keeps track of it all, just a counter maybe?
Is that different on other systems?
I don’t know how NTFS does it, but on FAT filesystems the directory table contains the filename along with all the other file metadata (access rights, creation date, size, etc). Only the list of sectors containing the actual data is separate. That means that you can’t have two filenames for the same file on FAT filesystems.
If you want to learn more about this, the data structure UNIX filesystems use, and FAT filesystems lack is called inode.