[kwlug-disc] Question about `ps` and `grep`

Ronald Barnes ron at ronaldbarnes.ca
Wed Sep 25 21:04:15 EDT 2024


I watched a recent video about bash on YouTube channel "You Suck At 
Programming" and a comment there has me completely baffled.


The topic was `pgrep` and `pkill` instead of `ps aux | grep ...`.


The comment had a solution to seeing the `grep` command in the output 
when grep'ing `ps` output:

This shows the grep command in the output:


# ps aux | grep  tmux
root        9032  0.0  0.0  23476  5632 pts/1    S+   Sep05   0:04 sudo 
tmux new -s w00
root        9041  0.0  0.0  23476  1560 pts/9    Ss   Sep05   0:00 sudo 
tmux new -s w00
root        9042  0.0  0.0  10916  3712 pts/9    S+   Sep05   0:00 tmux 
new -s w00
root        9045  0.0  0.0  14236  4920 ?        Ss   Sep05   1:14 tmux 
new -s w00
root      748047  0.0  0.0   9212  2560 pts/10   S+   17:59   0:00 grep 
--color=auto --directories=skip tmux



BUT, changing what's being grep'd for by making it [t]mux:

# ps aux | grep  [t]mux
root        9032  0.0  0.0  23476  5632 pts/1    S+   Sep05   0:04 sudo 
tmux new -s w00
root        9041  0.0  0.0  23476  1560 pts/9    Ss   Sep05   0:00 sudo 
tmux new -s w00
root        9042  0.0  0.0  10916  3712 pts/9    S+   Sep05   0:00 tmux 
new -s w00
root        9045  0.0  0.0  14236  4920 ?        Ss   Sep05   1:14 tmux 
new -s w00


Now grep's output is NOT shown.


And I cannot figure out why not?!?


I understand that [t] is a character range (of one character), but 
without explicit anchoring, why does that work?



Anyone able to explain this?


(Also, https://www.youtube.com/@yousuckatprogramming channel is highly 
recommended - 3 to 4 minute videos, usually about `bash` topics, where 
there's always something I learn.

Then check the comments for user "extrageneity", who expands on the 
topic with a Uni CS level comment.)


Thanks,

rb



More information about the kwlug-disc mailing list