Home » Internet » 10 Unix Commands to Use with the New Windows Terminal

10 Unix Commands to Use with the New Windows Terminal

by Pratik
0 comment

Until a year or so, Microsoft seems to be headed in the right direction. First, the inclusion of Linux Subsystem in the DOS Command Line. Next, transferring Microsoft Edge to Chromium and lately, Your Phone Companion app is seeing huge upgrades to increase Android compatibility. The recent good news has been the “new Windows Terminal”. The developer build is available to download through the Microsoft Store. The pleasing thing about this is it can run Windows, Powershell, and Unix commands under one console.

But, with all these overwhelming additions what are the Unix commands you should really know? So, here are the most essential commands to use with the new Windows terminal.

The new Windows Terminal is different from the Windows Subsystem for Linux and Ubuntu Virtual Machine.

What’s new with the Windows Terminal

The new Windows terminal has the following upgrades

  • Copy paste right of the box for PowerShell, cmd
  • Multi-tab support
  • Support emoji and GPU-based text rendering.
  • Supports multiple profiles

Unix Commands to use with the new Windows terminal

You have to switch to Ubuntu to run all of these commands. Alternatively, you can also type “bash” and get to the Unix Shell from the Powershell and cmd window as well.

1. cat & vi

Windows cmdlet doesn’t let you edit or view the text file within the terminal itself. Now with the new terminal, you can use the command cat or vi to view or edit the file within the terminal. The new terminal supports all the Unix native text editors such as nano, vi, vim or ed.

Example: cat abc.txt

nano-editor

2. cp or mv

Just like the Windows native copy and move command, you also have ‘cp’ and ‘mv’ in the Unix terminal. The only major difference is that cp and mv support much more switches than the native Windows commands. For example, you can create hard links and soft links of files with these commands. In case you don’t know, soft links are pointers which redirect the contents of the original file whereas hard link is a mirror copy of the original file. Soft links cannot exist without the original file whereas hard link can still present data.

Example: cp -sv /root/temp/photos /root/current/photos

soft-link-copy

3. tar

Windows lets you zip the file via command line but it cannot handle tars or bzip. With Unix, you get a native command line utility called tar which can perform zipping and unzipping alone. It supports a number of zip formats and you can even specify the compression ratio and algorithm while creating the zip. In case you don’t have tar built into the bash, install it by running the command sudo apt update && sudo apt-get install tar.

Example: tar -cvf test.zip abc.txt

tar-command-cvf

4. man

Back in college when I was learning Unix, man command used to be a life-saver to get through practicals. Now, comparing that to Windows help entry, it has always been fuzzy. The good thing about the new Windows terminal is that it supports ‘man’ ie. manual entry for commands. Although these manual entries are only for the Unix Commands, nonetheless it is extremely helpful for users coming from Windows.

Example: man vim

man-vim-command

5. type

type is an extremely useful utility in Unix. As a beginner, it lets you distinguish functions, aliases, and keywords reserved in Unix. You just have to suffix the command with type keyword and it tells you the location of the file or alias. The type command also allows you to append multiple commands and run to get a summarized output.

Example: type date ls test

type-command

6. ps & kill

The ps command works the same as tasklist in Windows. It displays the currently running processes by users connected to the system. It is easier to identify processes and then kill jobs if they’re causing any lock. My frequently used switch with ps command is ps -aux as it tells me the user path running the command with all the memory and CPU consumption. You can further use the kill command to kill the session by PID.

Example: ps -aux && kill 338

ps-and-kill

7. df & du

Windows didn’t have a dedicated command line utility to give you disk file usage or disk free space. The workaround was through dir command. But, with Unix in you have the “df”and “du” utility. df command tells you about the free space of the Linux filesystem whereas du tells you the space utilization of individual files and directories. I used the df command coupled with crontab to send me disk space alerts on my server.

Thankfully, df also gives you insights about the windows file system but the naming convention is IFS.

Example: df -h

df-command

Read: 15 Windows 10 File Explorer Tips and Tricks to Use It like a Pro

8. apt-get

Windows never had a good package manager and I had to resort to Chocolatey which was okayish to the max. But now, with the new Windows terminal, it is convenient and efficient to use apt-get. This also enables you to use all the apt-get command line utilities like ffmpeg, youtube-dl, sox on Windows. My favorite one is ffmpeg which lets me encode video or audio quickly with just a single command.

Example: sudo apt-get install sox

apt-get-install-sox

9. wget

wget is another command line utility that lets you download contents from the web server. It might not be added natively so you will have to download it via apt-get. It supports downloading via HTTP, HTTPS, and FTP. Its features include recursive download, conversion of links for offline viewing of local HTML, and support for proxies.

Example: wget example.com

wget-example

10. crontab

You can consider crontab as a command-line version of Windows Task Scheduler. It lets you schedule a command to run at a particular time, day of the week or month. If you incorporate a shell script in the command, you can do multiple tasks repetitively using crontab. I have used the crontab a lot back in the days to automate tasks on an AIX server. Assume, you want a chime to run every single hour, you can do that using crontab.

Also, crontab doesn’t alert you if the job has not run or the command has failed. So, you need to manually log the output of the crontab to a log file.

Example: crontab -e

crontab

11. Shell Scripts

The most important purpose that the new Windows terminal serves is scripting. The new terminal allows you to run shell scripts, PowerShell scripts, batch scripts, etc. Especially, I love shell scripting and its a sigh of relief to use it over PowerShell. I have always disliked scripting for Windows in PowerShell as the cmdlets are so complicated with those long switch names. On the other hand, a shell script is simple with the amalgamation of normal Unix commands.

For example, if I want to find out logged in users on my server, I need to write a long script in PowerShell whereas shell script can do that for me in a single command.

#!/bin/bash
echo "There are `users | wc -w` users logged in"

users-shell-script

Wrapping Up

We can expect some major upgrades in this edition of Windows Terminal. The changes can be visual or functional and I will be regularly updating this article incorporating all these changes. For any queries or questions, let me know in the comments below and I will get back to you.

Also Read: Top 6 Useful DOS Commands That You Should Know

You may also like

Leave a Comment