Question: How do I know if a file or files are in deferred state using bash? Is there a way to detect this?

sample:

*when saving a file, kernel cache the file and not yet written on the disk. this is the D state or deferred state. when its deferred state, when you check the file like `php -r "var_dump(file_exists($filename));"`, the kernel will respond, yep the file is there. but in reality, the file wasn't written on the disk yet. and when the server got restarted, the file is gone.*

the event happened to us and i want to prevent it or create a monitoring tool that detects it and notify us so we can copy the files on other server before restarting it.

Answer: 
I think you are looking at a wrong "problem". When system is properly restarted, the shutdown process will make sure that all data is written to permanent storage.

So, the problem here is that restart is done in wrong way, which causes data loss. You need to change your restart to use `shutdown -r now` or similar command.
i think i found the tool. not perfect of what i am looking for, but i'll make it work.

its a `vmtouch` command, can be found at <https://github.com/hoytech/vmtouch>

thanks.