Newer
Older
---
title: First step in a terminal
---
# First step in a terminal
[](http://creativecommons.org/licenses/by-sa/4.0/)
Objective: learn to use basic terminal command
The first thing that you can see is a welcome message (yes GNU/Linux users are polite and friendly), and information on your distribution.
> A **Linux distribution** (often abbreviated as **distro**) is an [operating system](https://en.wikipedia.org/wiki/Operating_system) made from a software collection that is based upon the [Linux kernel](https://en.wikipedia.org/wiki/Linux_kernel)
What is the distribution installed on your VM ?
You can go to this distribution website and have a look at the list of firms using it.
## Shell
A command-line interpreter (or shell), is a software designed to read lines of text entered by a user to interact with an OS.
To simplify the shell executes the following infinite loop:
2. translate this line as a program execution with its parameters
3. launch the corresponding program with the parameters
3. wait for the program to finish
4. Go back to 1.
When you open a terminal on an Unix-like OS, you will have a **prompt** displayed: it can end with a **$** or a **%** character depending on your configuration. As long as you see your prompt, it means that you are in step **1.**, if no prompt is visible, you are in step **4.** or you have set up a very minimalist configuration for your shell.
<img src="./img/prompt.png" alt="prompt" style="zoom:150%;" />
The blinking square or vertical bar represents your **cursor**. Shell predates graphical interfaces, so most of the time you won’t be able to move this cursor with your mouse, but with the directional arrows (left and right).
On the IFB, your prompt is a **$**
```sh
etudiant@VM:~$
```
You can identify the following information from your prompt: **etudiant** is your login and **VM** is the name of your VM (**~** is where you are on the computer, but we will come back to that later).
On Ubuntu 20.04, the default shell is [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) while on recent version of macOS it’s [zsh](https://en.wikipedia.org/wiki/Z_shell). There are [many different shell](https://en.wikipedia.org/wiki/List_of_command-line_interpreters), for example, Ubuntu 20.04 also has [sh](https://en.wikipedia.org/wiki/Bourne_shell) installed.
You can launch every program present on your computer from the shell. The syntax will always be the following:
```sh
etudiant@VM:~$ program_name option_a option_b option_c [...] option_n
```
And pressing **enter** to execute your command.
For example, we can launch the `cal` software by typing the following command and pressing **enter**:
```sh
cal
```
When you launch a command, various things can happen:
- Computation can be made
- Files can we read or written
- etc.
We can pass argument to the `cal` software the following way.
You can add as many parameters as you want to your command, try `-3 -1` what is the meaning of the `-1` parameter ?
The `-d` option display the month of a given date in a `yyyy-mm` format. Try to display your month of birth.
Traditionally, parameters are *named* which means that they are in the form of:
* `-X something` for an input option (like `cal -d yyyy-mm`)
Here the name of the parameter is `X`, but software can also accept list of unnamed parameters. Try the following:
```sh
cal 2
cal 1999
cal 2 1999
```
What is the difference for the parameter value `2` in the first and third command ?
## Moving around
For the `cal` program, the position in the file system is not important (it’s not going to change the calendar). However, for most tools that are able to read or write files, it’s important to know where you are. This is the first real difficulty with command line interface: you need to remember where you are.
If you are lost, you can **p**rint your **w**orking **d**irectory (i.e., where you are now, working) with the command.
```sh
pwd
```
Like `cal`, the `pwd` command return textual information
By default when you log on an Unix system, you are in your **HOME** directory. Every user (except one) should have it’s home directory in the `/home/`folder.
To **c**hange **d**irectory you can type the command `cd`, `cd` take one argument: the path of the directory where you want to go. go to the `/home` directory.
```sh
cd /home
```
The `cd` command doesn’t return any textual information, but change the environment of the shell (you can confirm it with ` pwd`) ! You can also see this change in your prompt:
```sh
`etudiant@VM:/home$`
```
What is the location shown in your prompt ? Is it coherent with the `pwd` information ? Can you `cd` to the `pwd` path ?
When we move around a file system, we often want to see what is in a given folde. We want to **l**i**s**t the directory content. Go back to the `/home` directory and use to the `ls` command see how many have a home directory there.
We will see various options for the `ls` command, throughout this course. Try the `-a` option.
```sh
ls -a
```
What changed compared to the `ls` command without this option ?
Go to your home folder with the bare `cd` command and run the `ls -a` command again. The `-a` option makes the `ls` command list hidden files and folders. On Unix systems, hidden files and folders are all files and folders whose name starts with a "**.**".
```sh
cd .
```
Can you cd to "**..**" ?
```sh
cd ..
```
What appended ?
Repeat 3 times the previous command (you can use the upper directional arrow to repeat the last command).
You can use the `-l` option in combination with the `-a` option to know more about those folders.
> We have seen the commands :
>
> - `cal` for calendar
> - `cd` for change directory
> - `ls` for list directory
> - `pwd` for print working directory
[You can now go to the Unix file system.](./4_unix_file_system.html)