This command outputs a table of sighting opportunities for the International Space Station. Find the URL for your city here: http://spaceflight.nasa.gov/realdata/sightings/ Show Sample Output
This uses Perl's rename utility (you may have to call it as prename on your box) and won't choke on spaces or other characters in filenames. It will also zero pad a number even in filenames like "vacation-4.jpg".
This command finds and prints all the symbolic and hard links to a file. Note that the file argument itself be a link and it will find the original file as well.
You can also do this with the inode number for a file or directory by first using stat or ls or some other tool to get the number like so:
stat -Lc %i file
or
ls -Hid file
And then using:
find -L / -inum INODE_NUMBER -exec ls -ld {} +
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)
Ruby version.
Also, a perl version:
perl -e 'printf("%.2x.",rand(255))for(1..5);printf("%.2x\n",rand(255))'
This command turns a multi-line file into a single line joined with <SOMETEXT>. To skip blank lines, use:
perl -pe '(eof()||s/^\s*$//)||s/\n/<SOMETEXT>/g' file.txt
Show Sample Output
I took matthewbauer's cool one-liner and rewrote it as a shell function that returns all the suggestions or outputs "OK" if it doesn't find anything wrong. It should work on ksh, zsh, and bash. Users that don't have tee can leave that part off like this:
spellcheck(){ typeset y=$@;curl -sd "<spellrequest><text>$y</text></spellrequest>" https://google.com/tbproxy/spell|sed -n '/s="[1-9]"/{s/<[^>]*>/ /g;s/\t/ /g;s/ *\(.*\)/Suggestions: \1\n/g;p}';}
Show Sample Output
I use this alias in my bashrc. The --vi-keys option makes info use vi-like and less-like key bindings.
Converts reserved characters in a URI to their percent encoded counterparts.
Alternate python version:
echo "$url" | python -c 'import sys,urllib;print urllib.quote(sys.stdin.read().strip())'
Show Sample Output
This shell function grabs the weather forecast for the next 24 to 48 hours from weatherunderground.com. Replace <YOURZIPORLOCATION> with your zip code or your "city, state" or "city, country", then calling the function without any arguments returns the weather for that location. Calling the function with a zip code or place name as an argument returns the weather for that location instead of your default.
To add a bit of color formatting to the output, use the following instead:
weather(){ curl -s "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=${@:-<YOURZIPORLOCATION>}"|perl -ne '/<title>([^<]+)/&&printf "\x1B[0;34m%s\x1B[0m: ",$1;/<fcttext>([^<]+)/&&print $1,"\n"';}
Requires: perl, curl
Show Sample Output
This function takes a word or a phrase as arguments and then fetches definitions using Google's "define" syntax. The "nl" and perl portion isn't strictly necessary. It just makes the output a bit more readable, but this also works:
define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Po '(?<=<li>)[^<]+';}
If your version of grep doesn't have perl compatible regex support, then you can use this version:
define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Eo '<li>[^<]+'|sed 's/<li>//g'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null;}
Show Sample Output
This is a command that I find myself using all the time. It works like regular grep, but returns the paragraph containing the search pattern instead of just the line. It operates on files or standard input.
grepp <PATTERN> <FILE>
or
<SOMECOMMAND> | grepp <PATTERN>
Show Sample Output
This command, taken from play's manual page, plays a synthesized guitar tone for each of the strings on a standard tuned guitar. The command "play" is a part of the package "sox".
This function displays the latest comic from xkcd.com. One of the best things about xkcd is the title text when you hover over the comic, so this function also displays that after you close the comic.
To get a random xkcd comic, I also use the following:
xkcdrandom(){ wget -qO- dynamic.xkcd.com/comic/random|tee >(feh $(grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}'))|grep -Po '(?<=(\w{3})" title=").*(?=" alt)';}
This uses mpg123 to convert the files to wav before burning, but you can use mplayer or mencoder or ffmpeg or lame with the --decode option, or whatever you like.
Substitute feh for the image viewer of your choice. display (part of imagemagick) seems to be a popular choice.
This bash function uses albumart.org to find the cover for an album. It returns an amazon.com url to the image.
Usage: albumart [artist] [album]
These arguments can be reversed and if the album name is distinct enough, it may be possible to omit the artist.
The command can be extended with wget to automatically download the matching image like this:
albumart(){ local x y="$@";x=$(awk '/View larger image/{gsub(/^.*largeImagePopup\(.|., .*$/,"");print;exit}' <(curl -s 'http://www.albumart.org/index.php?srchkey='${y// /+}'&itempage=1&newsearch=1&searchindex=Music'));[ -z "$x" ]&&echo "Not found."||wget "$x" -O "${y}.${x##*.}";}
Show Sample Output
This command lets you select from 10 different BBC stations. When one is chosen, it streams it with mplayer. Requires: mplayer with wma support.
This function uploads images to http://omploader.org and then prints out the links to the file.
Some coloring can also be added to the command with:
ompload() { curl -F file1=@"$1" http://omploader.org/upload|awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;sub(/^/,"\033[0;34m");sub(/:/,"\033[0m:");print}';}
Show Sample Output
This is a kind of wrapper around the shell builtin cd that allows a person to quickly go up several directories. Instead of typing: cd ../.. A user can type: cd ... Instead of: cd ../../.. Type: cd .... Add another period and it goes up four levels. Adding more periods will take you up more levels.
commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.
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: