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.
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:
This provides a way to sort output based on the length of the line, so that shorter lines appear before longer lines. It's an addon to the sort that I've wanted for years, sometimes it's very useful. Taken from my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
1.) my profile ends with $USER not with .default
2.) only grep for the first occurrence because some extensions have the translated name also inside the install.rdf
What was the name of that module we wrote and deleted about 3 months ago? windowing-something?
git log --all --pretty=format:" " --name-only | sort -u | grep -i window
The same as the other two alternatives, but now less forking! Instead of using '\;' to mark the end of an -exec command in GNU find, you can simply use '+' and it'll run the command only once with all the files as arguments.
This has two benefits over the xargs version: it's easier to read and spaces in the filesnames work automatically (no -print0). [Oh, and there's one less fork, if you care about such things. But, then again, one is equal to zero for sufficiently large values of zero.]
If you use HISTTIMEFORMAT environment e.g. timestamping typed commands, $(echo "1 2 $HISTTIMEFORMAT" | wc -w)
gives the number of columns that containing non-command parts per lines.
It should universify this command.
find -exec is evil since it launches a process for each file. You get the total as a bonus.
Also, without -n sort will sort by lexical order (that is 9 after 10).
This is a very simple and lightweight way to play DI.FM stations
For a more complete version of the command with proper strings in the menu, try: (couldnt fit in the command field above)
zenity --list --width 500 --height 500 --title 'DI.FM' --text 'Pick a Radio' --column 'radio' --column 'url' --print-column 2 $(curl -s http://www.di.fm/ | awk -F '"' '/href="http:.*\.pls.*96k/ {print $2}' | sort | awk -F '/|\.' '{print $(NF-1) " " $0}') | xargs mplayer
This command line parses the html returned from http://di.fm and display all radio stations in a nice graphical menu. After the radio is chosen, the url is passed to mplayer so the music can start
dependencies:
- x11 with gtk environment
- zenity: simple app for displaying gtk menus (sudo apt-get install zenity on ubuntu)
- mplayer: simple audio player (sudo apt-get install mplayer on ubuntu)
This shows you which files are most in need of commenting (one line of output per file)
I created this command to give me a quick overview of how many file types a directory, and all its subdirectories, contains. It works based off file extension, rather than file(1)'s magic output, because it ended up being more accurate and less confusing.
Files that don't have an ext (README) are generally not important for me to want to count, but you're free to customize this fit your needs.
This searches the Apache error_log for each of the 5 most significant Apache error levels, if any are found the date is then cut from the output in order to sort then print the most common occurrence of each error.
This command will return a full list of Error 404 pages in the given access log. The following variables have been given to awk
Hostname ($2), ERROR Code ($9), Missing Item ($7), Referrer ($11)
You can then send this into a file (>> /path/to/file), which you can open with OpenOffice as a CSV
Finds the top ten pages returning an http response code of 404 in an apache log.
Get a list of all the unique hostnames from the apache configuration files. Handy to see what sites are running on a server. A slightly shorter version.
Most of the "most used commands" approaches does not consider pipes and other complexities.
This approach considers pipes, process substitution by backticks or $() and multiple commands separated by ;
Perl regular expression breaks up each line using | or < ( or ; or ` or $( and picks the first word (excluding "do" in case of for loops)
note: if you are using lots of perl one-liners, the perl commands will be counted as well in this approach, since semicolon is used as a separator