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 :)
You could pipe it to
less
.somecommand | less
Or if you want only the beginning or end of output, use
head
ortail
.Pipe it through less. Example:
dmesg | lessThe 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.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).
Pipe it through more, for example
dmesg | more
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
/tmp
cries from neglect :DI only use tmp for scripts not for random crap I do in my term
random crap I do in my term
/dev/shm is great for that. :) Automatically cleans up regardless of distribution.