In my previous article, I introduced Bash for Windows 10. Since then, I have been playing with Bash on my primary Windows 10 computer (a Surface Pro 3) and I am amazed by all the opportunities it provides. In this post, I would like to talk about some cool things you can do with Bash on Windows 10.
Avatar
Follow me:
Latest posts by Anil Erduran (see all)

Some of such cool things are native Linux tasks, which we are now able to test on Windows, and some things are present just for fun. In general, however, I believe that Bash is a new way for Windows Administrators to extend their abilities and is a great addition for Linux Administrators with regard to their developer environments.

Monitor system resources and performance

It’s crucial for system administrators to monitor system resources and performance on a daily basis. Most of the important monitoring and debug commands on the native Linux distros also work on Windows 10 Bash.

The top command is a good way to see the running processes in an ordered list and get an overview of the load on your computer. It’s a dynamic output and updates continuously.

Top command

Top command

LSOF shows open files, with some additional details such as User, Size, Type, etc.

LSOF to show open files

LSOF to show open files

You can also use HTOP, which is a much more advanced process monitoring tool. It’s not installed by default on Windows 10 Bash, but you can simply install it using the following command:

sudo apt-get install htop
HTOP tool

HTOP tool

Also, with the simple command free, you can check how much memory you have available.

Freeing Memory on Bash

Freeing Memory on Bash

You can also run the following one-liner with the popular Linux command awk to see the available physical memory in KB:

Showing physical memory

Showing physical memory

Using native SSH

By executing the ssh command, you are able to start to play with SSH in Windows Bash.

SSH usage in Bash

SSH usage in Bash

In the example below, I established an SSH connection to my Azure Ubuntu server from Windows 10 Bash:

SSH from Bash to Azure

SSH from Bash to Azure

Python

Python is my second favorite scripting language (my absolute favorite is  PowerShell). It’s very easy to transfer your PowerShell knowledge into Python as its syntax and logic are quite similar to that of PowerShell.

Python v2 and v3 come pre-installed with Ubuntu, which means that the Bash on your Windows 10 Insider build also has Python installed by default.

Checking Python version

Checking Python version

In Python, you can begin coding right away by simply typing “Python” or “Python3”.

Print command in Python

Print command in Python

One way to install and manage packages in Python is to use PIP (Preferred Installer Program). To install PIP with the dev tools, run the below command on your Bash:

Installing PIP and Devtools

Installing PIP and Devtools

And there you have it. You now have a ready-to-go Python environment on your Windows 10 computer. Are you interested in game development? Why not install the PYGame module? Here is a list of useful modules you can start with.

Machine learning libraries

Well, there are a bunch of open source projects or efficient tools for data mining and data analysis but Python is probably one of the most versatile languages out there for machine learning. Moreover, Python and most of its machine learning libraries are free.

Scikit-learn is a free library for machine learning the Python language. It features various classification, regression, and clustering algorithms.

You can follow the instructions from the guide here to install it on your Windows 10 Bash, just as you would if you were using a Linux machine.

Installing the required packages for SciPy is the first step. SciPy is a Python-based ecosystem of open source software for mathematics, science, and engineering.

Installing PIP and Devtools

Installing PIP and Devtools

You can use PIP to install Scikit-learn:

Installing Scikit-Learn

Installing Scikit-Learn

You are now ready to go with your machine learning project on your Windows 10.

Scikit-learn has some built-in datasets for the classification and regression of supervised learning problems.

The following code sample will load iris and digits pre-built datasets:

ML Code Sample in Bash - Python

ML Code Sample in Bash - Python

Digits.data shows the features that can be used to classify the digits samples.

I’m not a machine learning guru but it’s pretty awesome to be able to use open source libraries and machine learning packages without leaving your Windows 10 machine.

Node.js

Node.js is a popular open source runtime environment for developing web applications which can run on a wide variety of endpoints and devices.

Node.js is also installed on Windows 10 Bash by default. I just updated it using the apt-get upgrade -y nodejs command.

Checking Node.js on Bash

Checking Node.js on Bash

Let’s check the version number and see where our node is installed:

Checking Node.js version

Checking Node.js version

You can give it a try using a basic console.log command under node:

console.log command for Node

console.log command for Node

Node Package Manager

NPM is the package manager that developers use to share and reuse code. This reusable code comes in packages. You can search for packages in online repositories, use the command line to install them, and then do version management. In that way, you can also easily install Node.js applications.

Node.js comes with NPM installed, so you don’t need to worry about installing it separately on Windows 10.

Checking NPM on Bash

Checking NPM on Bash

Let’s check again where it’s installed and what version we have:

NPM version

NPM version

Listing of current packages on Bash (I just installed the node-PowerShell package):

Listing NPM Packages

Listing NPM Packages

You can search for packages online using the NPM search command. A local index will be built when you first run the command.

Searching for NPM packages

Searching for NPM packages

Azure CLI NPM Package

So now we have Node.js, NPM, and an Ubuntu Bash. Why don’t we use Azure cross platform CLI tools to interact with our Azure resources?

You can easily install the Azure-CLI from the NPM repository, which requires Node.js and NPM as prerequisites. In our case, we have everything in place on our Windows 10 Bash! Let’s start with the installation of the Azure CLI NPM package.

Installing Azure CLI

Installing Azure CLI

Symbolic link error

Symbolic link error

The error message "node: No such file or directory" is a known issue. To resolve this error, we need to create a symbolic link to /usr/bin/node by running the command below:

sudo ln -s /usr/bin/nodejs /usr/bin/node

Now we are ready to go. Type “Azure”.

Azure CLI Help

Azure CLI Help

We can use the Azure CLI to connect to our Azure Subscription.

The Azure Login command will create an authentication code so that you can use it on http://aka.ms/devicelogin.

Azure authentication

Azure authentication

And I’m now connected to my subscription in Bash.

Connecting to Azure Subscription

Connecting to Azure Subscription

You can use two different command modes with the Azure CLI: Service Management and Resource Manager. Use the following command to set the command mode to ARM:

Setting command mode to ARM

Setting command mode to ARM

The next command lists my accounts:

Listing accounts on Azure CLI

Listing accounts on Azure CLI

For other available Azure CLI commands, please read this:

Azure CLI commands in Azure Service Management (ASM) mode

Azure CLI commands in Resource Manager mode

Using VIM editor and finding the Easter egg

VIM is the enhanced version of vi, which is a popular text editor in Linux. There are several modes of VIM such as Command Mode, Insert Mode, and Visual Mode.

VIM is already installed on Windows 10 Bash and it supports all modes. You can also the use apt-get command to check whether you are using the latest version.

Checking VIM installation

Checking VIM installation

Type “VIM” to start, and play with it.

VIM Console

VIM Console

Here are the basic commands you can start with:

h — moves left

l — moves right

j — moves down

k — moves up

:help — open help

:q — quit Vim

:wq — save and quit Vim

:q! — quit without saving

:w — saves the current file

There is also an Easter egg in VIM help file. Type “:help 42” to access a special help menu (a quote from Douglas Adams, the author of The Hitchhiker's Guide to the Galaxy).

Easter Egg in VIM

Easter Egg in VIM

Aliases

By default, the alias command shows a list of aliases in Bash that are defined for the current user.

Listing default aliases

Listing default aliases

To create your own alias, you can use following command:

Create custom alias

Create custom alias

To clear my screen, I simply configured “c”.

In the next post in this series, I will show you a few fun things that you can do with the Windows 10 Bash.

2 Comments
  1. Avatar
    Vince Sh 7 years ago

    While Bash in Windows 10 is a neat idea, MobaXterm has been available for several years and works on all modern versions of Windows. MobaXterm is a single executable that provides Bash, SSH, PowerShell, X-Windows, RDP, SFTP, Serial, etc, etc, etc. The personal version is free for non-corporate use. A paid-Professional version is also available for corporate use are a very reasonable cost.

    http://mobaxterm.mobatek.net/

    Vince

  2. Avatar
    mousse 7 years ago

    Function keys not working.. What can I do?

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account