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:
compare to alternative :
- directly tests the -STOP of the process to continue or stop loop,
- background operator should be set (or not) at the call of the function
For extension i suggest a slowPID() based on kill like above and a slowCMD based on killall.
Some IO intensive process make the system unresponsive. This function periodically starts/stops a process, which hopefully releases some resources for other activities.
This function is useful when ionice is not available
List background jobs, grep their number - not process id - and then kill them
run this in another terminal, were xxxx is the process ID of the running dd process.
the progress will report on the original terminal that you ran dd on
Kills all the threads from the user provided in the WHERE request.
Can be refined through the SQL request, of course, see http://dev.mysql.com/doc/refman/5.1/en/processlist-table.html for the available columns.
This one liner is to kill all google chrome tabs. This works similar to $ killall firefox command which is to kill all firefox processes.
The previously-posted one-liner didn't work for me for whatever reason, so I ended up doing this instead.
# define user pid to kill
PID=httpd ;
# kill all pids
ps aux | grep $PID | grep -v grep | awk '{print $2}' | xargs kill -9
The other 2 commands that are listed will also kill the egrep process and any libexec processes because the .exe isn't escaped so it is really using . meaning anything containing exe. The command i posted escapes the (dot) in .exe and then filters the actual egrep process so that it doesn't get killed before the other processes being killed. Also added the -9 switch for kill to send sigterm to the processes, in case people are wondering why processes aren't getting killed after running just kill . This should work better for people :)
Occasionally, to force zone updating, cache flush is necessary. This command is better than restart the mydns daemon.
eg:
Already running cmd
sleep 120
Substitution cmd
c=$(pgrep sleep) && sleep 5 && kill $c
If you know that you want only the first match from a 'find' command, this will terminate the find as soon as a match is found.
Recent versions of GNU find have the -quit parameter, which does the same thing as this, so this is only useful if you are stuck with an older version of find. or need to write a backward portable script.
I can't take credit for this - I saw it on a chat room where I work and thought it was useful, so am sharing it here both for others, and in case I want to remember it in the future.
Only slightly different than previous commands. The benefit is that your "watch" should die when the dd command has completed. (Of course this would depend on /proc being available)
I have some problems with gnome panel which does not load completely leaving me without the actual GUI. This commands helps to kill the gnome-panel process then it should be relaunch automatically.
Outputs the PID of any given file run from a command line... Hope it helps!
This command kills all wine instances and each EXE application working on a PC.
Here is command info:
1) ps ax > processes = save process list to file named "processes" (we save it because we don't wont egrep to be found in the future)
2) cat processes | egrep "*.exe |*exe]" = shows the file "processes" and after greps for each *.exe and *exe] in it
3) | awk '{ print $1 }' > pstokill = saves processes PID's to file "pstokill" using awk filter
4) kill $(cat pstokill) = kills each PID in file pstokill, which is shown by cat program
5) rm processes && rm pstokill = removes temporary files
This shell function takes a single argument, which is used as the base name of the .wav, .timing and .session files created. To create a screencast:
screencast test
type and talk ...
then type 'exit' or to exit the screencast.
test.wav will contain the audio from your screencast.
test.session will contain text and control characters needed to paint the screen
test.timing will contain timing information needed to synch individual keystrokes in test.session with the audio.
to play back:
aplay test.wav & scriptreplay test.{timing,session}
NOTE: because the shell function uses the variable "$!", and bash likes to expand '!' during history expansion, you will need to turn off bash's history before you enter the shell function.
This can be achieved using the command
set +H
This is an attempt to get a command which I can alias. It's ugly but it works. I'm hoping someone can suggest a cleaner version.
I have tried....
# alias kfire="for i in $( ps aux | grep [F]irefox | awk \'{print $2}\' ); do kill $; done"
# alias kfire=`kill $(ps aux | grep [F]irefox | awk '{print $2}' | tr '\n' ' ')`
# alias kfire='ps au | grep -i [F]irefox | awk \'{ print $2 \'} '
and they all fail in a .bashrc I've tried escaping the quotes and can't find a way to make the single quotes ' that awk wants work. Maybe I'm just stubborn but I don't want to put in a little #!/bin/bash file just so I can kill a firefox process all in one stroke. This script works (it kills the process before it errors out)... it's just ugly and there may be a pretty way to do this.