Repository navigation
Working with Ubuntu
This section explains how to use basic command line commands, a little about ownership and what a PATH is, how to install new packages, how to use git and some of the associated terminology.
Ubuntu is a Linux distribution developed by Canonical. It is an operating system based on the linux kernel, a descendent of one of the early operating systems, called Unix. The function of an operating system is as an interface between a computer user and its hardware. It manages things like memory management, process management and controlling peripheral devices such as disk drives and printers. In the rest of the guide we assume that you are using Ubuntu.
Guidance for installing Ubuntu is usually given in the first year bachelors program that you follow. If needed, a guide on how to install Ubuntu can be found here
The terminal can be opened using the keyboard shortcut Ctrl-Alt-T. Once you open the terminal you can use Ubuntu's default shell, Bash. The shell is a text-only user interface for Ubuntu. This means you can use it to perform all normal operations like making new files, moving files around, starting applications, etc. The text you see after opening the terminal is referred to as the prompt. Executing operations like making a new file can be done entering commands into the command line, the area behind the prompt where you can enter commands.
Tip: If you have copied something into your clipboard, you can paste it in the terminal using Ctrl-Shift-V.
All your files are stored in a file system, which consists of directories that contain other directories and files. Where you are in this hierarchy is referred to as your current working directory. When you initially open the terminal, you will find yourself in the home directory. To view your current working directory, use the command pwd, which is short for 'print working directory'. This command will probably result in something like /home/<your-username>.
Note: if you see notation with <>, this means that this is something that is platform dependent or a parameter you can fill in yourself.
You can change the directory you are in using the cd, short for change directory command. Use this command by following it up with the name of the directory you want to go to or .. to move up to the parent directory. If you enter the command cd /, you will go to the root of the file system, also referred to as the root directory. From here you can move back to your home directory by first going into the /home directory with the command cd home and then cd <your-username>. You can also chain multiple cd commands by combining them with a /. So you could also move from your root directory to your home directory with one command cd home/YOUR_USERNAME. Since you will often need to go back to your home directory there is also a shortcut for this directory ~ just as there is with the root directory /. These can also be chained, so you can use the command cd ~/Documents to change to the Documents directory. As you change directories you will see the prompt change, indicating in what directory you are.
Tip: while navigating through your directories use Tab for auto completion.
Before continuing, let's make a new directory to work in, so we don not mess up any of the other currently existing files/directories. You can make a new directory using the command mkdir. Make a new directory in your /tmp folder by executing the command mkdir /tmp/newdir. Notice the use of an absolute path, to make sure that we create the tutorial directory inside /tmp. Without the forward slash at the start, the mkdir command would try to find a tmp directory inside the current working directory, then try to create a tutorial directory inside that. If it couldn’t find a tmp directory the command would fail. Move into the new directory. Once you are there you can make multiple subdirectories in a single command mkdir dir1 dir2 dir3. The three names of the subdirectories we passed to the mkdir command are referred to as it's arguments.
To see what files and folders there are in this directory, use the command ls. You should see the three directories we just made.
Some times you might want to make nested directories. This can be done by using a flag -p the full command will now be mkdir -p dir4/dir5/dir6. Flags are a way to specify certain options for commands you enter into the command line. You will see that only the dir4 is added to the contents of the current directory, as dir5 and dir6 are contained within dir4. Check this by moving around and using the ls command.
Move into dir1. To print something in the terminal you can use the command echo, for example the command echo hello will print the text hello to in your terminal. You can redirect the output of a command into a file using >. For example if you execute the command echo hello > hello.txt the text hello will be stored in the file hello.txt. To check this, you can use the command cat to print the contents of the file which should be hello. You can use the command >> to append to an existing file without completely replacing its contents as > would do, test this out. Once you have created this file, you can make copies of it using the cp command or remove it using the rm command. You can move the file around by using the mv command, for example you can move the file hello.txt into dir2 with the command mv hello.txt ../dir2. The move command can also be used to rename files. The command mv ../dir2/hello.txt ../dir2/hi.txt, will rename the file hello.txt to hi.txt. If you want to remove the contents of an entire directory, meaning that directory and the files/other directories it contains, you can use the command rm -r. Be very careful when using this command, as it cannot be undone.
There are several other ways of making a new file. To simply create an empty file, you can use the command touch <filename>. You can also run an editor to edit and save files. Usually such a command would look like this <editor> <filename>. For small edits you could use a default editor that is shipped with Ubuntu called nano. You can use nano by executing the command nano <filename>.
When you want to execute multiple commands, you can use &&, for example the command cd .. && echo hello will move to the parent directory and print hello to the terminal. It is also possible to pipe the output of one command to the input of another. You could pipe the output of the ls command into the grep command. The grep command can be used for searching. So piping the output of ls into grep, means you can search through all listed files, when looking for a certain file in a directory, you could use the command ls || grep <filename>. Play around with this and test this out.
When finding information about commands or finding new commands, google is your best friend. But often more effective is using the command man followed by the command you want to find more information about. This will give a precise definition of that command. From now on you can use this tool to look up information about any of the given commands. Additionally almost all commands take the -h or --help flag as a parameter for information about that command.
Some commands are only allowed to be executed by the superuser also referred to as root. To execute a command as root, prefix the command you want to use with sudo.
A flag that can be used with ls to see more information about the files in your current directory, you can add the flag -a. This means the entire command you entire is ls -a. The first bit of information you will see is a series of 10 characters. The first indicates what type of file this is.
| Character | Type |
|---|---|
| - | Normal file |
| d | Directory |
| l | Symbolic link |
| p | Named pipe |
| b | Blocked device |
| c | Character device |
| s | Socket |
The following 9 characters describe who is allowed to manipulate that file in what way. Every file and directory in the file system has three types of owners: owner, user, group. Each three following letter indicate whether owners of that type may read that file in that order. These permissions are indicated with and 'r', write to that file indicated with an 'w' or execute that file, indicated with and 'x'.
| Type | Definition |
|---|---|
| Owner | Permissions used by the assigned owner of the file or directory |
| Group | Permissions used by members of the group that owns the file or directory |
| Other | Permissions used by all users other than the file owner, and members of the group that owns the file or the directory |
For executing a file it might be necessary to change these permissions, such that you are allowed to execute the file, this can be done with the command chmod, usually chmod u+x <filename>.
An executable file can be executed from the command line by entering the path to that file. All basic commands you have entered so far are such executable files and can be found in /bin. Check this for yourself (More information on the filesystem hierarchy can be found here). When executing how does your shell know what commands to execute? When executing a command, the shell will look into all directories on your PATH, if it can find the command you are executing. If it cannot not find the command, the command will fail. PATH is called environment variable. What directories are contained in your path can be found out by executing the command echo $PATH, which prints the content of the environment variable PATH.
To set an environment variable you can use the command export, for example the command export EDITOR=/usr/bin/vim, will set the EDITOR environment variable to be /user/bin/vim. To add another path to your PATH you could use the command export PATH="/path/to/dir:$PATH". However you will notice that upon closing the shell this change will be forgotten. To make sure this environment variable changes permanently, you can add the command export PATH="/path/to/dir:$PATH" to the file ~/.bashrc which is a script (a file containing consecutive commands to be executed) that is executed every time a new shell session is started (every time you open the terminal). The easiest way to quickly edit a file is by using nano, which is a basic terminal editor installed by default. When using nano you can navigate using the arrow keys, make the changes you want to make and then save and exit, with the keybinding Ctrl-X and choosing to save the modified buffer.
When editing code, you want to have some more features then a simple terminal editor like nano provides, features like syntax highlighting, autocomplete or tools for debugging. This is what an IDE, short for Integrated Development Environment provides. There are many IDEs you could use, but we suggest using Visual Studio Code.
There are several ways for installing new tools like vscode. A package contains all the necessary files, meta-data, and instructions to implement a particular functionality or software application. Debian package files typically have the extension .deb, and usually exist in repositories which are collections of packages found online. Packages are normally in a pre-compiled binary format; thus installation is quick and requires no compiling of software.
Many packages use dependencies. Dependencies are additional packages required by the principal package in order to function properly. For example, the speech synthesis package festival depends upon the package alsa-utils, which is a package supplying the ALSA sound library tools needed for audio playback. In order for festival to function, it and all of its dependencies must be installed. This is what the package manager manages for you, Ubuntu's package manager is the Advanced Packaging Tool (APT). For most tools there will be a package available in one of the repositories that APT uses and you can simply install that tool by using the apt command line tool (you need to execute this command as the superuser) sudo apt install <package-name>. You can remove that tool again with the command sudo apt remove <package-name>.
You can also install newer versions of tools you have already installed. APT uses a cache of available packages. This cache does not contain the packages themselves, just the metadata (version, repository, dependency etc) of the package. If you don’t update this cache, APT does not know if there are newer packages available or not. You can update this cache by using the command sudo apt update. Then you can use the command sudo apt upgrade to update your current packages based on the updated cache.
Sometimes it might be the case that a package is not available or you want a newer version of the package than is currently available. In this case you might be provided a .deb file containing the package you want to install. For example for installing the newest version you can install a .deb file from the website. You can then install this package with the command sudo apt install <path-to-downloaded-deb-file>. Once you have installed vscode, you can open it from the application menu, or you can open a file from the terminal using vscode with the command code <filename>. If you have vscode installed you can install many useful extensions in the extensions tab on the left sidebar.
Tip: do you want to check if a certain package exists or what version it is? Use the --version flag.
- Home
- Organisation
- Working with Ubuntu
- Git
- Python
- Rust
-
Robot usage
- Setting up DNT
- pyNaoqi Setup Guide
- Connecting and compiling
- Teamcopy
-
Playing a match
- Setup
- Rules
- Working day
- Gamecontroller
-
Framework
- Overview
- Taal
-
Framework Applied
- Dummy
- Assignment