With the release of the Anniversary Update for Windows 10, Microsoft announced the Windows Subsystem for Linux (WSL) – a way to run real, native Bash on Windows 10, which supports executing native Linux binaries. It does this by running a user-mode Ubuntu Linux image on top of Windows.
This means that you can run Linux command-line tools such as
chmod. Since you are running genuine Ubuntu underneath, running
lsb-release -a will give you the following output:
You can use
apt-get and friends to install utilities such as
tmux, or even play a game of
Keep in mind, however, that this system is in beta and not intended for server workloads. It is only a tool for developers (and enthusiasts) to test out their Linux-centric applications on Windows without modifications. This is also not a tool intended to run Linux GUI applications or environments such as Gnome or KDE, although that is possible too with certain hacks. Having cleared that out, let’s take a look at how the Linux shell works in Windows 10.
Windows Subsystem for Linux (WSL)
According to the official documentation, “WSL is a collection of components that enables native Linux ELF64 binaries to run on Windows”. It does that by implementing a virtualized Linux kernel interface on top of the Windows NT kernel. That is, it does not use any code from the actual Linux kernel – whenever an application makes a Linux-specific system call (syscall), WSL translates it to the equivalent Windows syscall, which then does all the heavy lifting.
Differences from Virtual Machines and Cygwin
Now let’s take a look at how Linux Bash Shell on Windows 10 is different compared to the likes of virtual machines and Cygwin.
You might be thinking, “Well, why use this? Why not just use a Linux VM in Windows?”
Compared to a virtual machine, WSL uses fewer resources. It also lets you work with your files as you would on Linux, while giving you complete access to the underlying Windows filesystem without having to rely on shared folders or network shares.
Another popular method of running popular Linux/Unix-like tools on Windows is Cygwin. The biggest difference between the two approaches is that Cygwin is not a way to run native Linux binaries on Windows. It only provides a set of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.
On the other hand, WSL tools are native Linux ELF-64 compiled binaries running on Windows. For example, running an
apt-get install emacs command in WSL will download and install the same files as on an Ubuntu 14.04 installation, from the official Ubuntu repositories.
Users, Permissions and File Systems in WSL
File System Hierarchy
WSL is installed under the current user’s
%LocalAppData%\lxss\rootfs directory. This is known as the WSL Environment and acts as the Linux “
/”(root) directory. For example, if your username on Windows is
beebom, Linux’s root directory will be located in
C:\Users\beebom\AppData\Local\lxss\rootfs. This means that each Windows user can have their own WSL environment, and can make changes such as
apt-get install software packages, without affecting other Windows users.
It is possible to access the underlying Windows file system in WSL. All drives are mounted under
/mnt. For example,
C:\ is mounted under
D:\ is mounted under
Users and Permissions
When you first install WSL, it will prompt you to create a new default Linux user. This user need not have the same name as the current Windows user, and is treated as a separate entity in general. You can even create multiple Linux users, controlled by a single Windows user.
It is possible to obtain
root privileges using the
sudo command. Keep in mind that being
root in WSL only impacts the user’s rights within the Linux environment and filesystem – they have no impact on the Windows privileges granted. For example, a WSL session with Windows admin privileges may
cd /mnt/c/Users/Administrator while a Bash session without admin privileges would see Permission Denied. Typing
sudo cd /mnt/c/Users/Administrator will not grant access to the Administrator’s directory since the permissions are restricted by Windows.
Linux-Specific File System Features
Linux is a case-sensitive system. That means that
Photo.png are treated as two different files. While Windows is not case sensitive by default, it is still case aware. Which means that while
Photo.png are not treated as two distinct files, it certainly is aware of the difference in case.
WSL handles case-sensitivity just like on Linux. It is even possible to create two files whose name only differs by case outside of the WSL environment. Keep in mind, however, that many Windows applications cannot handle such situations and may not be able to open one or both of the files.
Similarly, symbolic links are supported, provided you are running an NTFS file system. However, symbolic links will work only inside WSL and cannot be resolved by other Windows applications.
Linux also supports nearly all special characters inside file names, while Windows is more restrictive. WSL, however, allows using such special characters, provided that they are restricted to the Linux system’s environment.
SEE ALSO: How to Sync Your OneDrive Account on a Linux Computer
Ready to Run the Linux Command Line on Windows?
So, that’s how Ubuntu Bash or Linux Bash Shell, also known as Windows Subsystem for Linux works on Windows 10 (with the Anniversary update). Along with its working, we also learned how it is different and better than the traditional methods of running Linux-specific commands on Windows. So, if you have always wanted to use Linux commands, get started and if you have questions, comments, or tips, make sure to let us know in the comments section.