Let's Play in the Terminal! (For Windows Users)
Playing around with the terminal is one of the best ways to get comfortable with the command line and learn new tools and technologies. When you're having fun while familiarizing yourself with new commands and techniques, learning becomes deeper and your confidence grows. The knowledge and skills you gain through play often end up being useful in your actual work.
Windows Terminal
You want to enjoy using the tools you frequently work with, right? Think about learning guitar - if you buy a really cheap one, it might be hard to play and not enjoyable to use, which could ultimately hold back your progress. Similarly, if you don't have a good terminal application, you might end up hating the terminal just because of how clunky it feels to use.
Microsoft provides an official, user-friendly terminal app called "Windows Terminal." It lets you easily switch between different environments like Command Prompt, PowerShell, and Git bash all within the same app. Plus, it handles text selection, copying, and pasting naturally - just select text with your mouse, copy with Ctrl+C, and paste with Ctrl+V, just like you'd expect.
How to Install Windows Terminal:
Here's how to get Windows Terminal set up:
- Open the Microsoft Store from the Start menu
- Type "Windows Terminal" in the search box in the top right
- Select "Windows Terminal" from the search results
- Click the "Get" or "Install" button
That's it - Windows Terminal is now installed!
Package Managers
A package manager is a tool that helps you manage software packages - installing, updating, and removing them all from one place. While they're especially popular on Linux-based systems, Windows users can get in on the action too.
You just specify what software you want to install, and the package manager handles the rest. For example, choco install vscode
is all you need to install Visual Studio Code. This is particularly helpful for command-line tools that might otherwise be tricky to install.
For Windows, there are three popular package managers:
-
Winget: Microsoft's official package manager.
-
Chocolatey: One of the older options with support for tons of software, including GUI applications.
-
Scoop: Focused on user-space installations and giving you more control over your setup.
Installing Winget:
While Winget is relatively new and has fewer supported packages than other package managers (which is why we won't be using it today), it's worth knowing about since it's the official solution. If you're running Windows 10, here's how to get it:
- Open Microsoft Store
- Search for "App Installer"
- Install "App Installer"
Now you can use the "winget" command in Windows Terminal or Command Prompt.
Installing Chocolatey:
To install Chocolatey, you'll need to use the command line. Here's how:
- Open PowerShell as administrator
- Run this command:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
That's it - Chocolatey is installed!
Installing Scoop:
Scoop also installs via command line. Here's how:
- Open PowerShell as administrator
- Run these commands:
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iwr -useb get.scoop.sh | iex
And you're done! Since Scoop works in user space, you actually don't need admin rights for this one.
Fun Commands
Let's face it - even when we're using the command line, we want to have some fun. So let's check out some playful commands: "ntop", "cowsay", "figlet", and "meow".
ntop
ntop is a Windows port of htop, a popular Linux tool. It's a system resource monitor that shows you real-time CPU usage, memory usage, and running processes in a visual way.
You can install it with Chocolatey:
choco install ntop.portable -y
To fire it up, just run the "ntop" command:
ntop
You'll see your system resource usage in real time.
While this tool has practical uses (checking CPU and memory usage by various processes), I'm mainly sharing it today because it makes you feel like a hacker. 😎
cowsay
cowsay generates ASCII art of a cow that "says" whatever text you give it. Here's how to get it:
- Open PowerShell as administrator
- Install it with Scoop using this command:
scoop install cowsay
To use cowsay, just type "cowsay" followed by your message:
cowsay "Moo moo!"
And you'll get a cow saying your message in ASCII art.
figlet
figlet turns your text into big ASCII art letters. Here's how to install it:
- Open PowerShell and run:
choco install figlet-go -y
To use figlet, just type "figlet" followed by your text:
figlet Hello, world!
And you'll get your text in big ASCII letters.
meow
meow is a Windows port of lolcat, a popular Linux command. You can install it through scoop after adding the extras bucket:
scoop bucket add extras
scoop install meow
meow adds rainbow colors to command line output, turning boring black and white text into a colorful display:
meow "Hello, world!"
Your text will appear in rainbow colors!
Combining Commands with Pipes
Pipes are one of those command line features that's both really useful and really fun. A pipe (the "|" symbol) takes the output of one command and feeds it into another command as input. This lets you chain commands together to do more complex operations in a single line.
Let's look at an example using PowerShell's "ls" and "meow" commands.
The "ls" command lists the contents of your current directory. "meow" is the rainbow text command we just learned about. Let's pipe them together:
ls | meow
Here's what that looks like:
We can also combine the fun commands we learned today. This lets us get even more creative with our command line shenanigans.
For example, we can use figlet to turn "Hello, World!" into ASCII art, then pipe it through meow to add colors:
figlet "Hello, World!" | meow
Or we can make our cow say the big ASCII text:
figlet "Hello, World!" | cowsay
And if we're feeling particularly fancy, we can combine all three:
figlet "Hello, World!" | meow | cowsay
This gives us a rainbow-colored ASCII art message being spoken by our ASCII cow!
A Practical Pipe Example
While we've been having fun, let's look at a practical example.
We already used "ls" to list directory contents. Let's combine it with "grep", a text search tool. On Windows, grep comes with Git Bash by default (though you can install it in PowerShell via Chocolatey).
The command looks like this:
ls | grep 'json'
This pipes the output of "ls" into grep, which searches for lines containing "json". In other words, it helps you find files with "json" in their name in the current directory.
Having Fun Online
We can have some online fun too. Here are a couple of cool commands.
First, let's check the weather using the "curl" command, which is a tool for transferring data over networks. Here's how to check the weather in Naha City, Okinawa:
In PowerShell:
(curl "http://wttr.in/Naha%20City,Okinawa,Japan?tqp0").Content
In Git Bash:
curl "http://wttr.in/Naha%20City,Okinawa,Japan?tqp0"
This will show you the current weather, temperature, wind speed, and more for Naha City.
And if you're in the mood for some entertainment, you can watch Star Wars in ASCII art using the "telnet" command:
telnet towel.blinkenlights.nl
This will start an ASCII art animation of Star Wars. Yes, really!
Wrapping Up
Today we've played around with the command line, from making colorful output with "meow" to combining commands with pipes to do more complex operations. We even found ways to check the weather and watch Star Wars right from our terminal!
The command line might seem a bit intimidating at first, but that's just because it's new. Once you learn a few basic commands and get comfortable with them, you'll find that the command line can be both a powerful tool for getting work done more efficiently and a fun playground for tech experiments.
This article was originally published on Qiita.