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 :)

  • 0day@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    20 days ago

    You could pipe it to less.

    somecommand | less

    Or if you want only the beginning or end of output, use head or tail.

  • neidu3@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    25 days 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.

  • Andrew@piefed.social
    link
    fedilink
    English
    arrow-up
    1
    ·
    25 days 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).

  • DreamButt@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    25 days 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