Learn Linux

The EV3 brick runs a version of the Linux operating system, and the microSD card that you have prepared also contains a version of Linux called EV3dev. Linux is more popular than you might think, for the Android operating system that is wildly popular on smartphones and tablets is actually a version of Linux.

You are looking at this page because you have chosen NOT to follow my advice to use Visual Studio Code to write and run programs for the EV3. Since you have made that choice, you will often be interacting directly with Linux when you use the terminal or console so you need to be familiar with some basic Linux commands. Here are a few, but you should make an effort to learn more about Linux and I will therefore suggest a few links. I have to say that I myself don't like having to learn such unintuitive and cryptic commands - this is one of the reasons I like to use MobaXTerm to manage my SSH sessions. Using MobaXTerm most of the operations below can be done in intuitive ways without having to use the corresponding Linux commands. The commands highlighted in orange are the ones that that you do NOT have to memorise if you use MobaXTerm because MobaXTerm makes it easy to carry out the same operations without using a Linux command. 

In the console, the Linux command prompt probably looks like this for you, since you are logged on as 'robot':

Be aware that the password for the 'robot' user is 'maker' by default.

At the command prompt, you will find the following commands useful. Many of them have options or 'switches' but you will have look elsewhere to learn about them. Don't forget that Linux is case-sensitive!

sudo is short for 'superuser do' and the superuser is the equivalent of the 'administrator' in Windows. Sometimes you have to precede certain commands with 'sudo', as mentioned below.

ls lists the contents of the current directory, or folder. When I run that command I see this

because my home directory called 'robot' contains some Python programs and a subdirectory called 'projects', but your 'robot' directory will initially be empty when you start using EV3 Python.

mkdir creates a new directory inside the current directory. For example, to create a new directory called inside the current directory called 'demos' then you would type mkdir demos. Note that directory names (and file names) in Linux cannot begin with a digit and can only contain the characters a-z, A-Z, 0-9, '-' and '_'. Spaces are not allowed in directory names or file names. After running the mkdir command you will probably want to run the ls command to make sure that the directory has been created successfully.

cd (change directory) lets you switch from the current directory into a different one. For example, if the current directory contains a subdirectory called 'projects' then you could switch into it by running the command cd projects. You can move from the current directory to its parent directory by running cd .. (note the space between cd and the two dots.

mv (shortened from “move”) is used to move files and folders, but can also be used to rename files. To move files and folders, see HERE. The following syntax is used to rename files with mv:    mv (option) filename1.ext filename2.ext     where “filename1.ext” is the original, “old” name of the file, and “filename2.ext” the new name.

rmdir is used to remove (delete) an EMPTY directory. For example, to remove an EMPTY directory called 'projects, run rmdir projects.

cp is used to make copies of files and directories. To make a copy of a file into the same directory: cp origfile newfile creates a copy 'newfile' of the original file 'origfile' in the working directory. CAREFUL! If the destination file newfile already exists, it will be overwritten without a confirmation prompt. To copy a directory and it all its contents: cp -R /one/two /three/four would copy the directory two (located in the directory /one), and everything two contains, into the destination directory /three/four. The result will be called /three/four/two. The directory /three must already exist for the command to succeed. If the directory four does not already exist in the directory /three, it will be created. For more examples see HERE.

rm is used to remove (delete) a file. For example, to delete a file called drive.py in the current directory, use rm drive.py. rm is usually used to remove files, but it can also be used to remove directories, even directories that are not empty, by using the -r 'switch'. For example, to remove a directory named "files", you would type rm -r files at the prompt.

> can be used to create a new text file. Since a Python script is a text file we can use it to create an empty Python script. For example, to create an empty Python file with the name myscript.py, type > myscript.py . You should see this:

Notice that you are returned to the prompt with no indication that a file was created. You can check that the file exists by using the “ls” command if you wish.

touch can also be used to create a new text file, and therefore can be used to create a new Python file. Type “touch” followed by a filename. For example type touch myscript.py to create an empty Python file with the name myscript.py. Warning: the > command and the touch command will overwrite any existing file with that name without warning you!

python3 is used in our ev3dev version of Linux to start an interactive session with Python version 3. For help with Python, see the 'Learn Python' and 'Learn EV3 Python' pages.

python3 <filename> is used to launch a Python file in the current folder within Python3. For example, to launch a Python file called drive.py, use python3 drive.py 

./ can be used to launch some kinds of executable files but CANNOT be used to launch a Python script, even though that script may have been made into an executable file. For example, to launch an executable file called rpyc_server.sh you would type ./rpyc_server.sh . As a beginner, you will very rarely need t use ./

chmod +x <filename> is what you need to use to make the script filename executable so that it can be run from Brickman. For example, to make a script called myscript.py executable you would run  chmod +x myscript.py

sudo chvt 6 is what you need to use before attempting to run from SSH any script that uses the EV3's LCD screen. If you don't run this the script and Brickman will fight for control of the LCD screen. When the script has finished running you should run sudo chvt 1 to give control of the screen back to Brickman.

man (manual) is supposed to give you help with specific Linux commands. For example, man ls should give you help with the ls command, but in the EV3dev version of Linux the man command does not seem to work.

help() can be used to get help with Linux, but it's not designed for newbies and you may not find it very helpful. Type quit to exit the help system.

exit or logout lets you terminate your session.

The above listing is a microscopic sample of the Linux commands available, and you should certainly follow some of the links below to learn more about Linux.

As previously stated, if you are using MobaXTerm instead of PuTTY, then you won't need to learn or use the Linux commands highlighted in orange above. The left panel in MobaXTerm shows (if the Sftp tab is selected) a directory listing, as in this image.

You can enter the 'projects' directory shown in the image by double-clicking it, or enter the parent directory by double-clicking '..'.

If you right-click an empty part of the panel (as I did when the snapshot was taken) you have options to easily create a new directory or a new file (such as my-python-prog.py) or move to the parent directory. You can also easily upload a file from the PC into the current directory on the EV3.

If you right-click a file you can easily rename or delete the file, download it to the PC, open it with MobaXTerm's built-in text editor or open it with another program of your choice, such as Microsoft Visual Studio Code (VS Code), the free Python IDE (integrated development environment) that I recommend to newbies.

You can download or upload files between the PC and the EV3 using drag-and-drop, but curiously it does not seem possible to use drag-and-drop to move files within the directory listing panel itself. For example, in my image, I would not be able to move the sound.py file into the projects directory by dragging it there. Am I missing something?

Here are a few sites where you can learn more about Linux:

To be honest, learning about Linux by using the EV3 is not ideal because you can't plug a screen, a mouse and a keyboard into the EV3 and therefore you have to communicate with it via a 'proper' computer. If you're serious about learning Linux and don't own a Linux computer (other than your EV3 and your phone and your tablet!) then consider buying a Raspberry Pi, a proper Linux computer the size of a pack of cards that costs about $30. See my robotics site HERE for more info. It has input/output terminals that make it capable of controlling a robot or other devices and it has been massively adopted by schools in the UK, so there are many reasons to want to get experience with the Pi. Warning: you may end up enjoying working with the Raspberry Pi so much that you might forget about the EV3! Be reassured though that EV3 and Raspberry Pi are not separate universes - you can use the Raspberry Pi to control EV3 hardware using interfaces such as BrickPi or PiStorms. You can even run EV3dev and EV3 Python on the Raspberry Pi!