I am trying to understand this peculiar behavior. Basically, I'm trying to grep an output of a command while still keeping the first line/header. Thanks for the help in advance.
ps -ef | { head -1; grep bash; }
Output:
UID PID PPID C STIME TTY TIME CMD
username 1008 1 0 Jan21 tty1 00:00:00 -bash
username 1173 1008 0 Jan21 tty1 00:00:00 -bash
ls -tlrh / | { head -1; grep tmp; }
Output:
total 100K
(i.e.: it ignores the /tmp
folder)
@Jotne's answer is better, but sometimes you can use grep -E
if you know something in the first line, then you can search for that OR the other thing you want like this with the pipe symbol to express the alternation:
ps -ef | grep -E "UID|bash"
Output
UID PID PPID C STIME TTY TIME CMD
502 510 509 0 8:01am ttys000 0:00.08 -bash
502 48806 510 0 10:18am ttys000 0:00.00 grep -E UID|bash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With