Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using ps from sorted by
Terminal - Commands using ps - 221 results
stop () { ps -ec | grep $@ | kill -SIGSTOP `awk '{print $1}'`; }
2009-12-27 19:40:09
User: iridium172
Functions: grep kill ps
1

Add that and "cont () { ps -ec | grep $@ | kill -SIGCONT `awk '{print $1}'`; }" (without the quotes) to you bash profile and then use it to pause and resume processes safely

ps -ylC httpd --sort:rss | awk '{ SUM += $8 } END { print SUM/1024 }'
2009-12-20 15:41:50
User: nasser
Functions: awk ps
0

This command will show you amount of memory used by apache

ps aux | grep [h]ttpd | cat -n
2009-12-17 20:45:44
User: putnamhill
Functions: cat grep ps
Tags: cat
0

If you're on a system that doesn't have nl, you can use cat -n.

ps aux | grep [a]pache2 | nl
2009-12-17 18:48:09
User: donnoman
Functions: grep ps
4

Write each FILE to standard output, with line numbers added. With no FILE, or when FILE is -, read standard input.

ps ax| awk '/[h]ttpd/{print $1}'| xargs kill -9
ps aux| grep -v grep| grep httpd| awk {'print $2'}| xargs kill -9
psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
2009-11-13 06:10:33
User: AskApache
Functions: command ps
4

An easy function to get a process tree listing (very detailed) for all the processes of any gived user.

This function is also in my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html

ps -ec -o command,rss | grep Stainless | awk -F ' ' '{ x = x + $2 } END { print x/(1024) " MB."}'
2009-11-04 19:01:22
Functions: awk grep ps
0

Adds up the total memory used by all Stainless processes: 1 Stainless, 1 StainlessManager and 1 StainlessClient per tab open.

ps -eo pcpu,user,pid,cmd | sort -r | head -5
ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f\t%.2f\n",num[user], user, cpu[user], mem[user]) }'
2009-10-29 12:49:01
User: georgz
Functions: awk ps tail
7

The original version gives an error, here is the correct output

ps aux --sort=%mem,%cpu
2009-10-10 22:48:51
User: mrwill
Functions: ps
13

you can also pipe it to "tail" command to show 10 most memory using processes.

ps -ef | grep pmon
ps -C program_name || { program_name & }
ps -u<user>
psg() { ps aux | grep "[${1[1]}]${1[2,-1]}"; }
2009-09-07 04:37:11
User: jedahan
Functions: grep ps
-5

alias ps?='psg' for maximum hawtness. Works in bash or zsh.

ps -ef | awk '/process-name/ && !/awk/ {print}'
2009-08-19 11:22:09
User: dopeman
Functions: awk ps
1

This does the same thing as many of the 'grep' based alternatives but allows a more finite control over the output. For example if you only wanted the process ID you could change the command:

ps -ef | awk '/mingetty/ && !/awk/ {print $2}'

If you wanted to kill the returned PID's:

ps -ef | awk '/mingetty/ && !/awk/ {print $2}' | xargs -i kill {}
command ps -Hacl -F S -A f
2009-08-19 07:08:19
User: AskApache
Functions: command ps
8

I don't truly enjoy many commands more than this one, which I alias to be ps1.. Cool to be able to see the heirarchy and makes it clearer what need to be killed, and whats really going on.

ps aux | grep [c]ommandname
ps -C command
2009-08-14 15:30:42
User: recursiverse
Functions: ps
6

preferred way to query ps for a specific process name (not supported with all flavors of ps, but will work on just about any linux afaik)

ps aux | grep [p]rocess-name
2009-08-13 05:44:45
User: olorin
Functions: grep ps
62

As an alternative to using an additional grep -v grep you can use a simple regular expression in the search pattern (first letter is something out of the single letter list ;-)) to drop the grep command itself.

ps aux | grep process-name | grep -v "grep"
ps -A
2009-08-11 16:52:59
User: xraj
Functions: ps
-13

list all the processes

ps -o comm= -p $(ps -o ppid= -p $$)
2009-08-03 07:41:21
User: olorin
Functions: ps
4

Get the name of the parent command. This might be helpful, if you need to react on that information. E. g. a script called directly via ssh has got sshd as parent, manually invoked the parent process will probably be bash

ps -o rss -C httpd | tail -n +2 | (sed 's/^/x+=/'; echo x) | bc
2009-07-31 15:15:08
Functions: echo ps sed tail
4

Display the amount of memory used by all the httpd processes. Great in case you are being Slashdoted!