ObjectiveDisplay the current weather forecast in the Linux command line.
DistributionsThis will work on any Linux distribution.
RequirementsA working Linux install with an Internet connection.
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
- $ - requires given linux commands to be executed as a regular non-privileged user
IntroductionIt's be convenient to be able to retrieve the latest weather forecast right from your terminal without opening up a web browser, wouldn't it? What about scripting it or setting a cron job? Well, you can.
http://wttr.inis a website that allows you to search for weather forecasts anywhere in the world, and it displays he results in ASCII characters. By using
cURL, you can access
http://wttr.in, you can get your results directly in the terminal.
Get Your Local Weather
It's really simple to grab your local weather.
wttr.inwill automatically try to detect your location based on your IP address. It's reasonably accurate, unless you're using a VPN, of course.
$ curl wttr.in
Get Weather By City
Now, if you would like the weather in a different city, you can specify that with a slash at the end of
wttr.in. Replace any spaces in the name with a
$ curl wttr.in/New+YorkYou can also specify cities the way they're written in Unix timezones.
$ curl wttr.in/New_YorkDon't use spaces unless you like strange and inaccurate results.
Get Weather By Airport
If you're familiar with the three letter airport codes in your area, you can use those too. They might be closer to you and more accurate than the city in general.
$ curl wttr.in/JFK
You can have
wttr.intake a guess on the weather base on a landmark using the
$ curl wttr.in/~Statue+Of+Liberty
Weather From A Domain Name
Did you ever wonder what the weather is like where LinuxConfig is hosted? Now, now you can find out!
wttr.incan check weather by domain name. Sure, it's probably not the most useful feature, but it's still interesting none the less.
$ curl firstname.lastname@example.org
Changing The Temperature Units
wttr.inwill display temperatures in the units(C or F) used in your actual location. Basically, in States, you'll get Fahrenheit, and everyone else will see Celsius. You can change that by adding
?uto see Fahrenheit or
?mto see Celsius.
$ curl wttr.in/New_York?m $ curl wttr.in/Toronto?uThere's an odd bug with ZSH that prevents this from working, so you need to use Bash if you want to convert the units.
Closing ThoughtsYou can easily incorporate a call to
wttr.ininto a script, cron job, or even your MOTD. Of course, you don't need to get that involved. You can just lazily type a call in to this awesome service whenever you want to check the forecast.