Commands tagged ps (86)


  • -1
    ps aux | grep name | grep -v grep | awk '{print $2}' | xargs kill -9
    unixmonkey84604 · 2014-11-11 09:19:24 8
  • Function that searchs a process by its name and shows in the terminal. * Shows the Header for reference * Hides the process 'grep' from the list * Case sensitive Show Sample Output


    -1
    psg(){ ps aux | grep -v grep | egrep -e "$1|USER"; }
    ivanalejandro0 · 2014-12-31 22:27:27 9
  • Note that `grep "$(ir foo)"` really doesn't save any typing, but wrapping this inside a second shell function will: psg() { grep "$(ir \"$@\")" ;} Show Sample Output


    -1
    ir() { perl -pne 's/(.)(.*)/\[\1]\2/' <<< "$@" ;}
    bartonski · 2015-07-25 14:13:33 12
  • The '[r]' is to avoid grep from grepping itself. (interchange 'r' by the appropriate letter) Here is an example that I use a lot (as root or halt will not work): while (ps -ef | grep [w]get); do sleep 10; done; sleep 60; halt I add the 'sleep 60' command just in case something went wrong; so that I have time to cancel. Very useful if you are going to bed while downloading something and do not want your computer running all night.


    -2
    while (ps -ef | grep [r]unning_program_name); do sleep 10; done; command_to_execute
    m_a_xim · 2010-01-14 16:26:34 3
  • You'll need to install proctools. MacPorts and Fink have this if you're running Mac OS X, check your Linux distribution's repositories if it isn't installed by default. Show Sample Output


    -2
    pgrep <name>
    alesplin · 2010-02-28 22:59:33 10
  • hb(){ sed "s/\($*\)/`tput setaf 2;tput setab 0;tput blink`\1`tput sgr0`/gI"; } hb blinks, hc does a reverse color with background.. both very nice. hc(){ sed "s/\($*\)/`tput setaf 0;tput setab 6`\1`tput sgr0`/gI"; } Run this: command ps -Hacl -F S -A f | hc ".*$PPID.*" | hb ".*$$.*" Your welcome ;) From my bash profile - http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    -2
    hb(){ sed "s/\($*\)/`tput setaf 2;tput setab 0;tput blink`\1`tput sgr0`/gI"; }
    AskApache · 2010-04-07 08:45:26 4

  • -2
    pgrep -lf
    ajkaanbal · 2013-07-30 14:10:41 8
  • Function that searchs for process by its name: * Shows the Header for reference * Hides the process 'grep' from the list * Case sensitive The typical problem with using "ps | grep" is that the grep process shows up the in the output. The usual solution is to search for "[p]attern" instead of "pattern". This function turns the parameter into just such a [p]attern. ${1:0:1} is the first character of $1 . ${1:1} is characters 2-end of $1 Show Sample Output


    -2
    psg(){ ps aux | grep -E "[${1:0:1}]${1:1}|^USER"; }
    flatcap · 2015-01-01 00:12:45 9

  • -3
    ps -axgu | cut -f1 -d' ' | sort -u
    dfaulkner · 2010-07-07 12:29:46 4
  • Grep for a named process. Show Sample Output


    -4
    psgrep() { if [ ! -z $1 ]; then echo "Grepping for processes matching $1..." ps aux | grep -i $1 | grep -v grep; else echo "!! Need name to grep for"; fi }
    evenme · 2010-02-27 13:47:28 7
  • David thanks for that grep inside! here is mine version: psgrep() { case ${1} in ( -E | -e ) local EXTENDED_REGEXP=1 shift 1 ;; *) local EXTENDED_REGEXP=0 ;; esac if [[ -z ${*} ]] then echo "psgrep - grep for process(es) by keyword" >&2 echo "Usage: psgrep [-E|-e] ... " >&2 echo "" >&2 echo "option [-E|-e] enables full extended regexp support" >&2 echo "without [-E|-e] plain strings are looked for" >&2 return 1 fi \ps -eo 'user,pid,pcpu,command' w | head -n1 local ARG='' if (( ${EXTENDED_REGEXP} == 0 )) then while (( ${#} > 0 )) do ARG="${1}" shift 1 local STRING=${ARG} local LENGTH=$(expr length ${STRING}) local FIRSCHAR=$(echo $(expr substr ${STRING} 1 1)) local REST=$(echo $(expr substr ${STRING} 2 ${LENGTH})) \ps -eo 'user,pid,pcpu,command' w | grep "[${FIRSCHAR}]${REST}" done else \ps -eo 'user,pid,pcpu,command' w | grep -iE "(${*})" fi }


    -10
    psgrep() ... func to long, please look under "description"
    Xk2c · 2015-01-01 02:58:48 8
  • ‹ First  < 2 3 4

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

HTTP GET request on wireshark remotly

cycle through everything sox knows how to read, playing only the first three seconds
I wasted two hours reading the sox documentation and searching on the web for the format of some obscure fscking sound sample, and then finally came up with this. This plays only the first three seconds of your unknown formatted sound file using every one of sox's built-in filetypes. If you don't get an exact match, you may get close. . I could not fit every single type in and keep it under 127 characters, so you will have to replace "..." with the full list obtainable by `$ sox --help` (or try `Show sample output`) . note: /usr/bin/play should be linked to sox on most systems.

kill all foo process
Kill all processes with foo in them. Similar to pkill but more complete and also works when there is no pkill command. Works on almost every Linux/Unix platform I have tried.

List out classes in of all htmls in directory
Lists out all classes used in all *.html files in the currect directory. usefull for checking if you have left out any style definitions, or accidentally given a different name than you intended. ( I have an ugly habit of accidentally substituting camelCase instead of using under_scores: i would name soemthing counterBox instead of counter_box) WARNING: assumes you give classnames in between double quotes, and that you apply only one class per element.

Remove the first character of each line in a file

Hide or show Desktop Icons on MacOS
Hides all Files and Folders on the MacOS Desktop. To show files and folders, type "true" instead of "false". "Finder" at the end is case sensitive, "finder" doesn’t work

generate random tone

Show crontabs for all users
This is flatcaps tweaked command to make it work on SLES 11.2

print crontab entries for all the users that actually have a crontab
This is how I list the crontab for all the users on a given system that actually have a crontab. You could wrap it with a function block and place it in your .profile or .bashrc for quick access. There's prolly a simpler way to do this. Discuss.


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: