Prometheus Prometheus - 1 month ago 5x
Bash Question

Read first n lines of a huge file from remote server using bash command

I want to read first n lines of a huge file which resides at a different server. I was using scp to copy the file:

sshpass -p $password scp $username@$server:$path_to_file "$content_file"

But, I just want first few lines from the file. If the file is huge, I end-up downloading the whole file first and then I read first n lines using
command. I tried replacing
but that did not help me. Please suggest the right way.

gzh gzh

you can use the following command to output remote result to local.

ssh hostA head srcfile > destfile

or use the following to output local output to remote.

ssh hostA 'head > destfile' < srcfile