1

Checking if a file exists on my computer is easy. But how about checking if this file exist on my server?

If my file is:

host@server:/path/to/my/file.txt

What do I need to do to check if it exists?

Community
  • 1
  • 1
Rodrigo
  • 11,909
  • 23
  • 68
  • 101

3 Answers3

14

How about this?

ssh user@host 'if [ -f /path/to/my/file.txt ]; then echo yes; else echo no; fi'
jman
  • 11,334
  • 5
  • 39
  • 61
  • I found some thing like this, but this work very fine. I found my error. I use ssh user@host:/path/to/my/ 'if [ -f file.txt ]; ... This not work :) – Rodrigo Dec 01 '11 at 16:52
3

Something like this could help -

ping -c 1 ipaddress && ssh user@host 'test -e /path/and/filename && echo exists'
jaypal singh
  • 74,723
  • 23
  • 102
  • 147
0
ssh serverName

test -e
echo $?
Timothy Martens
  • 678
  • 4
  • 17