Trist
Trist

Reputation: 1366

Is it possible to copy a portion of a file using SSH?

I want to download a the end of a log file from my dev machine at home to my local machine, the last 1MB. Is this possible?

Upvotes: 1

Views: 98

Answers (2)

telina
telina

Reputation: 166

Well you could get the last 1MB from the file and save it as another file. Then scp that file to your local machine. You can extract the data by using:

tail -c $(( 1024*1024 )) your_file > target_file

(source: https://unix.stackexchange.com/questions/32941/use-dd-to-cut-file-end-part)

Upvotes: 1

Marcin Krasowski
Marcin Krasowski

Reputation: 686

Yes it is possible.

Run it on your dev machine

tail -c 1048576 logfile.log  | ssh  user@remotemachine "cat > local_file_name"

Upvotes: 1

Related Questions