this post was submitted on 09 Jan 2025
17 points (100.0% liked)

linux4noobs

1453 readers
36 users here now

linux4noobs


Noob Friendly, Expert Enabling

Whether you're a seasoned pro or the noobiest of noobs, you've found the right place for Linux support and information. With a dedication to supporting free and open source software, this community aims to ensure Linux fits your needs and works for you. From troubleshooting to tutorials, practical tips, news and more, all aspects of Linux are warmly welcomed. Join a community of like-minded enthusiasts and professionals driving Linux's ongoing evolution.


Seeking Support?

Community Rules

founded 1 year ago
MODERATORS
 

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

top 13 comments
sorted by: hot top controversial new old
[–] neidu3@sh.itjust.works 14 points 21 hours ago* (last edited 11 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.

[–] andrew_s@piefed.social 6 points 20 hours 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).

[–] lemmyng@lemmy.ca 4 points 19 hours 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.

[–] iii@mander.xyz 4 points 21 hours ago

Pipe it through more, for example dmesg | more

[–] ulterno@programming.dev 3 points 20 hours ago (1 children)

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

I have Shift+Home set for this purpose.

[–] 299792458ms@piefed.social 1 points 6 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.

[–] furikuri@programming.dev 2 points 19 hours 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\\"
}
[–] CameronDev@programming.dev 2 points 20 hours 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.

[–] tdawg@lemmy.world 2 points 20 hours ago (1 children)

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

[–] CameronDev@programming.dev 5 points 20 hours ago (1 children)
[–] tdawg@lemmy.world 1 points 20 hours ago* (last edited 20 hours ago) (1 children)

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

[–] MNByChoice@midwest.social 1 points 18 hours ago (1 children)

random crap I do in my term

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

[–] tdawg@lemmy.world 2 points 16 hours ago

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