Skip to content

Instantly share code, notes, and snippets.

@mgol

mgol/psa

Last active Apr 25, 2017
Embed
What would you like to do?
List processes matching a pattern
#!/bin/sh
# Usage: move this file to ~/bin/ and create a link ~/bin/psa-full -> psa.
# `psa STRING` will show you the output clipped to current number of columns in
# the terminal, `psa-full STRING` will give the full output.
# Tested on OS X 10.9-10.10.
if [[ "`basename "$0"`" == *-full ]]; then
COLS=10000
else
COLS=`tput cols`
fi
PS_COMMAND='ps axo pid,ppid,tty,user,group,time,pcpu,pmem,args'
if [ $# -eq 0 ]; then
eval "$PS_COMMAND" | cut -b1-$COLS
else
eval "$PS_COMMAND" | egrep -v "(/bin/sh $HOME/bin/psa|$PS_COMMAND|egrep)" | egrep -i '(PID\s+PPID\s+TTY\s+USER\s+GID\s+TIME\s+\%CPU\s+\%MEM\s+ARGS|'"$1"')' | cut -b1-$COLS
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.