Working on Linux Shell
Simply put, the shell is a program that takes commands from the keyboard and gives them to the operating system to perform. Since we will be working on BeagleBone board as a development board to build electronics projects, plugging it to a Monitor, Keyboard, and Mouse every time to work on it like a computer might be unwanted most of the times and you might need more resources also which is unnecessary all the time. So we will be using the shell command-line interface to work on the BeagleBone boards. If you want to learn more about the Linux command-line interfaces, I would suggest you visit to http://linuxcommand.org/.
Now let's go ahead and try some basic shell commands and do something on your BeagleBone board.
You can see the kernel version using the command uname -r
. Just type the command and hit enter on your keyboard, the command will get executed and you will see the output as shown here:
Next, let us check the date
on your BeagleBone board:
Like this shell will execute your commands and you can work on your BeagleBone boards via the shell.
Getting kernel version and date was just for a sample test. Now let's move ahead and start working with the filesystem.
ls
: This stands for list command. This command will list out and display the names of folders and files available in the current working directory on which you are working.pwd
: This stands for print working directory command. This command prints the current working directory in which you are present.mkdir
: This stands for make directory command. This command will create a directory in other words a folder, but you need to mention the name of the directory you want to create in the command followed by it.
Say I want to create a folder with the name WorkSpace
, I should enter the command as follows:
When you execute this command, it will create a folder named WorkSpace
inside the current working directory you are in, to check whether the directory was created. You can try the ls command again and see that the directory named WorkSpace
has been created.
To change the working directory and go inside the WorkSpace
directory, you can use the next command that we will be seeing.
cd
: This stands for change directory command. This command will help you switch between directories depending on the path you provide along with this command.
Now to switch and get inside the WorkSpace
directory that you created, you can type the command as follows:
cd WorkSpace
You can note that whenever you type a command, it executes in the current working that you are in. So the execution of cd WorkSpace
now will be equivalent to cd /home/debian/WorkSpace
as your current working directory is /home/debian
.
Now you can see that you have got inside the WorkSpace
folder, which is empty right now, so if you type the ls
command now, it will just go to the next line on the shell terminal, it will not output anything as the folder is empty.
Now if you execute the pwd
command, you will see that your current working directory has changed.
cat
: This stands for the cat command. This is one of the most basic commands that is used to read, write, and append data to files in shell.
To create a text file and add some content to it, you just need to type the cat
command cat > filename.txt
Say I want to create a sample.txt file, I would type the command as shown next:
Once you type, the cursor will be waiting for the text you want to type inside the text file you created. Now you can type whatever text you want to type and when you are done press Ctrl + D. It will save the file and get back to the command-line interface.
Say I typed This is a test and then pressed Ctrl + D. The shell will look as shown next.
Now if you type ls
command, you can see the text file inside the WorkSpace
directory.
If you want to read the contents of the sample.txt
file, again you can use the cat
command as follows:
Alternatively, you can even use the more
command which we will be using mostly:
Now that we saw how we can create a file, let's see how to delete what we created.
rm
: This stands for remove command. This will let you delete any file by typing the filename or filename along with path followed by the command.
Say now we want to delete the sample.txt
file we created, the command can be either rm sample.txt
which will be equivalent to rm /home/debian/WorkSpace/sample.txt
as your current working directory is /home/debian/Workspace
.
After you execute this command, if you try to list the contents of the directory, you will notice that the file has been deleted and now the directory is empty.
Like this, you can make use of the shell commands work on your BeagleBone board via SSH over Ethernet or Wi-Fi. We will be seeing how to connect your BeagleBone board to Wi-Fi in BeagleBone board to connect to your router via Wi-Fi instead of Ethernet to give wireless access to your BeagleBone board.
Now that you have got a clear idea and hands-on experience on using the Linux Shell, let's go ahead and start working with python and write a sample program on a text editor on Linux and test it in the next and last topic of this chapter.