Basic Linux commands and navigating the filesystem
After completing Chapter 1, Getting Started with the BeagleBone Black, you should have a working BeagleBone Black running a version of Linux called Ubuntu. We selected this distribution because it is the most popular and has the largest set of supported hardware and software. The commands I am going to review should also work with other versions of Linux, but I'll be showing examples using Ubuntu.
Prepare for lift off
So, power up your BeagleBone Black and log in using the proper username and password. If you are going to log in remotely, go ahead and establish the connection and log in. Now we will take a quick tour of Linux. This will not be extensive, but we will walk through some of the basic commands.
Engage thrusters
Once you have logged in, you should open up a terminal window. If you are logging in using a keyboard, mouse, and monitor, or using vncserver, you'll find the terminal selection by selecting the Applications Menu in the upper-left hand corner, then selecting the Terminal Emulator selection, as shown in the following screenshot:
Tip
Downloading the example code and colored images
You can download the example code files and colored images for this Packt book you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
If you are using PuTTY to use SSH to log in, you should already be at the terminal emulator program. Either way, it should look something like this:
Your cursor is at the command prompt. Unlike Microsoft Windows, or Apple's OS, most of our work will be done by actually typing commands into the command line. So, let's try a few. First, type ll
, and you should something like this:
The command ll
in Linux is an abbreviation for list-long and lists all the files and directories in our current directory with information about who owns the files, the times they were created, and the various permissions on the files. The files are listed by their names; you can tell the directories because they are normally in a different color, and d
proceeds the lines for those listing. In this case Videos
is a directory. The default installation of Ubuntu has no directories. Installing the Xfce windows manager creates the Desktop
, Documents
, Downloads
, Music
, Pictures
, Public
, Templates
, and Videos
directories.
You can move around the directory structure by issuing the cd
(change-directory) command. For example, if you want to see what is in the Videos
directory, type cd ./Videos
. Now if you issue the ll
command, you should see something like this:
This directory is empty, except for a couple of default directory selections. Now, I should point out that you used a shortcut when you typed cd ./Videos
. The .
is a shortcut for the default directory. You could also have typed cd /home/ubuntu/Videos
and gotten the exact same result, because you were in the /home/ubuntu
directory, which is the directory where you always start when you first log in to the system.
If you ever want to see which directory you are in, simply type pwd
, which stands for print-working-directory. If you do that here, you should get:
The result is /home/ubuntu/Videos
. Now, you can use two different shortcuts to move back to the default directory. The first is to type cd ..
; this will take you to the directory just above this one in the hierarchy. Do this, then type pwd
, and you should see the following:
The other way to get back to the home directory is to type cd ~
, as this will always return you to the home directory. If you were to do this from the Videos
directory, and then type pwd
, you will see something like this:
You can also use cd –
, which will direct you to the last directory accessed. Another way to go to a specific file is to use the entire path name. In this case, if you want to go to the /home/ubuntu/Video
directory from anywhere in the filesystem, simply type cd /home/ubuntu/Video
and you will go to that directory.
There are a number of other Linux commands that you might find useful as you program your robot. Here is a table with some of the more useful commands:
Objective complete – mini debriefing
Now you can play around and look at your system and the files that are available to you. Be a bit careful! Linux is not like Windows; it will not warn you if you try to delete a file, or copy over a current file.