---
title: First steps with the Linux command line
description: Learn the basics of Linux command line with this beginner-friendly tutorial. Master essential commands to navigate, manage files, and streamline tasks effectively.
tags: linux ubuntu pwd mkdir
products:
  - dedibox
  - instances
  - elastic-metal
dates:
  validation: 2025-06-02
  posted: 2023-11-16
  validation_frequency: 12
difficulty: beginner
usecase:
  - best-practices
ecosystem:
  - third-party
---
import image from './assets/scaleway-win.webp'
import image2 from './assets/scaleway-terminal.webp'
import image3 from './assets/scaleway-nano.webp'

import Requirements from '@macros/iam/requirements.mdx'


This tutorial shows you how to get started with the Linux command line (also known as the **terminal**).

You may be used to using a **G**raphical **U**ser **I**nterface (**GUI**) for your machine, such as Windows or MacOS. These GUIs make it easy to do everything visually, with clicks of your mouse to open, and close programs and complete thousands of different tasks.

<Lightbox image={image} alt="" />

However, when you provision a virtual or remote machine such as a [Scaleway Instance](/instances/how-to/create-an-instance/), [Dedibox](/dedibox/how-to/order-a-server/), or [Elastic Metal server](/elastic-metal/how-to/create-server/) it is more usual to use the text-based command line, rather than a GUI, to operate the machine. While GUIs are user-friendly, the command line is much more powerful, uses fewer of the machine's resources (leaving more compute power to be used elsewhere), is less laggy, and more efficient.

Even if you are using a GUI on your own local machine, you can also choose to use the command line by opening a **terminal** application in your GUI, to start carrying actions via the command line instead of the graphical interface.

<Lightbox image={image2} alt="" />

When you are faced with operating a machine via the command line for the first time, this can be confusing and frustrating. This document aims to show you some of the basic principles of using a command line instead of a graphical interface. We will guide you through a series of hands-on exercises to practice some of the main commands you need to get started.

In this document, we cover commands for a **Linux** command line. If you are using a Windows command line, we recommend that you [refer to the Windows documentation](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands), as the commands differ. In the context of virtual machines and servers, a Linux-based OS is generally the go-to choice. Unlike Windows, Linux OSes do not require paid-for licenses; they are free and open source.

<Message type="tip">
If you are just looking for a quick recap and cheatsheet of Linux commands you are already familiar with, [skip to the last section](#linux-commands-summary-and-cheatsheet).
</Message>

<Requirements />

- Provisioned a virtual/remote machine running a Linux OS and [connected to its command line via SSH](/instances/how-to/connect-to-instance/) or you are using a physical machine running a Linux OS or MacOS, and have opened the terminal.

## The command prompt

When you are first connected to the command line (aka the **shell**), you will see a **command prompt** which should look something like this:


```bash
username@machine-name:~$
```

<Message type="tip">
If you see `/root`, this suggests you may have a fresh Linux installation with no individually created users yet. It would be a good idea to [create a "normal" user](#creating-and-logging-into-new-user-accounts---adduser-usermod-and-su) before continuing.
</Message>

The exact prompt will vary depending on the setup of your individual machine. But generally, it will display your **username** on the machine, followed by an `@` and the name of the machine itself.

The `~` indicates that you are in your **home directory**.

The `$` signals the end of the command prompt (if you are logged in as [root](#running-commands-as-the-superuser-sudo) you may see a `#` instead of a `$`).

## Where am I? The working directory - pwd

The working directory is also known as the current directory. It represents the directory you are currently in, in the command line. You can imagine a graphical file system with many different folders, each themselves containing more subfolders and files. Whenever you are in the terminal, you are "in" a particular directory (or folder) somewhere within this file system tree.

To find out where you are (i.e. what your working directory is), use the `pwd` command. It stands for **p**rint **w**orking **d**irectory. Type it into your terminal and hit enter:

```bash
pwd
```

You see an output that prints your current working directory to the screen, for example:

```
/home/username
```

## Moving between directories - cd

You can move between directories with the `cd` command. It stands for **c**hange **d**irectory.

1. Go one directory "upwards" in the file system, i.e. a step closer to the root, by using the command `cd` followed by `..`:

    ```bash
    cd ..
    ```

2. Repeat the `pwd` command to check your new working directory:

    ```bash
    pwd
    ```

    The working directory now displays, for example:

    ```bash
    /home
    ```

    <Message type="tip">
    If you were already in the root directory and tried to do `cd ..` you will not change directories, as there is no upward level to move to.
    </Message>

3. Go one directory "downwards" in the file system, i.e. into a subdirectory of your current directory, by using the command `cd` followed by the directory name. Assuming you are now in the `home` directory, use the command below replacing `username` with your own username, to move back into the directory where you started:

    ```bash
    cd username
    ```

## Listing the contents of a directory - ls

You can use the `ls` command to list the contents of your working directory. It stands for **l**i**s**t.

1. List the subdirectories and files in your current working directory with `ls`:

    ```bash
    ls
    ```

    The output will depend on the contents of your particular directory, but you may see something like the following:

    ```bash
    Documents   Music       Templates
    Desktop     Pictures    config.txt
    Downloads   Public      Videos
    ```

2. Practice the `cd` command again by changing the directory into one of the subdirectories listed, checking the contents with `pwd`, and then using `cd ..` to change back to the upper directory again:

    ```bash
    cd Documents
    ```

    - You change into the Documents directory.

    ```bash
    pwd
    ```

    - You see an output showing the contents of the Documents directory.

    ```bash
    cd ..
    ```

    - You change back into the Documents directory.

## Make a new directory - mkdir

You can make a new directory with the `mkdir` command. It stands for **m**ake **dir**ectory.

1. Make a new directory with `mkdir` followed by the name of the directory you want to create:

    ```bash
    mkdir my-directory
    ```

2. Use `ls` to confirm that the directory is created:

    ```bash
    ls
    ```

    You see `my-directory` that you just created, listed in the contents of the current working directory.

3. Move into the directory you just created:

    ```bash
    cd my-directory
    ```

## Make a new file - touch

You can make a new file, without any content, with the `touch` command.

1. Make a new file called `my-text-file.txt` with the touch command:

    ```bash
    touch my-text-file.txt
    ```

2. Use `ls` to confirm that the file is created:

    ```bash
    ls
    ```

    The filename should now display among the rest of the output.

## Edit a text file - nano

There are many different programs you can use to edit text in the command line of Linux. Some of these include [Vim](https://www.vim.org/), [GNU Emacs](https://www.gnu.org/software/emacs/) and [ne](https://ne.di.unimi.it/). However, for this tutorial, we will use [nano](https://www.nano-editor.org/). It is pre-installed on most Linux distributions, and relatively easy to use for beginners.

1. Make sure you are in the same working directory as the text file you created in the previous step, and then open the text file with nano:

    ```bash
    nano my-text-file.txt
    ```

    Nano opens the file and you see a screen like the following:

    <Lightbox image={image3} alt="" />

    The information at the bottom tells you the keyboard shortcuts for different actions within the file. Depending on your keyboard, a command such as `CTRL + X` will exit the file and take you back to the command line, whereas you can use `CTRL + K` to cut text, etc.

2. Enter some text into the file, for example:

    ```txt
    Hello world!
    This is my first text file in Linux.
    ```

3. Use `CTRL+O` to save ("write out") the file, and hit enter when asked to confirm.

4. Use `CTRL+X` to exit the file and go back to the command line.

## Display the contents of a file - cat

You can display the contents of a file on the command line, without opening the file itself, using the `cat` command. It stands for con**cat**enate. This is because it is frequently used to concatenate the contents of multiple files together. However, here we will just look at its most simple, basic usage.

1. Make sure you are in the same working directory as the text file you created in the previous step, and display its contents with `cat`:

    ```bash
    cat my-text-file.txt
    ```

    The contents of your text file display on the command line:

    ```bash
    Hello world!
    This is my first text file in Linux
    ```

    You can also use `cat` to put the contents of the text file, into a new text file, as we see next.

2. Copy the contents of `my-text-file.txt` into a new text file called `another-text-file.txt`, with the following command:

    ```bash
    cat my-text-file.txt > another-text-file.txt
    ```

3. Display the contents of the new text file:

    ```bash
    cat another-text-file.txt
    ```

    The contents of the new text file display on the command line. Of course, the contents are identical, as it is simply a copy of the first file:

    ```bash
    Hello world!
    This is my first text file in Linux
    ```

## Moving or copying files and directories - mv and cp

You can move files and directories with the `mv` (**m**o**v**e) and `cp` (**c**o**p**y) commands.

1. Create a new directory called **dir-2** with the following command, as we saw earlier:

    ```bash
    mkdir dir-2
    ```

2. Make sure you are in the same working directory as the file `my-text-file.txt` that you previously created, and then copy into the directory created in step 1 with the following command:

    ```bash
    cp my-text-file.txt dir-2
    ```

3. Use `cd` and `list` to move into the new directory and check that the text file has been copied:

    ```bash
    cd dir-2
    ls
    ```

    You should see the name of the file (`my-text-file.txt`) when displaying the directory contents with `ls`.

4. Use `cd` to move back to the previous directory, and check that the original text file still exists there too:

    ```bash
    cd ..
    ls
    ```

    You should see the name of the file (`my-text-file.txt`) when displaying the directory contents with `ls`. The `cp` simply made a new copy for the new folder.

5. Make a new text file with the following command. Notice that here instead of using `touch` to create an empty file, we use `nano` to directly create and edit the new file:

    ```bash
    nano second-text-file.txt
    ```

    Nano opens the empty file.

6. Add the following text to the file, then save and exit as shown [before](#edit-a-text-file---nano):

    ```txt
    This is a new text file.
    I'm a Linux pro now.
    ```

7. Use `mv` to move `second-text-file.txt` into the `dir-2` directory you previously created:

    ```bash
    mv second-text-file.txt dir-2
    ```

8. List contents of the current directory, to see that `second-text-file.txt` is no longer there:

    ```bash
    ls
    ```

9. Use the following commands to change your working directory to `dir-2` and see that `second-text-file.txt` has been moved there:

    ```bash
    cd dir-2
    ls
    ```

    <Message type="tip">

        **A note on file paths** <br/><br/>

        In the examples above, we can simply use the names of the files and the directories in our commands, because we are in the **current working directory** that contains those files and directories. <br/><br/>

        If our current working directory was something else, we would need to specify the **path** of the file to move or copy, and the path of the directory to move it to. Remember that you can use `pwd` to display the path of your current working directory at any time, as a helper. <br/><br/>

        Take the example that my working directory was `/home/username/documents/`, but the file I wanted to move was in `/home/username/downloads/text-files`, and the target directory to move it to was `/home/username/recipes`, I can use the following command:

        ```
        mv /home/username/downloads/text-files/my-text-file.txt /home/username/recipes
        ```

        This principle does not just apply to the `mv` command, but all commands. For example, you can use `cd` + a path to a directory, to navigate straight from one working directory to another, even if they are not "adjacent".

    </Message>

## Deleting files and directories - rm

You can remove files and directories with the `rm` (**r**e**m**ove) command.

1. Navigate to the directory where `my-text-file.txt` is located, and delete the file with the following command:

    ```bash
    rm my-text-file.txt
    ```

2. With `cd`, navigate to the directory where you created `dir-2` (do not go **into** `dir-2`, stay in its parent directory).

    The command to remove the directory depends on whether or not it is empty.

    - If there are no files in the directory use `rm -d dir-2`
    - If there are files (or other directories) in the directory, use `rm -r dir-2`

3. Delete the `dir-2 directory` (which we presume still has other files inside):

    ```bash
    rm -r dir-2
    ```

    <Message type="tip">
    The `-r` part of this command is known as a **flag** or **option**. Flags are used to modify the behavior of a command slightly. Nearly all commands, including `ls`, `cat`, `mkdir` etc. have flags available to use. <br/><br/>

    Flags typically take the form of either one dash followed by a single letter (e.g. `-r`) or two dashes followed by a word (e.g. `--recursive`). Often both flag forms are available for the same option. <br/><br/>

    To find out about the flags that can be used with each command and what they can do, run `<command> --help` in your terminal, replacing `<command>` by the command you want help with, e.g. `cat --help`, `rm --help` etc.
    </Message>

## Running commands as the superuser - sudo

When you first install Linux, the only user that exists is **root**, which has inherent "superuser" administrative powers. It is not generally advisable to stay permanently logged in as the superuser, for reasons of security. Instead, you should [create a "normal" user account](#creating-and-logging-into-new-user-accounts-adduser-usermod-and-su) and use that when carrying out operations on your machine.

But as a "normal" user, you will not have permission for everything, such as updating and upgrading software. To carry out this kind of operation, you will need to prefix your command with `sudo` (**su**peruser **do**).

You are usually prompted to enter a password when you enter a `sudo` command, to ensure that you have the right permissions. After you have entered your password once, you will not be asked to enter it on subsequent `sudo` commands for a little while.

Carry on to the next section to see how to update and upgrade your system's software, using `sudo`.

## Updating the system and installing new applications - apt

You can use `apt`, the command for the **A**dvanced **P**ackage **T**ool, to install, update, delete, and manage software packages on Linux systems like Ubuntu and Linux Mint.

In this context, "package" essentially refers to **software**. On Linux, software is usually built as a package, distributed across remote repositories, and managed by users like you via package managers on their local machines.

You need to use [sudo](#running-commands-as-the-superuser---sudo) for these commands.

1. Update the software packages on your system with the following command:

    ```bash
    sudo apt update
    ```

    APT will fetch the latest information (about versions, indexes, etc) for packages on your system.

2. Upgrade the software packages on your system with the following command:

    ```bash
    sudo apt upgrade
    ```

    APT will use the information it gained in the previous step, to now actually fetch the new versions of the machine's packages and bring everything up to date.

    You will probably see a message like this:

    ```bash
    After this operation, 19,5 kB of additional disk space will be used.
    Do you want to continue? [Y/n]
    ```

    Hit `y` on your keyboard and then **Enter**, to continue.

    Your system's software is updated and upgraded.

3. Install a new software package on your system. In this example, we install the text editor `ne`:

    ```
    sudo apt install ne
    ```

    The `ne` packages are installed.

4. Open `ne` by typing its name:

    ```
    ne
    ```

    The text editor opens. You can play around with this text editor, or type `CTRL+Q` to exit.

## Creating and logging into new user accounts - adduser, usermod, and su

As previously mentioned, when you first install Linux, the only user that exists is **root**, which has inherent "superuser" administrative powers. It is not generally advisable to stay permanently logged in as the superuser, for reasons of security. Instead, you should create a "normal" user account and use that when carrying out operations on your machine.

When creating user accounts, you need to either be logged in as `root`, or else to prefix these commands with `sudo`.

1. Create a new user with the `adduser` command. Replace **sarah** with the username of your choice.

    ```bash
    sudo adduser k8s
    ```

    You will be prompted to add a **password** for this user. Then you will be prompted to add optional information such as first name, surname, and telephone number. You can hit enter to skip adding each optional piece of information. Hit `y` when prompted to confirm and create the user.

    ```bash
    Adding user `sarah' ...
    Adding new group `sarah' (1003) ...
    Adding new user `sarah' (1003) with group `sarah' ...
    Creating home directory `/home/sarah' ...
    Copying files from `/etc/skel' ...
    New password:
    Retype new password:
    passwd: password updated successfully
    Changing the user information for sarah
    Enter the new value, or press ENTER for the default
        Full Name []: Sarah
        Room Number []: 3
        Work Phone []:
        Home Phone []:
        Other []:
    Is the information correct? [Y/n] y
    ```

    You can see that a home directory has been automatically created for the new user.


2. Give the new user sudo privileges, so that they can carry out actions like updating software with the `sudo` prefix. This is done via the **usermod** command (**user** **mod**ification):

    ```
    sudo usermod -aG sudo sarah
    ```

3. Log in as the new user with the `su` (**s**witch **U**ser) command:

    ```
    su sarah
    ```

    <Message type="tip">

    You can use the command `cd ~` to change your working directory to the new user's home directory. `~` is a special shortcut in Linux to signify the home directory.

    </Message>

## Linux commands summary and cheatsheet

The table below provides a summary of everything we covered in this tutorial.

|                                                            |   Command                                                     |
|------------------------------------------------------------|---------------------------------------------------------------|
| Print your working directory                               | `pwd`                                                         |
| Move one directory 'upwards'                               | `cd ..`                                                       |
| Move into a directory that's inside your working directory | `cd name-of-directory`                                        |
| Move into a directory that's elsewhere                     | `cd /path/name-of-directory`                                  |
| Move into the home directory                               | `cd ~`                                                        |
| List the contents of a directory                           | `ls`                                                          |
| Make a new directory                                       | `mkdir name-of-directory`                                     |
| Make a new empty file                                      | `touch name-of-file`                                          |
| Open nano to edit a text file                              | `nano name-of-file`                                           |
| Display the contents of a file                             | `cat name-of-file`                                            |
| Copy the contents of a file into a new file                | `cat my-file.txt > new-file.txt`                              |
| Create a copy of a file and put it in a specific directory | `cp my-file.txt target-directory`                             |
| Move a file into a specific directory                      | `mv my-file.txt target-directory`                             |
| Delete a file                                              | `rm name-of-file`                                             |
| Delete an empty directory                                  | `rm -d name-of-directory`                                     |
| Delete a non-empty directory                               | `rm -r name-of-directory`                                     |
| Run a command as the superuser                             | `sudo command`                                                |
| Update the software packages on your system                | `sudo apt update`                                             |
| Upgrade the software packages on your system               | `sudo apt upgrade`                                            |
| Create a new user                                          | `sudo adduser name-of-user`                                   |
| Give a user sudo privileges                                | `sudo usermod -aG sudo name-of-user`                          |
| Log in as a different user                                 | `su name-of-user`                                             |