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/
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.
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
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:
proc lister
usage: p
proc killer
usage: p patt [signal]
uses only ps, grep, sed, printf and kill
no need for pgrep/pkill (not part of early UNIX)
_p(){
ps ax \
|grep $1 \
|sed '
/grep.'"$1"'/d' \
|while read a;do
printf ${a%% *}' ';
printf "${a#* }" >&2;
printf '\n';
done;
}
p(){
case $# in
0)
ps ax |grep .|less -iE;
;;
1)
_p $1;
;;
[23])
_p $1 2>/dev/null \
|sed '/'"$2"'/!d;
s,.*,kill -'"${3-15}"' &,'|sh -v
;;
esac;
}
alas, can't get this under 255 chars.
flatcap?
Works on most unixes, on OpenBSD replace the "-g" parameter at the sort with a "-n".
Like the original version except it does not include the parent apache process or the grep process and adds "sudo" so it can be run by user.
This is great when you need to reboot the system-server, or your own daemon that has gone crazy
This one liner is to kill all google chrome tabs. This works similar to $ killall firefox command which is to kill all firefox processes.
# define user pid to kill
PID=httpd ;
# kill all pids
ps aux | grep $PID | grep -v grep | awk '{print $2}' | xargs kill -9
It grabs the PID's top resource users with $(ps -eo pid,pmem,pcpu| sort -k 3 -r|grep -v PID|head -10)
The sort -k is sorting by the third field which would be CPU. Change this to 2 and it will sort accordingly.
The rest of the command is just using diff to display the output of 2 commands side-by-side (-y flag) I chose some good ones for ps.
pidstat comes with the sysstat package(sar, mpstat, iostat, pidstat) so if you don't have it, you should.
I might should take off the timestamp... :|
works as well as echo $0, but also prints process id, which pts you're using. echo $SHELL doesn't always get updated when changing shells, so this is a better solution than that. Just one more variation on a theme.
Tested in bash on AIX & Linux, used for WAS versions 6.0 & up. Sorts by node name.
Useful when you have vertically-stacked instances of WAS/Portal. Cuts out all the classpath/optional parameter clutter that makes a simple "ps -ef | grep java" so difficult to sort through.
Gets the current system user running a process with the specified pid
This command will allow to search for duplicate processes and sort them by their run count. Note that if there are same processes run by different users you'll see only one user in the result line, so you'll need to do:
ps aux | grep <process>
to see all users that run this command.
Find the USERid of a SUDOed user who has either left their terminal logged in or for scripting purposes to track who ran what commands.
This only applys to users that do sudo su - USERNAME. not sudo su USERNAME
Sudo su without the dash allows use of (echo $SUDO_USER)
to be executed from root. this works well on most commercial unix systems, have not tried on linux systems.