Linux Command Basics

Before diving into robotics with ROS, it's important to understand some basic Linux commands. These commands will help you navigate the system, manage files, and perform various tasks efficiently. Think of the Linux terminal as a place where you can interact with the computer using text commands instead of clicking on things like you do with a graphical interface.

1. Opening the Terminal

First, you’ll need to open the terminal, which is where you will type in the commands. On Ubuntu, you can do this by:

  • Pressing Ctrl + Alt + T on your keyboard, or

  • Clicking on the Terminal icon in the application menu.

Now, let’s dive into some basic commands.


2. Navigating the File System

When working in Linux, you’ll often need to navigate through different directories (folders). Here are some commands to help you move around.

  • pwd (Print Working Directory): This command shows you the full path of the directory you are currently in.

    Example:

    $ pwd
    /home/your-username

    This tells you that you are in the home directory of your user.

  • ls (List): This command lists the contents of the directory you are currently in. You’ll see files and folders.

    Example:

    $ ls
    Documents  Downloads  Pictures  ros_workspace

    This shows all files and folders in the current directory.

  • cd (Change Directory): Use this command to move from one directory to another.

    Example:

    This will move you into the Documents folder. If you want to go back to the previous directory, you can type:

    The .. means "go up one level" in the directory structure.


3. Managing Files and Directories

In Linux, you can create, copy, move, and delete files and directories using simple commands.

  • mkdir (Make Directory): This command creates a new directory (folder).

    Example:

    This creates a folder called my_new_folder in your current directory.

  • touch: This command creates a new, empty file.

    Example:

    This creates an empty file called example.txt.

  • cp (Copy): Use this command to copy files from one location to another.

    Example:

    This copies the file example.txt to the Documents folder.

  • mv (Move or Rename): This command moves a file or folder to another location, or renames it.

    Example 1 (Moving a file):

    This moves example.txt into the Documents folder.

    Example 2 (Renaming a file):

    This renames example.txt to new_example.txt.

  • rm (Remove): This command deletes a file.

    Example:

    This deletes example.txt. Be careful—once a file is deleted with rm, it cannot be easily recovered.

  • rmdir (Remove Directory): This command deletes an empty directory.

    Example:

    This deletes the folder my_new_folder. If the folder is not empty, you can use:

    The -r option tells Linux to remove the folder and everything inside it.


4. Viewing and Editing Files

Sometimes you’ll need to read or edit files directly from the terminal.

  • cat (Concatenate): This command displays the contents of a file.

    Example:

    This will print the contents of example.txt to the terminal.

  • nano (Text Editor): This opens a file in a basic text editor right in the terminal.

    Example:

    This will open example.txt in the nano editor, allowing you to make changes. To save and exit, press Ctrl + O (to save) and then Ctrl + X (to exit).


5. Checking System Information

You might need to check some basic information about your system.

  • uname -a: This command shows system information like your kernel version and system architecture.

    Example:

  • df -h: This command shows the disk usage on your system in a human-readable format.

    Example:

  • top: This command shows the current running processes and system resource usage (like CPU and memory).

    Example:

    To exit the top display, press q.


6. Installing Software with APT

In Linux, you often install software from the terminal. Ubuntu uses a package manager called APT (Advanced Package Tool).

  • sudo apt update: This updates the list of available software packages.

    Example:

  • sudo apt install <package-name>: This installs a software package.

    Example:

    This will install ROS 2 Foxy Desktop. The sudo command gives you administrator privileges for installing software.


7. Getting Help

If you’re not sure how to use a command or want to learn more about it, Linux offers built-in help.

  • man (Manual): This command shows the manual or documentation for a command.

    Example:

    This will show the manual for the ls command, explaining all the options you can use with it.

  • --help: Most commands also have a help option to give a quick overview.

    Example:


"Practice Makes Perfect"

These are just some basic Linux commands to get you started. As you progress through this training, you’ll use these commands frequently to manage files, navigate the system, and work with ROS. Don’t worry if they seem tricky at first—the more you use them, the more familiar they will become!

Last updated