-
-
Save mgol/10657381 to your computer and use it in GitHub Desktop.
List processes matching a pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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