Navigation on the Raspberry Pi

From Sensors in Schools
Jump to navigation Jump to search

Navigation on the Raspberry Pi

  • In this lesson we will be learning how to navigate up and down the file structure of the Raspberry Pi. This lesson can be applied to any Linux operating system.

Learning Objectives

  • Learn how to navigate the Linux directory
  • Finding the Raspberry Pi internal IP address
  • Make directories and files in the Terminal
  • Learn how to read and modify files
  • Updating the Raspberry Pi system software library

Learn how to navigate the Linux directory

Open the Raspberry Pi Terminal

  • From the Raspberry Pi desktop open up the Terminal.
  • The Terminal is the small black box looking icon at the top left of the Desktop
  • When you open the Terminal it will appear as a large window with a black background.
  • All inputs to this window will be text (command based). We won't use a mouse.

Adjusting font settings

  • When you first open the Terminal you may need to adjust the Font settings.
  • To edit settings, from the top drop-down menu select Edit > Preferences.
  • Click on the box to the right of Terminal font.

  • This will open up another window where you can adjust font size and type.
  • Increase the font size to 18.
  • Click Select and then OK to make the changes permanent.

Check for files and directories

  • Now that we know how to open up the Terminal we can use it to navigate around the Raspberry Pi.
  • When we start we are in the user pi home directory.
  • To list all the files and directories we enter the command ls
  • You should see a list appear:
    • white items are files
    • blue items are directories (directories can be empty, or have other files and directories inside)

Navigating up and down directories

  • The directory structure on the Raspberry Pi is arranged in the form of a tree.
  • To go back down the tree - towards the root - we need to enter the command cd .. (cd and two dots)
  • cd is short for Change Directory
  • Every time we enter this command (cd ..) it will take us down the tree.
  • The Terminal tells us that we have moved down one branch and are now in the /home directory

  • If we enter the command cd .. again it will take us right down to the root of the tree.
  • This is symbolised by the / (forward slash) symbol.

  • Using the ls command we can have a look around to see what branches are coming up out of the root (/) directory.
  • Enter the command ls

  • Another way we can find out where we are in the Raspberry Pi (Linux) directory is to enter the command pwd
  • pwd is short for Present Working Directory.
  • In the root directory, the output will be the / symbol (forward slash).
  • This is as low down the tree as we can travel.

  • Let's go up the /home directory. To do this enter the command cd home
  • The home directory is one of the many branches travelling up from the root.

  • To go up the branch into the pi directory enter the command cd pi

  • home/pi is normally shown just as a ~ (tilde symbol).
  • If you see this then you are in your pi user home directory.
  • We can also enter cd ~ to go home:)

Checking your Raspberry Pi internal IP address

Finding your IP address

  • Once you have connected to your home WiFi router you can find the IP address for your Raspberry Pi by hovering you mouse above the WiFI icon (top right of desktop).
  • You should see your IP address on the third line.
  • In the example below by Raspberry Pi IP address is 192.168.0.32
  • Everyone's IP address will be different and the IP address may change each time you start your Raspberry Pi.
  • There are also ways to make sure your IP address stays the same.

  • Another way you can find your IP address is from the Terminal.
  • Enter the command ifconfig

  • Scroll to the end of the Terminal output and look for wlan0
  • wlan is short for Wireless Local Area Network.
  • If you look closely on the second line you will see the IP address after inet - 192.168.0.73



Making Directories and Files in the Terminal

Creating a Directory

  • Up to now we have navigated up and down directories. In this lesson we will show you have to make new directories and also to populated them with files.
  • To make a new directory techschool we enter the command mkdir techschool

  • To check that the new directory has been created use the ls command.
  • To enter into the techschool directory we enter the command cd techschool
  • You can also check to see if you have entered the /home/pi/techschool directory correctly be entering the command pwd (present working directory).

Looking inside the directory

  • If we type in the command ls we can have a look inside the techschool directory.
  • At the moment the directory is empty.

Creating a file within the directory

  • We can now quickly create an empty file in the techschool directory
  • Enter the command touch test1.txt we create a new file called text1.txt
  • The file name and extension do not matter.
  • You don't have to write a file extension, and you could also add any extension (e.g. .dat .exe .csv)

  • Let's create another file called dummy.txt by entering the command touch dummy.txt
  • Then enter ls to check that its been created.

  • Create a few more files with the touch command and then enter the ls command to list them.

  • We have just been using the ls command by itself.
  • We can add an Option to the ls command.
  • By entering ls -l (-l is short for long format) it will list all files in long format.
  • This will include other details about each file such as who the owner is and when the file was created.

Creating another directory

  • Once again, we can make a new directory called backup with the command mkdir backup
  • If we enter the command ls -l we can see that there is a lower case d in the line with the directory backup. The d tells us that this item is a directory.

Navigating back to home directory

  • After all this fun we need to navigate back to our home directory.
  • The easy way to do this is to enter the command cd ~ (tilde symbol - below the Escape key).
  • You can prove that you are in the pi user home directory with the command pwd

Updating the Raspberry Pi System Software Library

The great thing about the Raspberry Pi is that you can install lots of free software.

The software is written by a community of computer enthusiasts who believe that most things in life should be free - especially computer software and operating systems.

Before we can install or search for any new software we need to update a software library catalog stored on our computer.

  • To update our local library we need to enter the command sudo apt-get update
    • sudo is short for Super User. It gives us special powers
    • apt-get is the program or application that is responsible for maintain the software library
    • update is the instruction to update the library

When you enter the command your computer will start the update process.

Sometimes this takes only a few seconds, but it can take longer depending on the speed of your internet connection and also how many updates to the library are required.