The terminal

Reading time15 min

In brief

Article summary

In this lecture, we give a brief introduction to the terminal usage and the main commands you should know to use it on a computer.

Main takeaways

  • Terminals are still very much present on modern computers.

  • They offer a quick and simple way to interact with the computer.

  • The main commands may differ from one OS to another, but they often achieve the same purpose (think of dir and ls on Windows and Linux respectively).

  • A basic knowledge of the usual commands is expected if you want to follow IMT Atlantique computer science curriculum.

Article contents

We have seen in the previous lecture that to interact with the OS, the user needed a User Interface, or Shell. If it can be more convenient for your day-to-day use of a computer to use the GUI, you can still use the Command Line Interface if you need to. Sometimes you may even have no other choice but to use it (think of servers, particularly those without a graphical interface , e.g., Linux servers).

In the computer science course, you will also find that some tasks are way easier using the command line. Knowing the basic commands will greatly improve your productivity while programing this semester and for futures lectures throughout your studies.

1 — What is a terminal?

Historically, the command line interface was a physical console, named a terminal, a device consisting of a cathodic screen and a keyboard, connected to the computer. Now, however, the terminal is just a program installed on your PC.

Depending on your operating system, the terminal application may be called differently, its function however is always the same. It displays a prompt (which usually ends with one of the characters $, %, #, :, > or -) and waits for you to type-in the correct commands. Here are a few terminal applications:

  • Windows Terminal (default in recent versions of Windows 10 and Windows 11).
  • Command Prompt (cmd.exe).
  • PowerShell.

The language used by cmd.exe is called Batch script (or simply Batch). The one used by PowerShell is called PowerShell Scripting Language (or simply PowerShell).

Most Linux distributions come with different default terminal emulators depending on the desktop environment:

  • Gnome Terminal (Gnome environment).
  • Konsole (KDE environment).

On most Linux platforms, the language used for interacting with the system is called Bash.

  • Terminal (the default terminal emulator).
  • iTerm2 (a popular third-party alternative, though not pre-installed).

On MacOs, the language used for interacting with the system is called Zsh.

2 — The main commands

The terminal allows you to interact with the operating system through various commands, here we will just give an overview of the more useful ones. You will be able to use more of them during session 3 about permissions & files.

The general pattern for a command line interface is:

<prompt> <command> <param_1> <param_2> <param_3> ... <param_N>
  • <prompt> – Generated by the program to provide context for the user. It usually ends with one of the characters $, %, #, :, > or -.
  • <command> – Provided by the user. It can be:
    • Internal commands are recognized and processed by the command line interpreter. Internal commands are also called built-in commands.
    • External commands run executables found in separate executable files (e.g., python).
  • <param_1> ... <param_N> – parameters provided by the user, if needed.

In the tab below, we give the main commands that you need to remember in order to use the terminal of your favorite OS.

  • help – Yes, this is a command. It provides either the list of supported commands, or gives details on a given command (e.g., ask for help cd). In addition, each of the following commands displays a brief help text when followed by the /? option (e.g., type dir /?).
  • dir – Lists the content of a directory.
  • cd – Changes directory (go to the directory you indicate, e.g., cd C:\Users\ or cd .., where the special directory named .. means a step back in the hierarchy).
  • C:, D:, A: – Jump to the hierarchy of the drive attached to the letter, if active.
  • mkdir (md)` – Creates a directory.
  • rmdir (rd)` – Removes a directory.
  • copy – Copies a file or a directory (also note xcopy, and extended version).
  • del – Deletes files.
  • ren – Renames a file or a directory.
  • tree – Displays the tree from your current location in the hierarchy.
  • more – Displays output one screen at a time (useful when you have a lot of information to display).
  • type – Displays the contents of a text file.
  • set – Displays, sets, or removes Windows environment variables.
  • systeminfo – Displays machine specific properties and configuration.
  • tasklist – Displays all currently running tasks including services.
  • taskkill – Kills or stops a running process or application.
  • ver – Displays the Windows version.
  • vol – Displays a disk volume label and serial number.
  • chkdsk – Checks a disk and displays a status report (requires administrator status).
  • exit – To exit the termnal.
  • Help (Get-Help) – Provides the details on a given command (e.g., ask for Get-Help cd).
  • Get-Command – Gives you a complete list of all the available commands or cmdlets as they are called in PowerShell.
  • Get-ChildItem (dir, ls) – List the content of a directory.
  • Set-Location (cd) – Changes directory (go to the directory you indicate).
  • New-Item – Creates either a file or a directory, depending on the -ItemType parameter (e.g., New-Item -ItemType Directory -Path new_directory).
  • Copy-Item (cp, copy) – Copy a file or a directory.
  • Move-Item (mv, move) – Move a file or a directory.
  • Get-Content (cat, type) – Displays the contents of a text file.
  • Select-String – Uses regular expression matching to search for text patterns in input strings and files.
  • Get-ComputerInfo – Gets a consolidated object of system and operating system properties.
  • Get-Process (ps) – Displays all currently running tasks including services.
  • Stop-Process (kill) – Kills or stops a running process or application.
  • Get-PSDrive – Gets drives in the current session.
  • exit – To exit the terminal.
  • help – Yes, this is a command. It provides either the list of supported commands, or gives details on a given command (e.g., ask for help cd).
  • man – Displays a manual page relating to an application or to the system. Unix has the great idea to come with its own official documentation (e.g., type man gedit, press ‘Q’ to quit).
  • ls – Lists the content of a directory.
  • cd – Changes directory (go to the directory you indicate, e.g., cd /home, or cd .. where the special directory name .. means a step back in the hierarchy; also note the special directory name ~ as an alias for your own home directory).
  • pwd – Prints working directory, your current location in the hierarchy.
  • mkdir – Creates a directory.
  • rmdir – Removes a directory.
  • cp – Copies a file or a directory.
  • rm – Removes files.
  • mv – Moves a file or a directory.
  • more – Displays output one screen at a time (useful when you have a lot of information to display).
  • cat – Concatenates files and print on the standard output.
  • grep – Searches for patterns in files.
  • uname – Prints system information.
  • lscpu, lspci, lsblk – List respectively CPU information, peripheral information and block device (hard drive) information.
  • ps – Displays all currently running processes.
  • kill – Kills or stops a running process or application.
  • df – Reports file system disk space usage.
  • du – Estimates file space usage.
  • free – Displays amount of free and used memory in the system.
  • exit – To exit the terminal.
  • help – Yes, this is a command. It provides either the list of supported commands, or gives details on a given command (e.g., ask for help cd).
  • man – Displays a manual page relating to an application or to the system. Unix has the great idea to come with its own official documentation (e.g., type man gedit, press ‘Q’ to quit).
  • ls – Lists the content of a directory.
  • cd – Changes directory (go to the directory you indicate, e.g., cd /home, or cd .. where the special directory name .. means a step back in the hierarchy; also note the special directory name ~ as an alias for your own home directory).
  • pwd – Prints working directory, your current location in the hierarchy.
  • mkdir – Creates a directory.
  • rmdir – Removes a directory.
  • cp – Copies a file or a directory.
  • rm – Removes files.
  • mv – Moves a file or a directory.
  • more – Displays output one screen at a time (useful when you have a lot of information to display).
  • cat – Concatenates files and print on the standard output.
  • grep – Searches for patterns in files.
  • uname – Prints system information.
  • lscpu, lspci, lsblk – List respectively CPU information, peripheral information and block device (hard drive) information.
  • ps – Displays all currently running processes.
  • kill – Kills or stops a running process or application.
  • df – Reports file system disk space usage.
  • du – Estimates file space usage.
  • free – Displays amount of free and used memory in the system.
  • exit – To exit the terminal.

The file system commands will be further explained in session 3 on file systems and permissions, and you will have the opportunity to try them throughout this dedicated course.

To go further

Important

The content of this section is optional. It contains additional material for you to consolidate your understanding of the current topic.

3 — Anonymous pipes

With these commands you can already use your system. However, most operating systems also support what are called anonymous pipes. An anonymous pipe is a one-way communication channel typically used for inter-process communication (IPC) between related processes. It is called “anonymous” because it doesn’t have a name in the file system. It exists only in memory and is used exclusively by the processes that created it.

Key Characteristics of anonymous pipes:

  • Unidirectional – Data flows in only one direction, from the pipe’s write-end to its read-end.

  • Parent-child process communication – Often used for communication between a parent process and its child processes. For instance, a parent process can create an anonymous pipe and fork a child process, passing the pipe to the child to facilitate communication.

  • Short-lived – Anonymous pipes are temporary and cease to exist when the creating processes terminate.

  • Platform support – Supported by most operating systems, including Windows, Linux and MacOS.

In Unix-like systems like MacOs or Linux, anonymous pipes are frequently used with the shell’s | operator, where the output of one command is piped as input to another command:

ls | grep <file_name>
ls | grep <file_name>

In this example, the ls command outputs to an anonymous pipe, and grep reads from the pipe. It is used to search a directory for a specific file with the name <file_name>.

To go beyond

Important

The content of this section is very optional. We suggest you directions to explore if you wish to go deeper in the current topic.