0

I use curl to access ASCII info from some server but it always moves to the bottom. How do I ensure that it starts from the top?

There is an analogous question about the cat command and I guess a solution could be to redirect the output to a file, then use less as suggested here. Is something more efficient possible?

1 Answer 1

1

You could pipe the output through less with the +Gg flags (check the comments):

curl ... | less +Gg

Meaning of the flags, from the manpage:

   g or < or ESC-<
          Go to line N in the file, default 1 (beginning of file).  (Warn‐
          ing: this may be slow if N is large.)

   G or > or ESC->
          Go to line N in the file, default the end of the  file.   (Warn‐
          ing:  this  may  be slow if N is large, or if N is not specified
          and standard input, rather than a file, is being read.)
6
  • This would only show the top then. I want it such that I can scroll from top to bottom, just like we do on the man page. May 15, 2021 at 16:18
  • @cookiemonster pipe into less instead of head.
    – cas
    May 15, 2021 at 16:38
  • @cas I you pipe into less, the download continues. If you pipe into head, only the needed information is downloaded. Since it was about efficiency the idea is to close the pipe and interrupt the download. May 15, 2021 at 17:01
  • True, but I think @cookiemonster was concerned about the start of the output scrolling off the top of their terminal. BTW, if CM wants less to read all of curl's output before displaying anything, you can run curl ... | less +Gg - the uppercase G tells less to skip to the end of the input, and the lowercase g tells it to jump back to the start. This is useful to avoid having the remote web server time out and close theconnection prematurely if you take a long time reading through the file.
    – cas
    May 15, 2021 at 17:08
  • 2
    no, you go ahead and use it if you want. it's way too late for me to write an answer, i intended to go to sleep hours ago. stuff said in comments is fair game, anyway.
    – cas
    May 15, 2021 at 18:55

You must log in to answer this question.

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