The Shell (aka the Command Prompt, command line, Terminal)

author: Sabine Bartsch | version: 2021-10-02

The Shell, also known as the Command Prompt in Windows (German: Eingabeaufforderung) or Terminal in MacOS and Linux, provides access to commands and tools that are not accessible via the graphical user interface, but have to be called by means of command line parameters. Many professional tools in linguistics have to be called from the command line. It is thus very important for students of linguistics to familiarize themselves with the command line. In this tutorial, we are introducing the basic functionality of the command line that is necessary for navigation in the file system, for creating and deleting files and directories and for data inspection and manipulation without a graphical user interface. In a second step, we are providing some examples of useful tools that are becoming accessible through the command line. We are hoping to encourage users who are chiefly used to operating a computer via the functionality of the graphical user interface (GUI) to use the command line proficiently and to their advantage.

Calling the Shell from the Windows GUI

There are different ways of cranking up the shell from the Windows GUI. We are introducing the two most important ones here to get you started:

Calling the Shell from the Program menu

The simplest way of calling the command line or shell is via the Program menu.

Click on the START button - click on Programs - navigate to Accessories and then click on the Command icon. This opens up a windows with a black background and white characters. This is the shell or command line. When first opened, it shows some text including, at the very top, information on the version of Microsoft Windows you are running on your computer. The cursor is blinking behind a chain of characters called the command prompt, short prompt. It tells you where in the file system you are currently working, the so-called working directory. On my computer, it looks like this:

C:\Users\sabine\

Calling the Shell from the Search ... dialogue

Users can also call the shell from the desktop search dialogue in the bottom left corner of the menu that opens up when they click the Start button in Windows. Type the three letters cmd (short for command line) into that search box and the command line Window shown above opens up.

These two ways of calling the command line from the Windows GUI are entirely equal, you can choose which approach suits your preferences.

Users may find the second approach very convenient because it also allows you to call up other programs from the keyboard. This is especially appealing for keyboard focused people like myself. Try it by just typing the name of a program into the box and see what happens …. As an example, type “Excel” and Windows will navigate you to the Excel icon that allows you to open up Microsoft Excel. If there is more than one program with the letter sequence you typed in, Windows will show you all potential options of programs with that letter sequence in the name on the menu, and only these. You can verify this letter option by typing in “Word”, very likely, Windows will offer you Microsoft Word (if installed on your machine) and WordPad, one of the standard editors offered as a default by Microsoft Windows.

Alternative Shell options

In addition to the basic Command Prompt there a also alternatives with added functionalities. In the Windows world, the so-called PowerShell (note: shell is an alternative term for terminal) features prominently here. The PowerShell comes with powerful additional functionalities such as its own in-built scripting language which is effectively like a programming language in its own right. You do not need to know this scripting language, though, in order to use the PowerShell as an alternative terminal. One reason you will see me use it in my teaching is that the commands used are similar to those sed in the Linux world, e.g. ls for listing the directory contents.

Some useful basic commands

Some of the most important functions you will need to use on the command line are displaying directory contents and navigation between directories. Here are some of the options in tabular form:

command semantics prose description example
dir directory contents show contents of the present directory; equivalent to ls in the Windows Powershell or the MacOS Terminal or Linux dir
ls list directory contents show contents of the present directory, alternative to dir, works in Powershell and Mac OS and Linux terminal ls
cd change directory change to the directory in the parameter cd /temp
cd .. change one directory down moves one directory down in the directory tree
cd / change to root (c:\) change directory down to the root directory of the drive (e.g. to c:\) cd /
md make directory creates a new directory under the current working directory md /temp
rd remove directory removes the specified directory, use with extreme caution, there is no simple way of recovering, no back button rd /temp

Please make sure you get your head around where your files are stored. This may not seem the most appealing pass-time for most of you, but in order to keep your files organized also with a view to back-up and later submissions, it is vital that you get a sense of how your computer's file system is organized and where your files are stored.

4. Usability functions

4.1 Auto completion

A nice and often overlooked feature of the Windows command line – and indeed most all terminals or shells – is the *Auto completion*. When you're typing in long file or directory names, you will find that you often make typing mistakes and every time you make a mistake, your command will fail because the operating system has no clue what you mean. This is one of the most frustrating experiences for novice command line users on any operating system as well as for programming apprentices. However, the developers of operating systems offer you some help. When you start typing in a command, you can hit the tabulator button after the first few letters and the system will complete the character sequence you started with a completion of either file or directory names that are available in the present working directory. If there are several possibilities, repeatedly tapping the tabulator key will iterate through the available options. The best way to explore this function is to try it for yourself. Open up the command line and you'll be in the default working directory of your user. On my computer that is:

c:\Users\YOURNAME

Now type in cd Do

then hit the tabulator button and Windows completes this as

Documents

which is your folder Documents

or German

Eigene Dokumente

Hit the return button and the system changes into that directory.

Auto completion also works for file names.

4.2 Command recovery

Many commands are regularly reused and have to be typed in many times in one session. cd for change directory is one such example, but also calls for software programs often have to be repeated. Instead of retyping a command, the command line offers another convenience function called command recovery. If your command line window is still open and you have already typed in a few commands from the exercises above, just hit the up arrow button (usually located somewhere in the bottom right hand corner of your key board between the main alphabetical block and the number block) and see what happens. Hit it a few times and you will see that the system keeps in memory all previous commands that you have typed in one session; you can recover them in sequence. You can even recover a previous command and alter it, for example to work on a different file. This function is especially useful when you are carrying out repetitive tasks that only require minor alternations.

5. Output handling

Most command line tools will by default print their output to the screen unless they are “told” to do otherwise. This is a very useful default behaviour because it allows you to instantly inspect whether a tool is performing the desired function and whether the data look like they have undergone the desired processing procedure. However, most of the time, when a piece of software is behaving in the desired fashion, we want to capture the output for further processing or for query and analysis. So a function that allows us to capture the output in a file instead of the screen would be very welcome. Fortunately, operating systems offer this functionality out of the box. It is typically evoked in a fashion that basically specified the processing function to be carried out, optional parameters influencing the processing (e.g. a choice of a modell for part of speech tagging or parsing), the name of the input file, a signal telling the operating system to pipe the output to a file and the name of the output file which can be specified by the user:

Under the Windows shell, the pipe symbol is >, it takes as its arguments an input file-name before the symbol and an output file-name after the symbol. This writes the output to a file in the same directory as the input file unless a different path is specified.

Examples of running this type of procedure can be viewed in the following tutorials: