I often want to read output from the terminal from the beginning but by default I have to scroll back up. This can be laborious when there is a lot of text. Is there anything I can do about this?

Thanks :)

  • @[email protected]
    link
    fedilink
    English
    13
    edit-2
    18 hours ago

    Pipe it through less. Example:
    dmesg | less

    The pipe character basically takes the output (STDOUT to be specific) of one command and provides it as input (STDIN) to the next command. It’s one of the many ways of redirecting in linux.

    Some relevant examples:
    dmesg > dmesg.txt …(over)writes the ouput to a file
    dmesg >> dmesg.txt …appends the output to a file
    ps aux | grep bash …pipe, as described above. The tidbit is that grep only prints lines matching the pattern specified
    find / -name somefilename 2>&1 >result.txt …redirects warnings and errors (STDERR) to STDOUT, so that you don’t have to treat those separately.

  • lemmyng
    link
    fedilink
    English
    41 day ago

    One option that hasn’t been mentioned yet: head. It will only show the first 10 (or is it 20?) lines of the output you pipe into it by default, but you can also pass a parameter to change the number of lines shown. The complement of this command is tail, to show only the last N lines. Both these commands are handy when you only want to see the first/last lines of output.

  • Andrew
    link
    fedilink
    English
    41 day ago

    It’s interesting that ‘less’ and ‘more’ have both been mentioned - when I was first starting with Linux, the fact ‘less’ is the newer, more advanced version of ‘more’ is the kind of jokey stuff that I couldn’t get my head around.

    Anyway, depending on the output, another useful option can be piping it to ‘column’. There was a fun video about this the other day at https://piefed.social/post/401865 (the video itself is hosted by PeerTube).

  • @[email protected]
    link
    fedilink
    21 day ago

    For cases where you really just want to jump between different prompts without piping out to another program/file, many terminals also support jumping through prompts as long as your shell marks them with an OSC-133;A escape code (looks like fish does this automatically now). Some terminals that support this are foot, tmux, kitty, and Emac’s vterm, but it’s undoubtably available in many others.

    For example let’s say you’re using the foot terminal and the zsh shell. Just add the following code to your zshrc and then you can jump through each prompt using CTRL-z and CTRL-x

    precmd() {
        print -Pn "\e]133;A\e\\"
    }
    
  • @[email protected]
    link
    fedilink
    English
    21 day ago

    Depending upon your terminal, you might find shortcuts for that.

    I have Shift+Home set for this purpose.

    • 299792458ms
      link
      fedilink
      English
      113 hours ago

      Yep, I think this is the best solution, with foot terminal you can navigate going to the top/bottom or scrolling with keybinds. Unless of course the output is too big or you want to save the output, then the other comments on the post have you covered.

  • DreamButt
    link
    English
    21 day ago

    Some people are saying to use less or more. But what you really wanna do is dump the output to a text file then less or more the file. You can delete the file later

    I always use my desktop for this bc the icons annoy me so I know I’ll nuke it later.

    But anyway this is better in general bc often you’ll forget what the output was or you’ll want to reference it somehow

      • DreamButt
        link
        English
        1
        edit-2
        1 day ago

        I only use tmp for scripts not for random crap I do in my term

        • @[email protected]
          link
          fedilink
          11 day ago

          random crap I do in my term

          /dev/shm is great for that. :) Automatically cleans up regardless of distribution.

          • DreamButt
            link
            English
            223 hours ago

            Oh for sure. Anything other than the desktop just feels more offical somehow is the thing

  • @[email protected]
    link
    fedilink
    11 day ago

    Using less is good, but only if your command output is done in one go. If you have a command that keeps running, use reset; command to first clear all output, and then run the command. You can easily scroll right to the top.