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:
My variant on this common function. Some highlights:
Allows you to override the default ps args of "aux"
Uses bracket trick to omit the grep process itself without having to use a second grep
Always prints the correct header row of ps output
Limitations: Ugly ps error output if you forget to quote your multi word grep argument
This command takes the output of the 'last' command, removes empty lines, gets just the first field ($USERNAME), sort the $USERNAMES in reverse order and then gives a summary count of unique matches.
This will give you the Dell Service tag number associated with your machine. Incredibly useful when you need that number for tech support or downloads.
This command deletes all files in all subfolders if their name or path contains "deleteme".
To dry-run the command without actually deleting files run:
find . | grep deleteme | while read line; do echo rm $line; done
This is a 'killall' command equivalent where it is not available.
Prior to executing it, set the environment variable USERNAME to the username, whose processes you want to kill or replace the username with the $USERNAME on the command above.
Side effect: If any processes from other users, are running with a parameter of $USERNAME, they will be killed as well (assuming you are running this as root user)
[-9] in square brackets at the end of the command is optional and strongly suggested to be your last resort. I do not like to use it as the killed process leaves a lot of mess behind.
finds all forms instanciated into a symfony project, pruning svn files.
Get simple description on each file from /bin dir, in list form, usefull for newbies.
this will find text in the directory you specify and give you line where it appears.
/proc/cpuinfo contains information about the CPU.
Search for "processor" in the /proc/cpuinfo file
wc -l, counts the number of lines.
grep -sq "" filename && command
grep can be used in combination with && to run a command if a file exists.
The trick here is to use the brackets [ ] around any one of the characters of the grep string. This uses the fact that [?] is a character class of one letter and will be removed when parsed by the shell. This is useful when you want to parse the output of grep or use the return value in an if-statement without having its own process causing it to erroneously return TRUE.
Filter comments and empty lines in files. I find this very useful when trying to find what values are actually set in a very long example config file.
I often set an alias for it, like :
alias nocomment='grep -v "^\($\|#\)"'
only works for freeBSD where ports are installed in /usr/ports
credit to http://wiki.freebsd.org/PortsTasks
changes the PS1 to something better than default.
[username.hostname.last-2-digits-of-ip] (current directory)
Very useful set of commands to know when your file system was created.
Great for finding which jar some pesky class is hiding in!
Backups all MySQL databases to individual files. Can be put into a script that grabs current date so you have per day backups.
This is the simple revision number on stdout, that can be fed to any useful/fun script of yours. Setting LC_ALL is useful if you use another locale, in which case "Revision" is translated and cannot be found. I use this with doxygen to insert my source files revisions into the doc. An example in Doxyfile:
FILE_VERSION_FILTER = "function svn_filter { LC_ALL=C svn info $1 | grep Revision | awk '{print $2}'; }; svn_filter"
Share your ideas about what to do with the revision number !
This is just one method of checking to see if an IP is blocked via IP tables or CSF. Simple and to the point. Replace xx.xx.xx.xx with the IP you wish to check.