check if file exists on remote host with ssh

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

    ssh -q $HOST [[ -f $FILE_PATH ]] && echo "File exists"
    

    The above will run the echo command on the machine you're running the ssh command from. To get the remote server to run the command:

    ssh -q $HOST "[[ ! -f $FILE_PATH ]] && touch $FILE_PATH"
    

提交回复
热议问题