本教程操作环境:linux5.9.8系统、Dell G3电脑。

Linux检查文件是否存在

1. test命令

它经常用来测试条件表达式,用到的命令为test -e <文件>

2. 用bash shell检查

假设我们有文件目录/home/benben/go_project和文件/home/benben/go_project/test.txt,下面我们用bash shell命令来检测下这个目录和文件是否存在。

  • 检查目录,执行命令[-d /home/benben/go_project ] && echo "found" || echo "not found"或者[-d ./go_project ] && echo "found" || echo "not found"
  • 检查文件,执行命令[-f /home/benben/go_project/test.txt ] && echo "found" || echo "not found"或者[-f ./test.txt ] && echo "found" || echo "not found"

相关推荐:《Linux视频教程》

以上就是linux怎么检查文件是否存在的详细内容,更多请关注悠悠之家其它相关文章!

点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部