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:
Typographically speaking, it's generally the [accepted wisdom][1] that about 60 characters per line makes for optimal reading (would that more Web pages followed this convention!). I know I got tired of reading manpages with text as wide as my screen! However, the command above sets manwidth to 70 rather than 60 because paragraphs in manpages are generally indented.
I recommend the following snippet for your .${SHELL}rc, which sets manwidth to 70 unless your terminal is smaller than 70 characters:
function man () {
if [[ $COLUMNS -gt 70 ]]; then
MANWIDTH=70 command man $*
else
command man $*
fi
}
[1]: https://en.wikipedia.org/wiki/Column_(typography)
Add the followin to ~/.bashrc
#colour
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;37m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'
Read all chapters up to 'Jumping', improve your effectiveness of wirking in terminal.
Most useful are the Moving and Searching commands
As odd as this may be, I know of servers where the man(1) command is not installed, and there is not enough room on / to install it. However, zcat(1), nroff(1) and less(1) are. This is a way to read those documents without the proper tool to do so, as sad as this may seem. :)
Find the usage of a switch with out searching through the entire man page.
Usage: manswitch [cmd] [switch]
Eg:
manswitch grep silent
____________________________
In simple words
man <cmd> | grep "\-<switch>"
Eg:
man grep | grep "\-o"
This is not a standard method but works.
Simple edit to work for OSX.
Now just add this to your ~/.profile and `source ~/.profile`
Quick and dirty version. I made a version that checks if a manpage exists (but it's not a oneliner). You must have ps2pdf and of course Ghostscript installed in your box.
Enhancements appreciated :-)
This microscript looks up a man page for each word possible, and if the correct page is not found, uses w3m and Google's "I'm feeling lucky" to output a first possible result. This script was made as a result of an idea on a popular Linux forum, where users often send other people to RTFM by saying something like "man backup" or "man ubuntu one". To make this script replace the usual man command, save it as ".man.sh" in your home folder and add the following string to the end of your .bashrc file:
alias man='~/.man.sh'
when we work with terminal often we open man pages for help if we did some mistakes
and when we want to open the man page for command we are working with this one helps
as many people may be knowing that '!!' performs the last command action
we use it in sudo !! to perform the last action with root previleages
man !! will also be helpful and handy
thanx
Another one.
Maybe not the quicker because of the sort command, but it will also look in other man sections.
updated with goodevilgenius 'shuf' idea
I'm not sure why you would want to do this, but this seems a lot simpler (easier to understand) than the version someone submitted using awk.
Build an awk array with all commands and then select a random one at the end.
This avoids spawning extra processes for counting with wc or generating random numbers.
Explicitly call /bin/ls to avoid interactions with aliases.
Great idea camocrazed. Another twist would be to display a different man page based on the day of the year. The following will continuously cycle through all man pages:
man $(ls /bin | sed -n $(($(date +%j) % $(ls /bin | wc -l)))p)
Broaden your knowledge of the utilities available to you in no particular order whatsoever! Then use that knowledge to create more nifty one-liners that you can post here. =p
Takes a random number modulo the number of files in $dir, prints the filename corresponding to that number, and passes it as an argument to man.
This takes quite a while on my system. You may want to test it out with /bin first, or background it and keep working.
If you want to get rid of the "No manual entry for [whatever]" and just have the [whatever], use the following sed command after this one finishes.
sed -n 's/^No manual entry for \(.*\)/\1/p' nomanlist.txt
If I type 'man something', I want it to find the manpage in the same order as my PATH.
You can add something like this to your .bashrc
#
# Add my MacPorts, my personal utilities and my company utilities to my PATH.
export PATH=$PATH:/opt/local/bin:$HOME/bin:/our_company_utils/bin/
# Now set the manpath based on the PATH, after man(1) parses man.conf
# - No need to modify man.conf or manually modify MANPATH_MAP
# - Works on Linux, FreeBSD & Darwin, unlike /etc/manpaths.d/
# Must unset MANPATH first. MANPATH is set on some systems automatically (Mac),
# which causes manpath to ignore the values of PATH like /opt/local/bin (MacPorts).
# Also MANPATH may be deprecated. See "SEARCH PATH FOR MANUAL PAGES" in man(1)
unset MANPATH
# manpath acts differently on Solaris, FreeBSD, MacOSX & GNU. This works everywhere.
manpath >/dev/null
#
Note that MacOSX, FreeBSD & Linux have fancier ways to do some of this. (e.g. 'man --path' or 'man -q'), but this command is more universal and should work everywhere.
Quicker way to search man pages of command for key word
Prepends paths containing man directories to your MANPATH variable for the given top level directory. If you build or install software with non-standard documentation locations, you can just add them to your MANPATH with this little function. -xdev prevents crossing filesystem boundaries when searching for man dirs.
Example :
LC_ALL=C man less | less +/ppattern