在 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"。
本文发布于:2024-01-29 12:24:14,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170650225715259.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |