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:
or
which <command> > /dev/null 2>&1 || echo Error!
For example, I write
which colordiff > /dev/null 2>&1 && alias diff=colordiff
in my `~/.bashrc`.
alternatives:
xinit $(which gnome-awesome-session)
with cat /usr/local/bin/gnome-awesome-session:
#!/bin/bash
exec gnome-session --session awesome "$@"
following: http://awesome.naquadah.org/wiki/Quickly_Setting_up_Awesome_with_Gnome
note: in ubuntu 12.10 a probable Xephyr recent bug rejects keybd option ...
vie myscript
will find where myscript is, and then use vi to edit that file. Not much trick, but saves typing if you use it a lot.
This works in multiple unixes, not only linux, for different paths.
On solaris, if you do not have which, you can use:
ksh whence -p anypath/a_command.sh | sed "s|^./|$(pwd)|" ksh whence -p
Some people put spaces in filenames. Others have an $EDITOR environment variable set. This defaults to vim, but you can use whatever you wish: emacs, nano, ed, butterflies, etc.
This version builds on my command 8776 (Find the package a command belongs to on debian-based distros). So if you use that command to find package name then you could alternatively use following for
package summary:
function summpkg { dpkg -s $(whichpkg $1 | awk -F: '{print $1}'); }
Similar to command 7822, but handles errors gracefully.
The first argument is the interpreter for your script, the second argument is the name of the script to create.
This function is used to set environmental variables from a list of alternatives depending on what's installed on the system. It returns the first program found in the list.
Example usage:
export BROWSER=$(find_alternatives chromium-browser google-chrome opera firefox firefox-bin iceweasel konqueror w3m lynx)
.
export EDITOR=$(find_alternatives vim nano pico emacs kate)
.
export PAGER=$(find_alternatives vimpager less most more pg)
5 helpful aliases for using the which utility, specifically for the GNU which (2.16 tested) that is included in coreutils.
Which is run first for a command. Same as type builtin minus verbosity
alias which='{ command alias; command declare -f; } | command which --read-functions --read-alias'
Which (a)lias
alias whicha='command alias | command which --read-alias'
Which (f)unction
alias whichf='command declare -f | command which --read-functions'
Which e(x)ecutable file in PATH
alias whichx='command which'
Which (all) alias, function, builtin, and files in PATH
alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a'
# From my .bash_profile http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
Uses logger in a while loop to log memory statistics frequently into the local syslog server.
Returns the pathnames of the files which would be executed in the current environment had its arguments been given as a command.