2 ms·
People often say "you can refactor that line and save a useless invocation of cat" cat /var/log/file.log Output too long, so Press Up, |grep -e useful -e l
by iso1631 5y ago
People often say "you can refactor that line and save a useless invocation of cat"
cat /var/log/file.log
Output too long, so
Press Up, |grep -e useful -e lines
cat /var/log/file.log|grep -e useful -e lines
OK, that looks fine, but I want to tail it
Press Up, Home, deldeldel, tail -f (other terminal modes are available)
tail -f /var/log/file.log|grep -e useful -e lines
Exact same command no matter what grep -e you have. You separate the filtering logic from the accessing logic. You can work on one side without worrying about the other. Want to change from cat to bzcat, or tail, or tac, or nc? No problem. Want to add a pre-filter (say strip snmpd errors before you add -n to number your matches in grep), it all stays the same.
Now imagine this without "useless" cat
less /var/log/file.log
Press Up, Home, deldeldeldelgrep -e useful -e lines
grep -e useful -e lines /var/log/file.log
Then either
Press up, home, del(n times), tail, end, | grep -e useful -e lines
Or
Press up, up, |grep -e useful -e lines, home, deldeldel, tail -f
Cognative break, extra typing, potentially having to look at what you're typing too rather than muscle memory, all because someone says "cat is useless". My computer isn't from 1965, I don't need to justify every process I run.