Linux – Check to see if a directory exists remotely (shell script)

bashdirectorylinuxremote

Is there a way to see if a directory exists on a remote server?

Perhaps there's a better way, but I'm writing an application deployment script, and I want to create a directory on a remote server if the directory doesn't exist to place the files.

Thanks in advance!

Best Answer

You can use ssh to call a programme on the remote host, test tests for certain conditions.

if [[ `ssh user@example.com test -d /path/to/my/directory && echo exists` ]] ; then
    # put code in here
fi