本教程操作环境: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怎么检查文件是否存在的详细内容。