empowering creative people

Videos / Raspberry Pi Workshop - Chapter 1 - Introduction to Shell

The full Raspberry Pi Workshop in step-by-step format can be found here http://coreelec.io/piworkshop The shell is a program which processes our commands and returns outputs.

Search Videos

Related Content

Transcript

+

The Shell is a program that processes our commands that we enter and returns outputs. It’s worth getting familiar with the shell because it’s an incredibly powerful tool. For now I’m just going to cover some basics like navigating the file system and making files and as we move further through the workshops we’ll cover more specific commands and scenarios as we cross them. Let’s go!

So there are a couple of ways we can access the shell, one that we’ve already done is to run the Terminal emulator from here, the other is we can open up the Pi menu, go down to accessories  and go to terminal. I’m just going to increase the font size just to make it a little friendlier. So the first thing we’re greeted with is the prompt. Pi is the current user and Raspberry Pi is the machine that we’re accessing. This tilde character ~ is a special  shorthand for that home Pi directory that we saw in the last video. This dollar symbol $ is the prompt - it’s the shell waiting for our commands. So just on that tilde character, if we print working directory which is pwd we can see that tilde corresponds to /home/pi. Now we can list the contents of the directory that we’re currently in with the ls command and we can see that there are a few items - these blue items are in fact other directories so we could move into them but for now what we are going to do is just create a little sandbox to play around in for chapter one. We’re going to use the make directory command which is mkdir and I’m going to clashes directory ch1 for chapter 1. We can see that there is no feedback, our command has just been executed but it’s been executed silently.The shell assumes that we know what we are doing and that we don’t need to be bothered with constant reassurance that what we’ve directed it to do has actually been done. So we can execute the ls command again to see that, yes, our chapter 1 directory has been created. So lets move into that now with the cd command - that’s for change directory. We’re going to cd to chapter 1 directory and it’s important to note that now our prompt has changed and it’s updated the prompt to show us our current directory and we could print the directory again but this is just as good as long as we always remember that the tilde is shorthand for the home directory then this prompt is telling us that we’re in home, pi, chapter one. While we’re here we’ll make a couple of extra directories just to practice using some commands. So lets make 3 directories. I’m login to make directory test 1, make directory test 2 and make directory test 3 and of course all of that happened without any feedback and if we execute ls there they are.

So now I’ve got my chapter one directory with 3 small directories inside it. How about we make a text file. We can do this with the nano text editor and if we execute nano it will just open the nano program and we can write our file. If we already know what we want to name the file we can put in a name here like ‘textfile’ and that will create a file called text file in the directory we’re currently in. Now I could navigate into test 1 and create the test file there or when i’m creating the file, in the file name I could enter a relative path to where I want to put the text file so I could say text1/txt file and this is going to say from where I am currently there is already a directory called test1. In that directory I want to create text file so of we strike enter we leave the shell and we’re presented with the nano text editor. So we have an empty screen to enter our text and down the bottom we have our menu. This is a very very stripped back text editor as you can see. It’s very simple, these are caret symbols, these up arrow symbols represent a control so a ^X  would exit the program. Lets just enter some text, I’m just going to  say hello world and  now I’m going to press ^X to exit. We’re greeted with this save modified buffer message, that’s just saying “do you want to save the changes?” and I do so I’ll select Y for yes and because we already entered a file name for the text file it’s already populated test1/textfile into the file name to write and because that is what I want to call it I’m just going to strike enter.  When we do that we’ve dropped back into the shell so we can perform ls we can see nothing has changed. Rather than jump in to the test1 file with the cd command and then executing ls to see if our text file is there we can just say ls test1 and that’s just parsing to ls - I want to list the contents of this directory and we can see that textfile is indeed there.  Again we could edit the text file and we don’t even have to be in the test1 directory to do it, we can just execute nano test/textfile again and to recall that command history I’ve just used the up and down arrow keys to scroll through the past commands I’ve issued so I can go back up to nano test/textfile and start editing the text file without actually having to be in the directory. I’m just going to ^X out of that.

Now let’s delete our text file, so we could use the rm command to delete the text file and rather than seeding into the directory I’m going to do exactly he same thing. I’m going to say in the test1 directory there is a file called text file and that appears to have worked - again there is no feedback. So we can delete files, potentially important files and we won’t receive  any feedback about it.  Again we can perform our ls test1 and we can see that test1 is empty. So we’ve managed to write a text file, delete it, make a few directories and now let’s delete the directories. We could try to rm the test1 directory but rm has a built in safety, rm is no good for deleting directories just used as is.  We can see we can’t remove test1 - it’s a directory. We could use the rmdir command which is made for removing directories that are only empty. It will only remove empty directories, if I try to use this command when textfile was in test1 we wouldn’t be able to do it but if we remove directory test1 and ls again we can see that test1 has disappeared. If the screen ever gets a little too cluttered or messy you can of course always just  keep striking enter to create space or you can type clear and that clears the window for you,

Now I’m going to remove the other 2 test directories. So we can see that we have test 2 and test 3 remaining and rather than manually typing out test2 test3 in the rm directory command I’m going to use the wild card so I can type in $ rmdir and I’m going to type in test and then * which is a substitute for any number of characters. If I execute that and perform ls again we can see the directory is empty.

So that concludes running over the basics of the shell and in the next video we’re going to learn how to keep our Raspberry Pi up to date :-) 

comments