News for hackers. Stuff that matters.
Re:A Terminal Case of Linux by sverona on Monday May 29, 2023 @02:10PM (#36116399)
A good friend of mine called "cat file.txt" UUOC on the grounds I should have run "less file.txt". If you're writing a script, sure. If it's the first step in a pipeline that you're typing on the fly, does it really matter?
Re:A Terminal Case of Linux by levihaku on Monday May 29, 2023 @03:13PM (#36116976)
cat file.txt is always worthless. Best case scenario, you will end up with text that fits into one scree, but more often than not you will have to retype the command with $EDITOR filename or less filename anyway and now you just wasted (precious) time doing what could've been done few seconds ago.

Sure, few seconds isn't a lot, to someone who opens terminal once a year.

Re:A Terminal Case of Linux by omnibrain on Monday May 29, 2023 @03:19PM (#36117034)
Depends on how your terminal(-emulator) behaves in conjunction with the scroll lock key.
Re:A Terminal Case of Linux by pxc on Monday May 29, 2023 @04:44PM (#36117915)
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.

Re:A Terminal Case of Linux by darkwater on Monday May 29, 2023 @05:36PM (#36118386)
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.
Re:A Terminal Case of Linux by pxc on Monday May 29, 2023 @05:50PM (#36118524)
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.

Re:A Terminal Case of Linux by quesera on Monday May 29, 2023 @05:46PM (#36118489)
> 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.
Re:A Terminal Case of Linux by quesera on Monday May 29, 2023 @06:20PM (#36118776)
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.
Re:A Terminal Case of Linux by quesera on Monday May 29, 2023 @05:55PM (#36118575)
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. :)
Re:A Terminal Case of Linux by scbrg on Tuesday May 30, 2023 @01:18AM (#36121370)
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 :)
Re:A Terminal Case of Linux by sverona on Wednesday May 31, 2023 @03:21PM (#36142805)
Sure, if I know it's bigger than my screen I'll open another terminal and use less. But I can generally tell if that's the case from the filesize.