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
In addition to the answers above, there's the shorthand way to do it:
ssh -q $HOST [[ -f $FILE_PATH ]] && echo "File exists" || echo "File does not exist";
-q
is quiet mode, it will suppress warnings and messages.
As @Mat mentioned, one advantage of testing like this is that you can easily swap out the -f
for any test operator you like: -nt
, -d
, -s
etc...
Test Operators: http://tldp.org/LDP/abs/html/fto.html