DEV Community

Discussion on: A small byte of bash aliases and functions.

Collapse
 
moopet profile image
Ben Sinclair

For your process finding one, you might want to exclude the grep command itself, depending on what system you're on. On a Mac, for example, you'll get the process used to grep listed, which is generally not what you want. Also on a Mac, ps -aux will fail if there isn't a user called "x" because ps interprets commands differently depending whether you use a dash or not (I know!).

alias pid='ps aux | grep -v grep | grep'
Enter fullscreen mode Exit fullscreen mode

Or if you're only interested in the PID (as implied by the alias name, you can use pgrep which fits nicely with pkill because without any other options it just returns the PID.

I know you tagged this with #linux but I think it's good to make things as general as possible so if you have to work on a BSD system or a Mac you can re-use the same commands.

Collapse
 
waylonwalker profile image
Waylon Walker

I need to use pgrep more I still hand type the alias that you showed.