0


shell 查询文件是否存在

在 shell 中,可以使用

test

命令来查询文件是否存在。例如,要查询文件

/path/to/file

是否存在,可以使用以下命令:

test -e /path/to/file && echo "File exists" || echo "File does not exist"

如果文件存在,则会输出 "File exists";如果文件不存在,则会输出 "File does not exist"。

此外,也可以使用

[ -e /path/to/file ]

来查询文件是否存在。这两种方法都是等价的。

另外,还可以使用

ls

命令来查询文件是否存在。例如,要查询文件

/path/to/file

是否存在,可以使用以下命令:

ls /path/to/file &> /dev/null && echo"File exists" || echo"File does not exist"

如果文件存在,则会输出 "File exists";如果文件不存在,则会输出 "File does not exist"。

标签: linux 运维 服务器

本文转载自: https://blog.csdn.net/weixin_35750483/article/details/128870476
版权归原作者 李多田 所有, 如有侵权,请联系我们删除。

“shell 查询文件是否存在”的评论:

还没有评论