Display the current weather forecast in the Linux command line.
This will work on any Linux distribution.
A 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
It’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.in is 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.in will 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+York
You can also specify cities the way they’re written in Unix timezones.
$ curl wttr.in/New_York
Don’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.in take 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.in can 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.in will 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
?u to see Fahrenheit or
?m to see Celsius.
$ curl wttr.in/New_York?m $ curl wttr.in/Toronto?u
There’s an odd bug with ZSH that prevents this from working, so you need to use Bash if you want to convert the units.
You can easily incorporate a call to
wttr.in into 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.