Linux 中是否可以在不向硬盘发出请求的情况下检查文件是否存在?

发布于 2024-12-27 11:14:25 字数 429 浏览 7 评论 0原文

这是我在这里发表的第一篇文章。

我想检查文件是否存在但不使用硬盘。例如看看这段代码:

<?php
$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}
?>

据我所知 ext4 是日志文件系统。这是否意味着脚本可以通过查看日志(即主内存)来检查文件是否存在,而无需接触硬盘?

感谢您抽出时间。

UPD。

是否有任何文件系统可以将硬盘的日志保留在主内存中,以便可以在不访问硬盘的情况下完成文件存在的操作?

This is my first post here.

I want to check if a file exists but without using hard disk. For example look at this code:

<?php
$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}
?>

As far as I know ext4 is journaling file system. Does it mean that the script can check if the file exists by looking into it journal, that is main memory without touching hard disk?

Thanks for your time.

UPD.

Is there any filesystem that keeps hard disk's journal in main memory, so that file exist's operation can be done without accessing the hard disk?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷情妓 2025-01-03 11:14:25

日志 (a) 存在于磁盘上,并且 (b) 完全解决了另一个问题。

当你进行这样的调用时,内核将询问文件系统。如果文件结构的必要块缓存在内存中,则它不会访问磁盘。如果不是,它也会的。

The journal (a) lives on the disk, and (b) solves another problem entirely.

When you make a call like this, the kernel will ask the file system. If the necessary blocks of the file structure are cached in memory, it won't access the disk. If they're not, it will.

云之铃。 2025-01-03 11:14:25

不会。文件系统日志不会完全保存在内存中,并且在任何情况下都不包含文件系统中的所有元数据。它仅用作一种工具,可以更快地从不干净的卸载中恢复。

No. A filesystem journal is not kept entirely in memory, and in any event does not contain all metadata in the file system. It's solely used as a tool to make recovery from an unclean unmount faster.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文