Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

This question is related to a question I posted on rogue firefox procesess. It relates to firefox processes following image uploads that I have been having for a while.

I am trying to get to the second field of the ps command with the following set of pipes, so that I can kill the processes from the command line quickly:

ps aux| grep fire|cut -f 2

However this produces the wrong output as it shows the whole line of ps.

I know that the default delimiter for cut is tab

I have also tried:

ps aux| grep fire|cut -f 2 -d \t

From this question on stackoverflow I know that

ps axu | grep '[f]irefox' | awk '{print $2}'

gives me the output I want.


I want to understand why my two versions of cut are not working, and can it be made to work piping ps to grep and then to cut and getting to the second column (ie. the process IDs).

share|improve this question

1 Answer 1

up vote 3 down vote accepted

ps does not use Tabs to separate column (run ps aux > foo; vi foo to verify). As an alternative you can cut on character level by running

kill $(ps aux | grep fire | cut -c 17-23)

Or you can also just run

pkill fire

(or pgrep fire to see which processes would match)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.