7

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

  ssh [email protected] echo "hello gourav how are you">/g.txt

enter image description here

but no data in g.txt

3
  • 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, 2016 at 7:15
  • 2
    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, 2016 at 7:48
  • 2
    btw, your command will write the output of your ssh command to /g.txt on the local system. try ssh [email protected] '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, 2016 at 7:51

2 Answers 2

10

Add single-quotes around the remote command:

$ ssh [email protected] 'echo "hello gourav how are you" >> /g.txt'

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

2

Maybe

$ 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 .