check if file exists on remote host with ssh

后端 未结 11 717
醉酒成梦
醉酒成梦 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:43

    On CentOS machine, the oneliner bash that worked for me was:

    if ssh  "stat  > /dev/null 2>&1"; then echo "file exists"; else echo "file doesnt exits"; fi
    

    It needed I/O redirection (as the top answer) as well as quotes around the command to be run on remote.

提交回复
热议问题