check if file exists on remote host with ssh

后端 未结 11 840
醉酒成梦
醉酒成梦 2021-01-31 03:20

I would like to check if a certain file exists on the remote host. I tried this:

$ if [ ssh user@localhost -p 19999 -e /home/user/Dropbox/path/Research_and_Devel         


        
11条回答
  •  不要未来只要你来
    2021-01-31 03:44

    Can't get much simpler than this :)

    ssh host "test -e /path/to/file"
    if [ $? -eq 0 ]; then
        # your file exists
    fi
    

    As suggested by dimo414, this can be collapsed to:

    if ssh host "test -e /path/to/file"; then
        # your file exists
    fi
    

提交回复
热议问题