Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to do a simple inline style SSH command, for example:

ssh { cd foo/bar && rm *.foobar }
share|improve this question
up vote 24 down vote accepted

Should you want to execute cd foo/bar && rm *.foobar on the remote machine, simply do

ssh  'cd foo/bar && rm *.foobar'

and see man ssh...

ssh [-1246AaCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec] [-D
[bind_address:]port] [-e escape_char] [-F configfile]
[-i identity_file] [-L   [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-R
[bind_address:]port:host:hostport] [-S ctl_path] [-w tunnel:tunnel
[user@]hostname [command]

The parts you want:

ssh [user@]hostname [command]
share|improve this answer
Worth noting that you can pipe STDIN and STDOUT using this method as well- just the other day I made a HD image of a remote machine using DD over ssh. – crazy2be Aug 5 '11 at 2:54

style 1: ssh user@host 'embedded command'

style 2: ssh user@host " $(cat cmd.txt) "
cmd.txt is file that contain your remote command which is locate at your local machine

share|improve this answer

yes it is :

ssh 'cd foo/bar && rm *.foobar '
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.