I want to append a file that is already present on the server through ssh i m try:

  ssh root@ echo "hello gourav how are you">/g.txt

enter image description here

but no data in g.txt

closed as unclear what you're asking by Anthon, Jakuje, cuonglm, dr01, Archemar Feb 28 '16 at 14:04

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Do you want to append to a file, or do you want to append the file with the name hello pourav how are you to the file g.txt. Your question title suggests that you want to append an file to some other file, your code suggests another. Please update your question to make the title match your problem unambiguously. – Anthon Feb 28 '16 at 7:15
  • 1
    don't post screenshots when text will do. just cut and paste the text from the terminal. screenshots are a) non-searchable, b) unreadable on monitors with higher/different resolution to yours. – cas Feb 28 '16 at 7:48
  • 1
    btw, your command will write the output of your ssh command to /g.txt on the local system. try ssh root@ 'echo "hello gourav how are you" > /g.txt' - note that the entire command (including the redirection) to be executed by the remote host via ssh is enclosed in single quotes. – cas Feb 28 '16 at 7:51

Add single-quotes around the remote command:

$ ssh root@ 'echo "hello gourav how are you" >> /g.txt'

EDIT: yes, as @Andrew Miloradovsky noted, use >> rather than > for appending rather than writing anew.



$ ssh user@host "cat remote-file-1 >> remote-file-2"

assuming the files are at user's home

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