Depends on how your terminal(-emulator) behaves in conjunction with the scroll lock key.
If you're using a terminal multiplexer to handle scrollback, you can navigate the output using your usual pager whether you explicitly invoked it in the pipeline or not. And that leaves it searchable in your scrollback history even after you've gone on to run several more commands, unlike if you pipe it directly to a pager.
Additionally, if you're using a nicer colorizing pager, like bat, it'll automatically send the output to your pager for you when it detects that the output wouldn't fit on screen.
For both of those reasons, I almost never use `less` directly on a file.
First case is good, the second one feels like cheating, if you are using a cat substitute like bat, well, you are not using cat already.
Fair enough :)
Re:A Terminal Case of Linux
by bloopernova on Monday May 29, 2023 @05:30PM
(#36118327)
After your cat command has run, type 'vim ' then hit the escape key plus the period/full stop key. That inserts the previous command's parameters/arguments at the cursor.
Obviously you don't have to use vim, any other editor or whatever can be used.
> inserts the previous command's parameters/arguments at the cursor
In zsh, there are equivalent expansions:
!!:1 previous command line, arg 1 (zero-indexed)
!!:$ previous command line, LAST arg
!!:1-$ previous command line, args 1-end (zero-indexed)
So, e.g.: cat /etc/passwd /etc/shadow /etc/group
vi !!:1-$
(becomes) vi /etc/passwd /etc/shadow /etc/group
Re:A Terminal Case of Linux
by bloopernova on Monday May 29, 2023 @06:10PM
(#36118702)
Nice! I'll have to add those to my wall of index cards with useful commands.
I use !!:$ occasionally.
If I wanted to do the cat/vim switcheroo you described, I'd more likely do:
<UpArrow><Esc>vcwvi<Esc>:wq<Enter><Enter>
Which is a greater number of keypresses, but more flexible and requires less thought....as they say: Unix is user-friendly — it's just choosy about who its friends are.
Re:A Terminal Case of Linux
by boring_twenties on Tuesday May 30, 2023 @03:32AM
(#36122108)
Those all work in bash too, I believe they come from csh
Re:A Terminal Case of Linux
by tedunangst on Monday May 29, 2023 @05:39PM
(#36118409)
cat file leaves the contents on my screen as I compose my next shell command, as opposed to erasing them as quitting the editor flips back from the alt screen.
I sometimes use the following prevent screen clearing when exiting vi:
:set t_te=
Useful because vi makes it more convenient to select the chunk of file I want to view after exiting. More convenient than cat/head/tail at least. Competitive with more. :)My terminal emulator has supported scrollback since I started using it in '95. I didn't get the impression at the time that it was a particularly new feature :)
Sure, few seconds isn't a lot, to someone who opens terminal once a year.