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.

Engage thrusters

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:

Engage thrusters

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:

Engage thrusters

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:

Engage thrusters

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:

Engage thrusters

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:

Engage thrusters

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:

Engage thrusters

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:

Linux command

What it does

ll

List-long: Lists all the files and directories in the current directory. This includes lots of extra information about the file, including time it was created, permissions, owners, and so on.

ls

List-short: Lists all the files and directories in the current directory by just their names.

rm filename

Remove: Removes whichever file is specified by the filename.

mv filename1 filename2

Move: Renames filename1 to filename2.

cp filename1 filename2

Copy: Copies filename1 to filename2.

mkdir directoryname

Make directory: Make a directory with the name. directoryname. This will be made in the current directory unless otherwise specified.

cat filename

Catalog filename: Displays the file, you may want to use the | less command at the end of this so that it will display the file a page at a time. Use the space bar to go to the next page.

clear

Clear: Clears the current terminal window.

sudo

Super user: If you type the sudo command in front of any command, it will do that command as the super user. This can be required if the command or program you are trying to execute needs super user permissions. If, at any point in this book, you type a command or the name of program you want to run and it seems to suggest that the command does not exist, or permission is denied, try it again with sudo in front of the command or name of the program.

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.69.199