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

list block devices
Shows all block devices in a tree with descruptions of what they are.

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"

Figure out what shell you're running

watch iptables counters
This will allow you to watch as matches occur in real-time. To filter out only ACCEPT, DROP, LOG..etc, then run the following command: watch 'iptables -nvL | grep -v "0 0" && grep "ACCEPT"' The -v is used to do an inverted filter. ie. NOT "0 0"

How to copy CD/DVD into hard disk (.iso)
A dear friend of mine asked me how do I copy a DVD to your hard drive? If you want to make a copy of the ISO image that was burned to a CD or DVD, insert that medium into your CD/DVD drive and (assuming /dev/cdrom is associated with your computer?s CD drive) type the following command

Detect illegal access to kernel space, potentially useful for Meltdown detection
Based on capsule8 agent examples, not rigorously tested

Create a mirror of a local folder, on a remote server
Create a exact mirror of the local folder "/root/files", on remote server 'remote_server' using SSH command (listening on port 22) (all files & folders on destination server/folder will be deleted)

Show interface/ip using awk
Interfaces like lo can be omitted from the beginning, there are probably better ways of doing this, i'm a noob at awk.

Grep for regular expression globally, list files and positions.
Grep for expression globally, list files and positions. "Hirn" is a nice german crib meaning "Brain". :-) Afterwards you can edit the line you want with "vi ./p_common/common_main.pbt +1550"

resolving basic authentication problem(401) with wget
I have a server with a php requiring basic authentication, like this:


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: