2

The operating system is AIX. I have done multiple tests by running tail -f commands on text files. Then from another terminal session i try to delete the tailed file. I have always been successful to delete them and no problem occurred but i did not find any factual documentation saying that tail -f does not lock or prevent a file from being deleted. So i would like to know if there is such a formal information and if the tail command may lock or prevent a file from being deleted how can i reproduce the use case ?

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • On UNIX that is generally the case: You can unlink files from the filesystem that still have handles open. They will be physically deleted when the last handle closes. But I guess if you need factual documentation, you need to dig out something specific to AIX (or maybe the filesystem that it uses). If "Stackoverflow says so" is good enough, start here: https://stackoverflow.com/questions/22246397/why-file-is-accessible-after-deleting-in-unix – Thilo May 17 '18 at 12:48
  • 1
    Why is this tagged `linux`? Re-tagging as `AIX`. – Thilo May 17 '18 at 12:51
  • No, after you unlink the file, it does not show up anymore in the filesystem. And you can create a new file with the same name again. Depending on how `tail -f` is implemented, it will continue to show the old file or switch over to the new one or exit, not sure. – Thilo May 17 '18 at 13:07

2 Answers2

1

I suspect that the unlink() system call in AIX behaves similar enough to Linux that the first paragraph in this Linux man page adequately describes it:

unlink deletes a name from the filesystem. If that name was the last link to a file and no processes have the file open the file is deleted and the space it was using is made available for reuse.

When removing large log files that are being tailed (or written to), the disk space isn't free'd until all these processes close the file or terminate.

pcjr
  • 419
  • 2
  • 6
0

You can delete/move file while tail -f , but it will not create if deleted, have to create manually, hope this helps.

San
  • 226
  • 5
  • 14