Example: I log on my laptop machine (Ubuntu 14.04) via ssh and I need to make a .log file of some command output and than transfer it to my desktop machine. The command has -o option to redirect the output to a file. I could than just copy the file with scp command.

The question is: Can redirect the output directly to my machine, without the need to first make a file on laptop and than transfering it with scp?

Both machines use Ubuntu 14.

  • 2
    So... from Computer A you want to log into Computer B, and log output to Computer A?
    – Wilf
    May 20, 2017 at 19:23
  • That is correct. May 20, 2017 at 19:32

3 Answers 3


Depend on your command you can do something like this:

ssh user@machine command > log

the log will be saved in your machine, a real example:

ssh [email protected] ls > log

If your command does not supports outputs to stdout then run it like this:

ssh [email protected] "command -o output; cat output"  > log
  • 4
    A slightly better way would be to use the tee command, so that you'd also see the output on the screen. For instance: ssh user@machine command | tee log
    – boardrider
    Aug 6, 2019 at 17:21

If you want to see what are typing and output at the same time - try it:

ssh user@host 2>&1 | tee ssh-session.log

I have a similar requirement except I need to be able to "turn on" the output to local pipe/process after logging in and setting things up. I don't want all the login text getting put into the local file/pipe.

Basically, I need to ngrep from a remote machine, and pipe the output to a local test script that checks the network traffic for certain things. Also, when the test is running, I don't want to mix outputs which would happen if I used tee. I'd see the output from the ngrep, PLUS the output from the test which would be confusing. Also, directly redirecting to a file > filename would mean the login process would all be redirected to the file and I wouldn't be able to see what was going on.

This is for a demo so it has to be clear to the audience what is going on.

ssh yo@remote_box.
sudo ngrep | local_application

Bzzzt!!! Wrong! Doesn't work that way

If it weren't for the need for sudo with ngrep, this wouldn't be a problem. I can't really chmod a+s ngrep without bringing devops down on my case hard.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .