Sometimes I need to end a process quickly via terminal but it is tedious to just type ps -e | grep firefox and then kill all the time. I want to create an alias in my .bashrc and just type in killfirefox

I guess this would do it but I don't really understand everything.

so I've learn that either ps -e | grep firefox | sudo awk '{print $1}' or pgrep firefox will return the pid of firefox which I need to kill a process. I thought this would do the job :

pgrep firefox | sudo awk '{kill $1}' but it doesn't work. It says nothing and firefox is still running. I then tried pgrep firefox | sudo awk '{system(sudo kill $1)}' but then it returns "sh: 1: 27762: not found".

Why doesn't my way work? What's wrong?

  • 4
    your way doesn't work because it makes no sense. it's both wrong and massively over-complicated (e.g. why do you think you need sudo to kill a process you own?). BTW, if you have pgrep, you also have pkill.
    – cas
    May 1, 2016 at 10:57
  • 1
    You also could try killall firefox or killall -r firefox.
    – Thomas
    May 1, 2016 at 11:02
  • Upvoting this. Because overkill can be instructive sometimes. In French we call it "chercher midi à quatorze heures".
    – user86969
    May 1, 2016 at 17:05

3 Answers 3


To have your way works you have to fix the awk syntax and use the system function to execute commands in awk:

pgrep firefox | awk '{system("kill "$1)}'

Then you have your own-made (wheel reinvented) equivalent of:

pkill firefox

as pointed out in your question comments.


For applications like Firefox, I just use killall firefox.

man killall


can you try creating an alias of this

ps -U root -u root | grep "$2" | sudo awk '{system ("sudo kill "$2)}'

  • 3
    This is even more typing than the OP already was doing
    – Anthon
    Sep 2, 2017 at 6:20
  • original command by OP > ps -e | grep firefox | sudo awk '{print $1}' Sep 5, 2017 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .