Skip to content

Instantly share code, notes, and snippets.

@mgol
Last active April 25, 2017 10:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgol/10657381 to your computer and use it in GitHub Desktop.
Save mgol/10657381 to your computer and use it in GitHub Desktop.
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