Hacker News new | past | comments | ask | show | jobs | submit login

Now all we need is someone to modify less to recognize that its standard in is connected the output of more so that if you type `cat /etc/passwd | more | less` it could output something which, more or less, looked like the input.

The problem is less that we have fossilization and pointless cruft around basic utilities, it's more that the replacements are written by people with a sense of humor, and their sense of humor is distinctly punny.

It actually works already :)

(more does not page if its stdout is not a terminal)

That only gets you half way. You also need less to not page its input to its output if it detects "more" is on stdin (much harder).

I see what you did there. I think.

I hereby award you a "Useless use of cat" award [1]

more < /etc/passwd | less


Clearly cat is used for clarity in the joke, such that the more or less pun is more obvious. I therefore consider the use of cat in this instance good programming praxis. (Of course good programming praxis in bash is a bit like safe driving in formula one.)

Somehow when I was learning Linux/UNIX 13 years ago, my default way of grepping for something in a file became `cat foo | grep bar`. I've tried, a bit, to break this habit, but can never stick with it. The only time it slows me down is when I'm trying to show someone something and they interrupt to ask why I do it that way :)

I love that the same set of people who like to wax poetic about the elegance of pipes and composable single-purpose tools are the most pedantic about not doing all that when a single tool happens to have all the features you strictly need, monolithically built in. Never mind that STDIN works the same on all processes, while the file argument is highly inconsistent! Never mind that the expansion of single tools to encompass common tasks is widely regarded as a pox on the cleanliness of UNIX! You must learn all the options! Minimize the number of processes! You have 16 GB of RAM but that unnecessary 'cat' is UNACCEPTABLE!

I do the same thing. It fits with how I think. I want to print out this file. Oh, it's too long to parse by hand, I'll search for something. Up-arrow, pipe less.

Sure I could use "<something.txt grep something", but that requires me to decide to use grep right off the bat, something I hardly ever do. Usually I want to look at it first.

It's not a bad idiom to use. You can keep retrieving the last command, and change the grep term quickly with ^w . When the search argument to grep is in the middle of the line, you can't easily iterate over a bunch of search terms by hand.

Did you know you can start the command with the redirection operator?

    <input-file grep stuff
Unless you are concatenating stuff, I see no reason to use cat.

What if you just want to view the contents of input-file, unpaged. `<input-file` doesn't print anything unfortunately (curiously it doesn't error either).

or just more /etc/passwd | less ¯\_(ツ)_/¯

cat /etc/passwd | head -n X | tail -n Y

Print lines X-Y to X of a file. :D

Why so complicated?

sed -ne 'X,Yp' /etc/passwd

Because that's what I came up with in first year uni and nobody ever said "hey, that's too complicated, you should learn to use sed properly."

I should learn to use sed properly.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact