1

I want to rewrite this function so that it shows only the command name and the arguments without having to specify all those options to awk

function psgrep() 
    # show process id and command with arguments
    ps aux | grep "${1:-.}" | grep -v grep | awk '{print $2, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20}'
}
0

1 Answer 1

2

If you want to search for a specific executable, ps can do everything for you:

ps -o pid,cmd -C "$1"

If you want a more general search, you can post-process the output of ps -e -o pid,cmd:

ps -e -o pid,cmd | awk -v "s=$1" 'NR==1 || $0 ~ s'

You must log in to answer this question.