 We're going to use the terminal to issue commands to our operating system so that we can do different things. And we want to do some very basic things to get started. And that includes moving about the file system, changing directories, creating directories, creating new files, copying files, deleting files, and then looking and editing files. So just some very basic things we do on a computer, I want to introduce you to the commands we use in Linux on the command line. Some of you may know them already. So it should be easy. The first thing to get started, we're going to interact with our computer and what we see on the window is the prompt. This is referred to as the prompt. It's prompting me to issue a command. It has some structure, which we'll explain as we go through. But then when I type something in, then press Enter. It runs a command on my computer and executes something. Now one thing that we need to know about is where is that command executed with respect to my computer? And where means which directory or folder is it executed in? So we need to know something about the structure of the folders and directories. I will use the word directory. Some people talk about folders, but the directory, and in fact, the set of directories and files we refer to as the file system. Does anyone use Windows as their main operating system? Put your hand up. It's okay. I won't give you a lower grade. All right. So Windows, you use folders and files. What is the top most directory in Windows? Again, program files, even above program files. C drive is, if you think of Windows talks in terms of drives, and maybe the top most directory, I don't know if it's still like that. Don't type this. This is just a comment. But is it something like that or like that? All right. So C drive, you can think, is the top most directory in our file system. C is the drive. Maybe other drives. And you can think that this backslash indicates the top most directory because we have a hierarchy of directories. Underneath that are subdirectories. What are some of the subdirectories? Someone said one in Windows. Program files. I don't know. I don't have Windows. So please tell me. What are some other subdirectories of the top one in Windows? C drive files, user or user and settings or something and maybe system in the old days or Windows, temp, documents or whatever. But you know that there are some common directories from the top most directory and under them are further directories. So we say we have a hierarchy and there's the top most directory and subdirectories and so on. In UNIX type operating systems, UNIX type refers to the class included Linux and UNIX operating systems. There are many variations. Mac OS X is a UNIX operating system. Linux that we're using is a UNIX type operating system. In that, there's also a hierarchy. The top most directory is represented by the character forward slash. Instead of backslash, it's forward slash. The separator of directories is a forward slash. This top most directory, we give a special name. We refer to it as the root directory, the root of our file system or the root of the tree and under that are subdirectories and so on. When we run a command on the command line, it's run in some directory. Which directory to find out, we can check the present working directory. So you can try the commands now, follow along. The present working directory, PWD, shows us what directory I'm currently in and the answer from the root directory, the forward slash, there's a sub directory called home and from that there's another sub directory called student. So we can think in the hierarchy or in the file system, I'm in the slash home slash student directory currently. Together this is called a path, the path in the file system. I think you know this already, it's a syntax maybe slightly different but you know the concepts but PWT tells you where you currently are. The first thing we want to do is move between directories, change directories. We use CD to do that, CD will change between directories where we usually provide where do we want to go. Maybe I want to go into the slash home directory, CD slash home, that's rattling, perfect thank you Sam. CD slash home takes me into the slash home directory, you may guess that it worked, there's a hint there but PWD tells me now I'm in the slash home directory or CD into the root directory. The forward slash on its own means the root directory, we can't go any higher if we think of that the top most level and we can go back to the slash home slash student. So we can change directories. When we specify a parameter here or the option to change a directory into which directory in all of these cases I started with a forward slash. This means it's an absolute path, absolute means in this case it's relative to the root directory but we don't need to start with a forward slash, we can have a relative path. Let's see what I mean. Currently I'm in slash home slash student, let's go into the root directory and I can change into the home directory, I didn't start with a, I'll type it again, I don't start with a forward slash and now I can change into the student directory. So when we pass a parameter to the CD command, if it starts with a slash it means it's from the root directory, if it doesn't start with a slash like CD student it means relative to the current directory. We were in home, we CD into the sub directory which is called student. So we can move up and down in the hierarchy, in fact an easier way to move up, there's a special type which is dot dot, CD dot dot moves up in the hierarchy. I was in slash home slash student, I moved up to slash home, if I go up again I'm in the root directory, so dot dot means upper level from where you're currently are. How do I go home? You don't want to go home yet, is that what you're saying? No? All right, good. But if we want to get our home directory, of course there are different ways. We can type in the specific directory slash home slash student and we're in our home directory and it's common in our operating system that, our operating system supports multiple users. One user is called the student user, one is called instructor, one is, and there are some other users on this each computer and those users have their own private directory in the slash home directory. So we are logged in as the student user, our home is slash home slash student. If I just briefly show you, I'm currently in this window logged in as the instructor user, my home is slash home slash instructor, different users have different homes. Same as what is it, users and settings or documents and settings or whatever it's called in Windows, different users have different directories. Now, as an example, let's go back to the root directory. A quick way to go home is just type CD with no arguments, CD on its own will always take you home. Another shortcut for the home directory is the tilde character, the squiggly line. As an example, go into the root directory, CD tilde also takes me to the home directory. So the squiggly line, the tilde character, it really means your home directory and that can be useful because we can talk about directories relative to our home. We'll see in a moment. That's a little bit about directories, but more importantly, what about files and what is inside directories. So I'll go home, make sure I am there, yes. We want to see what's inside a directory, we want to list the contents of the directory, we use LS. LS returns what's inside this current directory. And in my case, it shows that there are four things, code, posters, SVN and VM. And as a hint, when it's blue on your window, it means those four things, those things are a directory, not a file. Normally we talk about files and directories. There are some other special types, but we'll deal with files and directories. Because I set this up, I know that those four items, code, posters, SVN and VM are directories inside your home directory. So let's go into one of them, maybe the posters directory and we can LS there and we see a set of files. And you can guess that they're files, extension PDF and the fact that they're not blue is that they are files, not directories. Don't always rely on the color coding because different systems may have different colors and also some may be black and white or someone may be colorblind. So there's another way to show what is a file and directory, we'll see shortly. Actually we will see now. So LS shows lists the contents of a directory. We can pass arguments to LS. We can not just list the current directory but list a specific directory, LS slash. List the contents of the root directory and it shows in the root directory there are some subdirectories called bin, home, lib, root, user and others and some special files. That is the like the C drive directory and some of those directories are common across many different Unix like operating systems. Here's an example of listing the contents of a directory VM relative to my home directory. The tilde or squiggly line means slash home slash student. So that's really the same as doing this. The tilde is just a shortcut there. Many commands, so we've seen PWD, CD, LS, we'll see more. Many commands have options, extra features and they usually specify using a dash as an option, a dash followed by a letter. So LS, currently it shows the list of files in my directory. I'd like to see the file sizes. So I want to see the list of files and get the long output. I'll use the minus L option, LS minus L and now we see that same list of files but we see some more details about each of those files. The same way in Windows that you can show the file list in the Explorer as icons or you can show the details. I'm not going to explain all of this information today because some of that may be come up later or is not relevant just yet but going backwards, say for the biographies.pdf file, there's the file name, the date and time of the last modification of that file when it was last modified. Files actually have different timestamps associated with them. Not just when they were modified but when they were created. This is the last modified time. Look at this. The size in what's the units, bytes. This is the size in bytes. So this file is about six megabytes, this PDF. The next two going backwards are something about who owns this file. Because we have multiple users on the computer, each file has some ownership. One particular user owns that file. Which user? The student user owns the file. There's also some ownership with respect to groups of users, not just the individual user but a group of users. It turns out in this computer set up that there's also a group called student. This number one, not relevant, it's about links to the file. Let's ignore it. These ten characters, the first character, if it's a dash, it's a file. If it's a letter D, it's a directory. We'll see another example in a moment. The next nine characters are about the permissions on the file. Can we read, write and execute that file? And that's related to the users. We're not going to cover that today, the permissions. But just be aware, to find the file size and the date and time, even the owner, use LS minus L. If I LS minus L dot dot, meaning upper directory, we see that these have the letter D, meaning they are subdirectories. So that's how we really know it's a directory or file, whether that output is a D or a dash. Let's go home. Sometimes I may use clear just to clear out the screen so things are at the top. You don't need to. If you did, you fail, no, that's all right. I'll just do it so it's a bit clearer on the screen. You don't need to because it's sometimes useful to see what you've just done. LS, there are four directories we know in our home directory. In Windows you have hidden files and directories. Some files and directories are not displayed by default. We refer to as hidden files and directories. The same in our Linux operating system, we can have hidden files and directories. I know you all love security and cryptography and learning about security. Hidden files are not a security mechanism. They're hidden from a presentation perspective. It's easy to see them. To see them, use LS minus A to see all files. This shows you the hidden files and directories. If you look closely, you'll note that the hidden ones start with a dot. To create a hidden file or directory, just create one that starts with a dot. Dot profile is a hidden file. Dot bash alias is another hidden file. Dot cache is a hidden directory in my home directory. Minus A shows us all files. Minus L gives the output in long format. We can combine options. Some people didn't see it. LS minus A minus L. You can do both. Or as a shortcut, just LS minus AL. In any order. Minus AL, LA. Show me the long format output for all files. You can change into those hidden directories just the same as a normal directory. I'm going to keep going with a demo, but make sure you ask the TAs, get their attention and ask some questions as we go. We'll get some time to have a break a little bit later. Let's create some things. We're in my home directory. Let's make a directory, mkdir. And then supply the name of this directory I want to make. And let's change into that new directory, maybe make some others. So mkdir makes a directory. We'll make some files shortly. We can change into directories. Doing things on the command line, of course, you realize we need to type a lot. Sometimes we'd like to speed things up. So there are often keyboard shortcuts that we can take advantage of to speed things up. One of them is the auto complete feature. So in my example, I've got three subdirectories, security, Steve, and test. I know I've got them there. I want to change into the test directory. So cd, and I type test, but what I can do is I can type t instead of typing e, I hit the tab key. So the tab key, hit that, see what happens. The auto completes for me. So if you start to use this auto complete, you can save on your typing and speed things up. If I type cd, I want to go into the security directory. I know it starts with an s, cd, s, press tab, nothing happens. Press it again. Because there are two possible directories that start with s, it doesn't auto complete one of them. If I press tab twice, it shows me those two options. Security or Steve, which one do you want? I type e, press tab again, and there's only one unique directory that starts with s, e. Security. It works on files and directories, many things. So the tab key on your keyboard is used for auto complete. We can remove directories, R-M-D-I-R, R-M for remove directory. Another keyboard shortcut, if you want to run a command that you've previously run, you can scroll through the previous commands using the arrow keys on your keyboard. On your keyboard, try the up and down arrow. If I press up, it scrolls through the previous commands. Down takes me back. I want to make the directory Steve again. Done. The up and down keys, the arrow keys. Back in my home directory, let's remove this directory, its352. What happened? It gave me an error message. Often when a command runs, if it's successful, it doesn't print anything on the screen unless there's some output like LS, but CD, R-M-D-I-R and so on, here it's printed something. Right. I've tried to remove its352, but it says that directory is not empty, there's something in it. R-M-D-I-R by default will not let you remove a directory if that directory has something in it. So that's just a precaution there. If I want to do it, there are different ways, but I could remove the subdirectories first. Now so I could remove, I will not do it, I could remove the directory its352 slash security, then remove the test directory. What's in there? Let me check to make the example a bit of a little bit more fun. I'll make Steve again. You can name yours different, but in my case I have security, Steve and test. I want to remove all of them. Then I can use R-M-D-I-R now, or I can to capture multiple values. I can use some expression, regular expression and the simple way is to use star. Star means all values that match, anything, they're all gone. I'll make mine again just to illustrate that. I've got three directories, security, Steve and test. Maybe I just want to remove the S directory, security and Steve, R-M-D-I-R, S-star. Remove everything that starts with an S, we're left just with the test directory. So the star, this wildcard value can be used in many places where we use files and directories. When we list LS, when we make things, edit files, copy files, we can use star when necessary. Before we move on to files, one last special directory, the current directory. If I do LS minus AL, LS minus AL, there's a sub directory called test. It shows me that there's a directory up, it's a bit strange, but it keeps track that there's a directory above my directory, dot, dot, we know, and it shows me dot means this directory. Dot is a special character that we use to refer to the current directory. CD dot just takes you to the same directory that you're currently in. It's not useful there, but we'll see in later uses. The dot refers to the current directory. These commands are on the printed reference card in front of you. The middle sheet printed on your desk is the commands I'm going through. Let me see if I've got it. Available on the course website, the reference sheet, you have in front of you printed and you have it in every quiz, so you can use that in the quiz. You've gone through directory operations, special directories, some of the LS options, we'll now go through some file operations.