# Découverte d'Ubuntu Linux et son Terminal Bash

## Navigating the Ubuntu GUI

> In this exercise, we will familiarize ourselves with the graphical user interface (GUI) of the Ubuntu operating system.

### Task 1: Familiarize Yourself with the Ubuntu Desktop

At the log-in screen, click in the password input box, enter `<span class="pre">rosindustrial</span>` for the password, and hit enter. The screen should look like the image below when you log in:

![../../_images/ubuntu_desktop.png](https://industrial-training-master.readthedocs.io/en/humble/_images/ubuntu_desktop.png)

There are several things you will notice on the desktop:

![../../_images/ubuntu_desktop_details.png](https://industrial-training-master.readthedocs.io/en/humble/_images/ubuntu_desktop_details.png)

<div class="document" id="bkmrk-the-gear-icon-on-the" itemscope="itemscope" itemtype="http://schema.org/Article" role="main"><div class="document" itemscope="itemscope" itemtype="http://schema.org/Article" role="main"><div itemprop="articleBody"><div class="section"><div class="section" id="bkmrk-the-gear-icon-on-the-1">1. The gear icon on the top right of the screen brings up a menu which allows the user to log out, shut down the computer, access system settings, etc…
2. The bar on the left side shows running and “favorite” applications, connected thumb drives, etc.
3. The top icon is used to access all applications and files. We will look at this in more detail later.
4. The next icons are either applications which are currently running or have been “pinned” (again, more on pinning later)
5. Any removable drives, like thumb drives, are found after the application icons.
6. If the launcher bar gets “too full”, clicking and dragging up/down allows you to see the applications that are hidden.
7. To reorganize the icons on the launcher, click and hold the icon until it “pops out”, then move it to the desired location.

</div><div class="section">  
</div></div></div></div></div>### Task 2: Open and Inspect an Application

Click on the filing-cabinet icon in the launcher. A window should show up, and your desktop should look like something below:

![../../_images/ubuntu_folder_browser.png](https://industrial-training-master.readthedocs.io/en/humble/_images/ubuntu_folder_browser.png)

Things to notice:

<div class="document" id="bkmrk-the-close%2C-minimize%2C" itemscope="itemscope" itemtype="http://schema.org/Article" role="main"><div class="document" itemscope="itemscope" itemtype="http://schema.org/Article" role="main"><div itemprop="articleBody"><div class="section"><div class="section">1. The close, minimize, and maximize buttons typically found on the right-hand side of the window title bar are found on the left-hand side.
2. The menu for windows are found on the menu bar at the top of the screen, much in the same way Macs do. The menus, however, only show up when you hover the mouse over the menu bar.
3. Notice that there are menu highlights of the folder icon. The dots on the left show how many windows of this application are open. Clicking on these icons when the applications are open does one of two things:

- If there is only one window open, this window gets focus.
- If more than one are open, clicking a second time causes all of the windows to show up in the foreground, so that you can choose which window to go to (see below):

</div></div></div></div></div>![../../_images/ubuntu_inspect.png](https://industrial-training-master.readthedocs.io/en/humble/_images/ubuntu_inspect.png)

<div class="document" id="bkmrk--4" itemscope="itemscope" itemtype="http://schema.org/Article" role="main"><div class="document" itemscope="itemscope" itemtype="http://schema.org/Article" role="main"><div itemprop="articleBody"><div class="section"><div class="section" id="bkmrk--5"></div><div class="section">  
</div></div></div></div></div>### Task 3: Start an Application &amp; Pin it to the Launcher Bar

Click on the launcher button (top left) and type gedit in the search box. The “Text Editor” application (this is actually gedit) should show up (see below):

![../../_images/ubuntu_start_application.png](https://industrial-training-master.readthedocs.io/en/humble/_images/ubuntu_start_application.png)

Click on the application. The text editor window should show up on the screen, and the text editor icon should show up on the launcher bar on the left-hand side (see below):

![../../_images/ubuntu_application_pin.png](https://industrial-training-master.readthedocs.io/en/humble/_images/ubuntu_application_pin.png)

<div class="document" id="bkmrk-right-click-on-the-t" itemscope="itemscope" itemtype="http://schema.org/Article" role="main"><div class="document" itemscope="itemscope" itemtype="http://schema.org/Article" role="main"><div itemprop="articleBody"><div class="section"><div class="section">1. Right-click on the text editor launch icon, and select “Lock to Launcher”.
2. Close the gedit window. The launcher icon should remain after the window closes.
3. Click on the gedit launcher icon. You should see a new gedit window appear.

</div></div></div></div></div>## Le Terminal Linux  


> In this exercise, we will familiarize ourselves with the Linux terminal.

### Starting the Terminal

<div class="section" id="bkmrk-pour-ouvrir-le-termi">1. Pour ouvrir le Terminal, recherchez le programme "terminator" ou cliquez sur l'icône:
    
    [![63008829.png](https://innovation.iha.unistra.fr/uploads/images/gallery/2023-09/scaled-1680-/63008829.png)](https://innovation.iha.unistra.fr/uploads/images/gallery/2023-09/63008829.png)
2. Create a second terminal window, either by:
    
    
    - Right-clicking on the terminal and selecting the “Open Terminal” or
    - Selecting “Open Terminal” from the “File” menu
3. Create a second terminal within the same window by pressing “Ctrl+Shift+T” while the terminal window is selected.
4. Close the 2nd terminal tab, either by:
    
    
    - clicking the small ‘x’ in the terminal tab (not the main terminal window)
    - typing `<span class="pre">exit</span>` and hitting enter.
5. The window will have a single line, which looks like this:
    
    `<span class="pre">ros-industrial@ros-i-humble-vm:~$</span>`
6. This is called the prompt, where you enter commands. The prompt, by default, provides three pieces of information:
    
    
    1. *ros-industrial* is the login name of the user you are running as.
    2. *ros-i-humble-vm* is the host name of the computer.
    3. ~ is the directory in which the terminal is currently in. (More on this later).
7. Close the terminal window by typing `<span class="pre">exit</span>` or clicking on the red ‘x’ in the window’s titlebar.

</div>### Navigating Directories and Listing Files

#### Prepare your environment

<div class="section" id="bkmrk-open-your-home-folde"><div class="section"><div class="section" id="bkmrk-open-your-home-folde-1">1. Open your home folder in the file browser.
2. Double-click on the `<span class="pre">ex0.3</span>` folder we created in the previous step.
    
    
    - *We’ll use this to illustrate various file operations in the terminal.*
3. Right click in the main file-browser window and select “Open in Terminal” to create a terminal window at that location.
4. In the terminal window, type the following command to create some sample files that we can study later:
    
    
    - `<span class="pre">cp</span> <span class="pre">-a</span> <span class="pre">~/industrial_training/exercises/0.3/.</span> <span class="pre">.</span>`

</div></div></div>#### ls Command

<div class="section" id="bkmrk-enter-ls-into-the-te"><div class="section"><div class="section" id="bkmrk-enter-ls-into-the-te-1">1. Enter `<span class="pre">ls</span>` into the terminal.
    
    
    - You should see `<span class="pre">test.txt</span>`, and `<span class="pre">new</span>` listed. (If you don’t see ‘new’, go back and complete the [<span class="doc">previous exercise</span>](https://industrial-training-master.readthedocs.io/en/humble/_source/prerequisites/Exploring-the-Linux-File-System.html)).
    - Directories, like `<span class="pre">new</span>`, are colored in blue.
    - The file `<span class="pre">sample_job</span>` is in green; this indicates it has its “execute” bit set, which means it can be executed as a command.
2. Type `<span class="pre">ls</span> <span class="pre">*.txt</span>`. Only the file `<span class="pre">test.txt</span>` will be displayed.
3. Enter `<span class="pre">ls</span> <span class="pre">-l</span>` into the terminal.
    
    
    - Adding the `<span class="pre">-l</span>` option shows one entry per line, with additional information about each entry in the directory.
    - The first 10 characters indicate the file type and permissions
    - The first character is `<span class="pre">d</span>` if the entry is a directory.
    - The next 9 characters are the permissions bits for the file
    - The third and fourth fields are the owning user and group, respectively.
    - The second-to-last field is the time the file was last modified.
    - If the file is a symbolic link, the link’s target file is listed after the link’s file name.
4. Enter `<span class="pre">ls</span> <span class="pre">-a</span>` in the terminal.
    
    
    - You will now see one additional file, which is hidden.
5. Enter `<span class="pre">ls</span> <span class="pre">-a</span> <span class="pre">-l</span>` (or `<span class="pre">ls</span> <span class="pre">-al</span>`) in the command.
    
    
    - You’ll now see that the file `<span class="pre">hidden_link.txt</span>` points to `<span class="pre">.hidden_text_file.txt</span>`.

</div></div></div>#### `<span class="pre">pwd</span>` and `<span class="pre">cd</span>` Commands

<div class="section" id="bkmrk-enter-pwd-into-the-t"><div class="section"><div class="section">1. Enter `<span class="pre">pwd</span>` into the terminal.
    
    
    - This will show you the full path of the directory you are working in.
2. Enter `<span class="pre">cd</span> <span class="pre">new</span>` into the terminal.
    
    
    - The prompt should change to `<span class="pre">ros-industrial@ros-i-humble-vm:~/ex0.3/new$</span>`.
    - Typing `<span class="pre">pwd</span>` will show you now in the directory `<span class="pre">/home/ros-industrial/ex0.3/new</span>`.
3. Enter `<span class="pre">cd</span> <span class="pre">..</span>` into the terminal. \* In the [<span class="doc">previous exercise</span>](https://industrial-training-master.readthedocs.io/en/humble/_source/prerequisites/Exploring-the-Linux-File-System.html), we noted that `<span class="pre">..</span>` is the parent folder. \* The prompt should therefore indicate that the current working directory is `<span class="pre">/home/ros-industrial/ex0.3</span>`.
4. Enter `<span class="pre">cd</span> <span class="pre">/bin</span>`, followed by `<span class="pre">ls</span>`.
    
    
    - This folder contains a list of the most basic Linux commands.  
        *Note that `<span class="pre">pwd</span>` and `<span class="pre">ls</span>` are both in this folder.*
5. Enter `<span class="pre">cd</span> <span class="pre">~/ex0.3</span>` to return to our working directory.
    
    
    - Linux uses the `<span class="pre">~</span>` character as a shorthand representation for your home directory.
    - It’s a convenient way to reference files and paths in command-line commands.
    - You’ll be typing it a lot in this class… remember it!

</div></div></div>*If you want a full list of options available for any of the commands given in this section, type `<span class="pre">man</span> <span class="pre"><command></span>` (where `<span class="pre"><command></span>` is the command you want information on) in the command line. This will provide you with built-in documentation for the command. Use the arrow and page up/down keys to scroll, and `<span class="pre">q</span>` to exit.*

<div class="section" id="bkmrk--8"><div class="section" id="bkmrk--9"></div></div>### Altering Files

#### mv Command

<div class="section" id="bkmrk-type-mv-test.txt-tes"><div class="section"><div class="section" id="bkmrk-type-mv-test.txt-tes-1">1. Type `<span class="pre">mv</span> <span class="pre">test.txt</span> <span class="pre">test2.txt</span>`, followed by `<span class="pre">ls</span>`.
    
    
    - You will notice that the file has been renamed to `<span class="pre">test2.txt</span>`.  
        *This step shows how `<span class="pre">mv</span>` can rename files.*
2. Type `<span class="pre">mv</span> <span class="pre">test2.txt</span> <span class="pre">new</span>`, then `<span class="pre">ls</span>`.
    
    
    - The file will no longer be present in the folder.
3. Type `<span class="pre">cd</span> <span class="pre">new</span>`, then `<span class="pre">ls</span>`.
    
    
    - You will see `<span class="pre">test2.txt</span>` in the folder.  
        *These steps show how `<span class="pre">mv</span>` can move files.*
4. Type `<span class="pre">mv</span> <span class="pre">test2.txt</span> <span class="pre">../test.txt</span>`, then `<span class="pre">ls</span>`.
    
    
    - `<span class="pre">test2.txt</span>` will no longer be there.
5. Type `<span class="pre">cd</span> <span class="pre">..</span>`, then `<span class="pre">ls</span>`.
    
    
    - You will notice that `<span class="pre">test.txt</span>` is present again.  
        *This shows how `<span class="pre">mv</span>` can move and rename files in one step.*

</div></div></div>#### cp Command

<div class="section" id="bkmrk-type-cp-test.txt-new"><div class="section"><div class="section" id="bkmrk-type-cp-test.txt-new-1">1. Type `<span class="pre">cp</span> <span class="pre">test.txt</span> <span class="pre">new/test2.txt</span>`, then `<span class="pre">ls</span> <span class="pre">new</span>`.
    
    
    - You will see `<span class="pre">test2.txt</span>` is now in the `<span class="pre">new</span>` folder.
2. Type `<span class="pre">cp</span> <span class="pre">test.txt</span> <span class="pre">"test</span> <span class="pre">copy.txt"</span>`, then `<span class="pre">ls</span> <span class="pre">-l</span>`.
    
    
    - You will see that `<span class="pre">test.txt</span>` has been copied to `<span class="pre">test</span> <span class="pre">copy.txt</span>`.  
        *Note that the quotation marks are necessary when spaces or other special characters are included in the file name.*

</div></div></div>#### rm Command

<div class="section" id="bkmrk-type-rm-%22test-copy.t"><div class="section"><div class="section" id="bkmrk-type-rm-%22test-copy.t-1">1. Type `<span class="pre">rm</span> <span class="pre">"test</span> <span class="pre">copy.txt"</span>`, then `<span class="pre">ls</span> <span class="pre">-l</span>`.
    
    
    - You will notice that `<span class="pre">test</span> <span class="pre">copy.txt</span>` is no longer there.

</div></div></div>#### mkdir Command

<div class="section" id="bkmrk-type-mkdir-new2%2C-the"><div class="section"><div class="section" id="bkmrk-type-mkdir-new2%2C-the-1">1. Type `<span class="pre">mkdir</span> <span class="pre">new2</span>`, then `<span class="pre">ls</span>`.
    
    
    - You will see there is a new folder `<span class="pre">new2</span>`.

</div></div></div>#### touch Command

<div class="section" id="bkmrk-type-touch-%7E%2Ftemplat"><div class="section"><div class="section">1. Type `<span class="pre">touch</span> <span class="pre">~/Templates/"Untitled</span> <span class="pre">Document"</span>`.
    
    
    - This will create a new Document named **“Untitled Document”**

</div></div></div>*You can use the `<span class="pre">-i</span>` flag with `<span class="pre">cp</span>`, `<span class="pre">mv</span>`, and `<span class="pre">rm</span>` commands to prompt you when a file will be overwritten or removed.*

<div class="section" id="bkmrk--10"><div class="section" id="bkmrk--11"></div></div>#### Editing Text (and Other GUI Commands)

<div class="section" id="bkmrk-type-gedit-test.txt."><div class="section"><div class="section" id="bkmrk-type-gedit-test.txt.-1">1. Type `<span class="pre">gedit</span> <span class="pre">test.txt</span>`.
    
    
    - You will notice that a new text editor window will open, and `<span class="pre">test.txt</span>` will be loaded.
    - The terminal will not come back with a prompt until the window is closed.
2. There are two ways around this limitation. Try both…
3. **Starting the program and immediately returning a prompt:**
    
    
    1. Type `<span class="pre">gedit</span> <span class="pre">test.txt</span> <span class="pre">&</span>`.
        
        
        - The `<span class="pre">&</span>` character tells the terminal to run this command in “the background”, meaning the prompt will return immediately.
    2. Close the window, then type `<span class="pre">ls</span>`.
        
        
        - In addition to showing the files, the terminal will notify you that `<span class="pre">gedit</span>` has finished.
4. **Moving an already running program into the background:**
    
    
    1. Type `<span class="pre">gedit</span> <span class="pre">test.txt</span>`.
        
        
        - The window should open, and the terminal should not have a prompt waiting.
    2. In the terminal window, press Ctrl+Z.
        
        
        - The terminal will indicate that `<span class="pre">gedit</span>` has stopped, and a prompt will appear.
    3. Try to use the `<span class="pre">gedit</span>` window.
        
        
        - Because it is paused, the window will not run.
    4. Type `<span class="pre">bg</span>` in the terminal.
        
        
        - The `<span class="pre">gedit</span>` window can now run.
    5. Close the `<span class="pre">gedit</span>` window, and type `<span class="pre">ls</span>` in the terminal window.
        
        
        - As before, the terminal window will indicate that `<span class="pre">gedit</span>` is finished.

</div></div></div>#### Running Commands as Root

<div class="section" id="bkmrk-in-a-terminal%2C-type--2"><div class="section"><div class="section">1. In a terminal, type `<span class="pre">ls</span> <span class="pre">-a</span> <span class="pre">/root</span>`.
    
    
    - The terminal will indicate that you cannot read the folder `<span class="pre">/root</span>`.
    - Many times you will need to run a command that cannot be done as an ordinary user, and must be done as the “super user”
2. To run the previous command as root, add `<span class="pre">sudo</span>` to the beginning of the command.
    
    
    - In this instance, type `<span class="pre">sudo</span> <span class="pre">ls</span> <span class="pre">-a</span> <span class="pre">/root</span>` instead.
    - The terminal will request your password (in this case, `<span class="pre">rosindustrial</span>`) in order to proceed.
    - Once you enter the password, you should see the contents of the `<span class="pre">/root</span>` directory.

</div></div></div>***Warning**: `<span class="pre">sudo</span>` is a powerful tool which doesn’t provide any sanity checks on what you ask it to do, so be **VERY** careful in using it*

*https://industrial-training-master.readthedocs.io/en/humble/\_source/prerequisites/Navigating-the-Ubuntu-GUI.html*

<div class="section" id="bkmrk--12"><div class="section" id="bkmrk--13"></div></div><div class="document" id="bkmrk--14" itemscope="itemscope" itemtype="http://schema.org/Article" role="main"><div itemprop="articleBody"><div class="section" id="bkmrk--15"><div class="section" id="bkmrk--16"></div></div></div></div>