The terminal
Reading time15 minIn 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 mains commands may differ from one OS to another, but they often achieve the same purpose (think of
dir
andls
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 (such as Linux servers))…
In the computer science course you will also find that some tasks are way easier using the command line and 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 waiting for you to type-in the correct commands.
- Linux: Most Linux distributions come with different default terminal emulators depending on the desktop environment:
- GNOME: GNOME Terminal
- KDE: Konsole
- Windows:
- Windows Terminal (default in recent versions of Windows 10 and Windows 11)
- Command Prompt (cmd.exe)
- PowerShell
- macOS:
- Terminal.app (the default terminal emulator)
- iTerm2 (a popular third-party alternative, though not pre-installed)
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 the third session about Permissions & files.
The general pattern for a command line interface is :
Prompt command param1 param2 param3 … paramN
- Prompt : generated by the program to provide context for the user, usually ends with one of the characters $, %, #, :, > or -)
- Command : provided by the user
- 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
)
- param1 …paramN — parameters provided by the user.
In the tab below we give the main commands that you need to remember in order to use the CLI of your favorite OS. For Windows systems we give the old cmd.exe commands as well as the more recent Powershell ones. For Unix like systems such as Linux or macOS the commands should be similar.
The basic commands you should know are:
help
: Yes, this is a command. It provides either the list of supported commands, or gives details on a given command (eg. ask for “help cd”). In addition, each of the following commands displays a brief help text when followed by the “/?” option (eg. type “dir /?”).dir
: List the content of a directory.cd
: Change Directory. Go to the directory you indicate (eg. “cd C:\Users", or “cd ..” where the special directory name “..” 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
)rmdir
(rd
): Make or remove a directory.copy
: Copy a file or a directory. (Also note “xcopy”, and extended version.)del
: Delete files.ren
: Rename a file or a directory.tree
: Display 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
: Kill or stop 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 basic commands you should know are:
Help
orGet-Help
: Provides the details on a given command (eg. 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
(aliasesdir
orls
): List the content of a directory.Set-Location
(aliascd
): Change Directory. Go to the directory you indicate.New-Item
: Create either a file or a directory depending on the-ItemType
parameter (for exampleNew-Item -ItemType Directory -Path new_directory
).Copy-Item
(aliasescp
orcopy
): Copy a file or a directory.Move-Item
(aliasesmv
ormove
): Move a file or a directory.Get-Content
(aliasescat
ortype
): 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
(aliasps
): Displays all currently running tasks including services.Stop-Process
(aliaskill
): Kill or stop a running process or application.Get-PSDrive
: Gets drives in the current session.exit
: To exit.
The basic commands you should know are:
help
: Yes, this is a command. It provides either the list of supported commands, or gives details on a given command (eg. ask for “help cd”).man
: Display a manual page relating to an application or to the system. Unix has the great idea to come with its own official documentation. (Eg. type “man gedit”; press ‘Q’ to quit)ls
: List the content of a directory.cd
: Change Directory. Go to the directory you indicate (eg. “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
: Print working directory, your current location in the hierarchy.mkdir
rmdir
: Make or remove a directory.cp
: Copy a file or a directory.rm
: Remove files.mv
: Move a file or a directory.more
: Displays output one screen at a time. Useful when you have a lot of information to display.cat
: Concatenate files and print on the standard outputgrep
: Searches for patterns in files.uname
: Print system informationlscpu
,lspci
&lsblk
: List respectively CPU information, Peripheral information and Block Device (hard drive) information.ps
: Displays all currently running processes.kill
: Kill or stop a running process or application.df
: Report file system disk space usage.du
: Estimate file space usage.free
: Display amount of free and used memory in the system.exit
: To exit.
The file system commands will be further explained in the dedicated chapter File systems and permissions, and you will have the opportunity to try them throughout this dedicated course.
To go further
The content of this section is optional. It contains additional material for you to consolidate your understanding of the current topic.
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, Unix, and Linux.
In Unix-like systems, 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"
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”.
To go beyond
The content of this section is very optional. We suggest you directions to explore if you wish to go deeper in the current topic.
- name.
Short description.