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:
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.
Adjust "sleep X" to your needs.
*NOTE: First sleep is required because bash doesn't have a "post-test" syntax (do XXX while).
I use this command, within a cron job, to kill XMMS after a certain amount of time. This command returns the PID used by XMMS, and gets passed to the kill command. Another alternative would be ps aux | grep xmms | grep -v grep | awk '{ print $2 }' | xargs kill
Logs all users out except root.
I changed the grep to use a regexp in case a user's username contained the word root.
Kills all process that belongs to the user that runs it - excluding bash, sshd (so putty/ssh session will be spared). The bit that says grep -vE "..." can be extended to include ps line patterns that you want to spare.
If no process can be found on the hitlist, it will print # NOTHING TO KILL. Otherwise, it will print # KILL EM ALL, with the cull list.
just a leaner, smaller version. Love the original idea!
It identifies the parents of the Zombie processes and kill them. So the new parent of orphan Zombies will be the Init process and he is already waiting for reaping them. Be careful! It may also kill your useful processes just because they are not taking care and waiting for their children (bad parents!).
Tested on FreeBSD 8.1 and CSH. The scripts works correctly but the Zombies do not die! I hope it will run and function as expected in Linux and others.
Somtime one wants to kill process not by name of executable, but by a parameter name. In such cases killall is not suitable method.
Removed unneeded grep -v by making the initial grep unable to match itself.
search_criteria = what do you want to kill
pid = pid of you dont kill