bash 如何使用bash检查服务器上是否存在文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8344859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:07:46 来源:igfitidea点击:
How to check if a file exists on a server with bash
提问by Rodrigo
Checking if a file exists on my computeris easy. But how about checking if this file exist on my server?
检查我的计算机上是否存在文件很容易。但是如何检查这个文件是否存在于我的服务器上?
If my file is:
如果我的文件是:
host@server:/path/to/my/file.txt
What do I need to do to check if it exists?
我需要做什么来检查它是否存在?
回答by jman
How about this?
这个怎么样?
ssh user@host 'if [ -f /path/to/my/file.txt ]; then echo yes; else echo no; fi'
回答by jaypal singh
Something like this could help -
这样的事情可能会有所帮助 -
ping -c 1 ipaddress && ssh user@host 'test -e /path/and/filename && echo exists'
回答by Tim Martens
ssh serverName
test -e
echo $?

