 We're going to issue commands to do things on our computer and the first basic thing that we're going to do is explore the file system So the file system is in a simple terms is made up of a set of directories and files Okay, so let's Do something with directories and files to get started First command will try is PWD and you type the command and press enter and it shows some output PWD tells me about my present working directory PWD my present working directory when I execute commands I am in Some directory when I execute them which directory well PWD tells me I am in the directory called slash home slash student That's typical for a username student to be initially in the directory called slash home and Followed by the username student to view contents of directories To list the files inside a current directory. We can use the program LS LS lists the contents of a directory and In this case shows an output showing Five different five different entries On your terminal it may be different than mine Should be very similar, but it may be slightly different. We our computers Some things have changed on some of them, but you should see something like that You need to ask questions as we go. Otherwise, I'll keep going put your hand up or just yell out if there's a problem I cannot see everyone at the back, but I'll stay seated so I can Type better LS shows us the list of files and directories in our current directory We'll look at that in detail at a moment Hint in this case the blue ones are directories the other ones are files So there are three directories or sub directories in windows. You call them folders, maybe but here we call them directories So there are three sub directories. Let's change into one the one called ITS 3 3 2 So change directory we use CD Followed by the directory name CD into ITS 3 3 2 change into that directory presenter PWD Now you'll see I'm in slash home slash student slash ITS 3 3 2 so this represents your current directory and it's What we call a full path or an absolute path It's saying relative to the the base of the file system or the root of the file system We're inside the ITS 3 3 2 directory Which is inside the student directory, which is inside the home directory and The home directory is inside the root of the file system the root directory We'll see some more about the exact structure later, but let's just maneuver about the the file system How do you go back I? Was in home slash student now. I'm in home student ITS 3 3 2. How do I go back to home slash student? CD We can give this the full sorry the full path to change to CD into slash home slash student Note the difference of our two CD examples the first one we CD into ITS 3 3 2. There is no slash at the front This is a relative path Change into the directory ITS 3 3 2 relative to where we are. There's no slash here Whereas the second case was change into the absolute directory slash home slash student Which is relative to the root So here we gave the full path We can use either a Relative or an absolute path. There's other ways To maneuver about let's go back into ITS 3 3 2 So to get back to student we can think we have a hierarchy of directories and a shortcut to go up in the hierarchy is CD dot dot Try it Try it and see where you will end up So we have Directories and you think of it as a tree. There's a root and then there's sub directories and sub directories and so on So we think that we can move down in the tree and move back up in the tree to move up We use the special Directory dot-dot means go up a directory You don't need to but just to so that it stays At the top of the screen. I'm going to use the Command clear you don't need to do that clear will just bring me to the top of the screen It will clear what we currently have and I'll do some things again Currently so very simple concepts. We start in slash home slash student We change into ITS 3 3 2 using a relative directory We're in home student ITS 3 3 2 Then we go back We CD up in the hierarchy, which takes us back to slash home slash student Let's explore a bit more of the directories. What about? Let's go to the root of the file system, which is just slash In windows if you're a windows user the root you often recognize as C drive like C colon slash or what? That's the top most Directory in our file system Have a look LS So in the root of our file system. We have a number of subdirectories and a few files even The blue ones are subdirectories in boot home Media var and others These are storing some of our user files and we'll note that inside the home directory the user files are stored Where most of the others are storing parts of the operating system and Applications You don't need to know what all of these subdirectories do I'll show you a slide lately later with an explanation But these are just subdirectories storing things like the operating system files applications user files Go back to your original directory home slash student Which we call our home directory if I'm the student user my home directory is where I start in the terminal Which is typically slash home slash the username Go back there So if I'm in the root To go home different ways CD home slash student because I know that's this the relative directory. I want to go to and I'm back in home slash student or Slightly different I'm currently in route CD slash home slash student and again gets me back to home What's the difference here between CD home slash student CD slash home slash student in this case? It has the same effect This one is a relative relative to where we start from where we're starting in the root directory So relative to that go to home and student where is this an app is an absolute path It ignores where we start from in this case. It gives us the same result. Let's go to the root directory There are a few shortcuts we can use instead of typing slash home slash student. I'll clear I'm in the root directory a Shortcut for your home directory is this tilde character The squiggly line Tilda I call it that is used to replace your home directory Try it. Okay, so there's a shortcut if you ever want to refer to your home directory You can use the tilde character For example, we go back to the root CD tilde slash ITS 3 3 2 means change into the directory Which is my home and the sub directory ITS 3 3 2 So tilde really is replaced with home slash student so that use it as a shortcut to go home and The faster way to go home It's just type CD CD with no parameters will take you home So just an alternative No matter where you are on the file system No matter which directory you're in if you want to get to your home directory Just type CD and enter and you'll get there any questions so far Most of the commands will go through we'll just use a few examples of them There are many more features that most commands have that we will not cover We'll show you how to read about the features later We can move around Maybe What does the file system look like? We said in the root directory There are some sub directories I've got a slide that tries to capture those sub directories Or some of them. It's usually common across different Unix and Linux based operating systems These slides are on your on the website and on actually the ITS 3 3 2 directory But I'll go direct to one of them the file system hierarchy Usually has these common sub directories of bin home lib and so on Bin is short for binary Usually stores applications binary applications. So if you look in the bin directory, you'll find many applications Home is where your home is Your home directory So there can be many users on a single computer The typical place for their home directories will be home slash username In Windows, what's the home directory? I don't have windows. Can anyone tell me? Where do you find your home directory in Windows? Or in OS X In in Mac it's slash users slash the username. I think You think I think if you look in a Mac, you'll actually see there is a home directory But it doesn't use that it uses slash users in Windows. I can't remember is it slash slash users or some user files or something Document yeah, so I think those who use windows can find their home directory. I cannot Live is short for libraries Libraries are files which usually applications share in Windows. You will know them usually is DLL DLLs Okay, you'll have an application in exe and it may use a library of executable code in a DLL file Okay, in Unix systems. We also have libraries with different applications share Usually in the basics we don't deal with the bin and the lib directory the slash root directory Don't confuse that with the slash directory slash root is the home of the root user So there is a root user that is an administrator that called root in Windows usually it's called administrator Okay, so they have a special home directory called slash root We've skipped over some ETC usually can contains configuration files if you want to change something in the operating system In Windows you use something like the registry There are registry settings and you can edit those registry registry settings in most unique systems The configuration of the operating system is done via text files and most of them are in the ETC directory Slash user is really repeats what we see here, but a different level So we see binaries or applications libraries and some source and other files Which again? applications and application information Var is variable things usually websites if your computer is a web server If your computer is an email server your emails will be stored here There's usually a temp directory and there are others You don't need to know them And it may be different on different systems, but often we'll see some of these common directories Some of them are explained there or very brief explanation Let's go back into our file system. Let's go home. Let's make a directory We make a directory using MK DIR Make MK for make DIR directory and then the directory name Whatever you like. You don't have to copy me Make a directory make sure you do it in your home directory Okay For those that come in make sure they have T-Mux set up T-Mux you'll help him with T-Mux and You'll help him with T-Mux Okay Karin Make a directory it doesn't matter what you call it but The output Should be nothing see when I ran make directory it just returns to what we call the prompt There's no warning message or error message if you see something different from this Something went wrong probably if you are in the wrong directory for example I was in the root directory and I tried make directory ABC I get an error message you cannot create that directory Pimmy permission denied it means You as this as the logged in user do not have the permissions to create a directory called ABC in this location We're not going to talk about permissions, but I think you can Guess that some users can I Restricted in what they can do on the file system You as the normal user the student user cannot delete all files from the file system You cannot make directories wherever you like you have limitations usually you do it in your home directory So make sure you're in your home directory LS and you should see ABC you shouldn't see high Someone's logged into my computer and and made a directory okay fine won't hurt me Okay Make a directory. Let's move on Delete a directory RM RM for remove MK for make RM for remove so delete and It's gone Let's move on so make directory and Delete a directory There are the main things with directories we can change we can view our current directory we can Make directories remove directories. Let's move on to files Let's create a file All right, let's start by creating a text file We'll use a text editor. There are many text editors on your computer the one we will use is called nano. Well, I will use Nano is a text editor and you can pass in a file name Whatever you like you don't have to use the same file name as mine and Presenter and it will open up a text editor type some message in your text file and then we'll see you how to save it Find him a seat and get him on T marks Type in your text editor type whatever you like in your text file So the basic text editor on Windows is notepad But there are other text editors you can install your own same on on our Ubuntu Linux We have nano as a simple text editor, but there are many others It gives us some screen where we can type some text now We're not going to teach you how to use nano except how to save files and exit and note down the bottom of the screen It gives you some menu The carrot that hat character means control So control G is get help Control X is exit Control O is save Now the main ones you need for today Control O right right the file means save the file if you want to save the file control O It says do you which file name? Do you want to save it as well the same one that I gave before just press enter and It's saved If you want to exit Control X if you try to exit before you save it will give you some prompt. Do you want to save? so create a text file again You can put whatever you like into it. You don't have to name it the same as mine Let's do something with that text file. Yep How can I change the directory of the save file you mean put it somewhere else? We'll move it. Okay. The question is how do I change the directory? Let's see where mine is or where yours is Let's do LS Your file should be there Okay Again, you'll see a different set of directories or files than me, but you should see the one you just created Let's Put it somewhere else So the question was how do I change directories? Well, we move it to a different directory MV My new file Move you move something from a source to a destination Move MV your file name Where do you want to put it? Well, if you want to put it in another directory type the name of the directory you want to put it in move My new file dot txt into it s 3 3 2 directory That shifts it into a different directory LS It's gone from here But if I change into it s 3 3 2 and LS It's one of those files amongst that list of files my new file dot txt So MV move Move a file from one location to another All of the commands we're going through are on the reference card So in a slightly different order, but we'll we'll get through some of them While we're on MV move We can use it to rename files move my new file Before I go Who can type as fast as me? okay typing on the command line is very Time-consuming sometimes there are many shortcuts we can use let's try and introduce a few as we go the first shortcut Which I find very useful All right. There's a set of files in my directory. I Want to move my new file somewhere else So I type MV for move and then I start to type the file name M for my new file and The command line has a autocomplete feature You know when you're searching Google you start typing in the keyword It presents options to autocomplete Well to get autocomplete in the command line press tab The tab character on your keyboard If it does nothing I Just press tab you didn't see it, but nothing changed. It means I cannot autocomplete that It means there's no unique file that starts with M. I type The next letter in the file name my new file and why I pressed tab It autocompletes Why because in this directory There were two files that starts with M When I press tab after typing M It couldn't determine which one I wanted but after I typed in Y My and press tab it autocompletes to the one that matches There's only one file that starts with my so that must be the one I want so use tab Start to use it all the time because it saves typing makes your life easier if you Try again If you press tab nothing happens if you press tab twice it will list the options Okay, I've got MVM. I press tab two times and The command line shows me the two files that start with M Just to remind me that in this directory there are two files that start with M. Ah, I now type Y Press tab and autocompletes so if Autocomplete doesn't work press tab again, and it will give you options of what starts with those particular letters Now what are we doing renaming a file? Renaming a file is the same as moving a file from one name to another name MV my file name to a new name Whatever you want to call it which is renamed and now My new file has disappeared. I now have a file called new name dot txt So MV is used for moving a file between directories as well as renaming files while we're there Let's copy the file CP CP for copy So CP the file named the source file the one you want to copy and the Destination the new one you want to create which is going to be identical to the source And If I do LS, I'll see hopefully that this new one exists now come back to LS We're going all over the place, but LS we can pass parameters If I do LS it shows me all the files and subdirectories What if I just want to see the text files? We can use a wild card like this list all files Which match any character star means any character? It's a wild card But finish with finishes with dot txt Someone deleted my copy I'm going to find out soon right. We'll try again You can do it better than me. I've got a file and I can copy it. Please don't delete it okay LS as with many many programs will take a parameter To filter out which one's the list and star is What we call wild card meaning match any value? So star dot txt means any value that ends with dot txt You can use star in different ways and there are in fact other patterns that we can match LSC star every file that starts with a C and You can have more complex patterns So what have we got we can copy we can move or rename we can Delete did we delete? RM remove delete a file is To remove a file from the file system. So RM is the Command to delete a file and it should be gone Okay, RM removes a file. There's no trash There's no recycle bin If you remove it's gone okay gone in that You need Special techniques if you want to recover it so it doesn't move into a trash or recycle bin it's deleted So be careful. Don't try and delete important files. Don't try and delete the operating system. Okay We can copy we can move we can remove we can edit with nano Let's go back to some of the commands. We know and Do a few different things with them? What let's come back to LS? LS lists the files It has many options and on the command line options are usually given as a character following a dash and We'll see how to find the options. Sorry. I'll just clear and go to the top of the screen Again, you can do this on your computer. It may be different output, but just try the different commands LS shows the files LS minus L shows the files in long format and to make it Sorry It doesn't look very good on my screen because my terminal is not big enough the files wrap around You can make your terminal bigger to make it look nicer on your screen. Okay, but Let's try again LS minus L show the output in long format give a lot of details Star dot txt of the text files Just move it up rather than clearing Look at this line here. What do you see? It gives them some details about that file So the file name going back from the right back the file name The something about the date and time of the file. Sorry July 25 1054 Now with files, there are different dates and times associated. There's usually creation time Modification time when it was at last modified and access time. When was it last accessed? This is the modification time from memory when it was the last modified 26 is the size of the file in bytes This file is 26 bytes Student and student is something about who owns a file whose file is it? The first student on the left means who's the user that owns it and the second one means who's the group? But today we're not going to cover permissions. So we're not going to explain That in any more detail But the owner of the file when our computer system may have many users We need to indicate whose file it is One I always forget. I'm not going to try and remember The first set of characters about permissions Something telling us about who can read the file Read means open who can write the file means edit delete change Dash means usually it's the third characters execute. So the permissions in Unix are read write and execute Read is opening writing is modifying executing is executing running it these 10 characters no of The 10 characters this the last nine tell us about permissions on this file And again, I don't want to spend time on explaining it three characters Say what the user can do The next three characters say what the group can do and the last three characters say what everyone else can do with this file I'm the user student. I can read and write this file. I cannot execute Anyone in the group student can read and write this file. They cannot execute any user who's not student and Not in the student group can only read the file. That's the way we interpret that You need to go study a little bit more about permissions to to go into more detail there. That's not for today The first character Indicates the type of file the main types of files. We have our files and directories I'll go back a directory Again very hard to see on my screen, but you will see the blue ones the first character is a D meaning this is a directory and The ones which are not blue the first character is a dash Meaning this is not a directory. It's a file So that's how you really know if it's a file or directory not by the color But by this first character in the output here directory or file so we can view the long format What else what about hidden files I Think you know on say on windows you can have hidden files ones which are not normally shown But they're actually there with a similar concept we have What have we got copy What did I have Do I have a file copy my abc file from my it's 3 3 2 directory, so this is the source I Want to copy abc dot txt from it's 3 3 2 directory into another file and I could type So create a file called another dot txt to make it hidden Put a dot in front of it do an LS and You won't see Dot another dot txt Okay, so the concept of a hidden file in Unix is a file that's name starts with a dot Dot files They're not hidden in terms of security usually you can find them quite easily But they just hidden in terms of convenience They're not listed when we do LS In a normal operation To list it you need to do LS minus a minus a for all files normal files plus hidden files and You see a bunch of hidden files and directories and one of them should be the one that you just created LS minus a List all files questions Too fast too slow everything. Okay? easy All right, okay We'll move on You can combine options try LS minus a minus L That is these dash minus a minus L are just options You can usually combine them in any order not always but in most cases list all files Minus a in long format Right doesn't look so nice there looks better on your screen and there are many other options. Where do you find the options to LS? So now how do we find help? Well, there are things called manuals or man pages manual pages if you know the command I Know the command to list files is LS to read about all the details. I do man LS man is the program that will show you the the help the manual for this program and You can scroll up and down with your keyboard up and down arrows Read through this name of this program or command is LS. It lists the directory contents The syntax is here and then you go through and it lists all the options scroll up and down minus a Do not ignore the entries that start with a dot Usually there are different formats for specifying options. Just a single dash and a or two dashes and a word They had the more verbose description many different options there So if you can remember the command but not all the options you use the man page to find those options Scroll down read them all To exit This man page press Q Q to quit Almost all commands that we will use have a man page man What have we used RM? Explains the RM command and the many options that you have Page up and page down will scroll through So really you just need to remember the commands and Then if you want to find the options use the man page What if you can't remember the command name? What if you don't know CP is for copying or RM is for deleting? There's a very basic search feature man minus K and Then some keyword show me all the man pages which contain in the description delete There's a lot You need to scroll up and down to find it gives you the name of the command and the and the description It's not not the best of search features Okay, but sometimes it will get you what you're looking for so there are many commands that refer to delete So it's a very primitive search for Command Really if you want to know what command to do something probably your best bet is to search on the internet How to delete a file in Linux and it will give you the command But over time you'll learn those commands and you'll remember Okay, we can move about directories. We can create files Let's create a few for a few more files Actually, I've got my file. What did I call it dot? File extensions don't matter in Linux or Unix Up to up until now my examples. I called files dot txt. It means nothing dot txt With respect to the operating system the extensions do not Indicate what the file type is Who did that? Someone's messing with my terminal. That's all right What was I saying file extensions don't matter the file ABC is a text file Just because it's not ABC dot txt doesn't change the the contents or the format of the file All right, some other ways to view a file cat Cat displays the contents of a file Okay, very quick way to display all the file When you have a very long file that just lists all those lines What's a very long file? I can remember a file called services There's a file in the ETC directory called services. Have a look at it. It's just a text file. It doesn't matter about the contents But when you type and I'll do it again cat and that long file cat displays everything on the screen It doesn't stop. So just Scrolls through Not very convenient in some cases So there's another command called less similar to cat Displays the contents of the file, but it scrolls one page at a time and You can use your arrow keys to go up and down and Page up page down So that's a nicer way to view the contents of a text file. I'll do it again less displays a long file page by page Allows you to scroll to exit press Q like a man page cat displays the contents of a file as is Just displays all of it at once So we can view files what else You want to see the first line of a file We can use head or the first few lines The head of a file Head shows by default. I think the first ten lines of a file You can specify how many you want to see head minus one Show me the first one line of a file head shows the head of a file Cat shows the contents less shows the contents page by page head shows this the top of the file Using the minus operator. You can specify how many Lines at the top you want to see and to see the bottom of a file. What do we use? The tail Tail shows the end of the file for example by default the last ten lines, but we can specify how many lines we want to see Many things in Linux we use text files the configuration of the operating system and There are many programs to support the processing of text files Because it can help when we want to automate things What let's find a file this command called find allows you to search through the file system looking for particular files The syntax is quite complex, but we'll just give some a simple example is find search in Slash home slash student files with name The end with txt Here's an example Find the first parameter is where you want to search. Where do you want to start your search? Which directory normally I want to search in this directory Then the next parameters this dash name says search for files which have the name and I put it in double quotes to to make sure this stays together that is anything dot txt Any file that ends with dot txt? Do you find any and? It searches through the home slash student directory all the sub directories that goes through Even the hidden ones and prints out the list of files at end with txt So finding can be very powerful to find files on your operating on your file system We could do a shortcut Find in our home directory instead of having to type slash home slash student and we get the same result So this is the shortcut for slash home slash student if you want to search in your current directory you're in I'll go into its 3 3 2 Find if on a search in the current directory the shortcut for your current directory is dot this directory find Looking in this directory The current one and all its sub directories all the files with name ending with dot pdf And it looks in this directory So dot is a shortcut for this directory two dots is a shortcut for the directory up Tilda is a shortcut for your home directory the squiggly line Find has many other options. You don't have to search by name. You can search by size by date And when you search you can do things like delete the files that it finds Let's say you want to delete all the files which were created after some date on your in your directory You can use find or not do it There's an option to find based upon date or time and there's an option to once you find them to delete them So it can be very powerful to to manipulate Your file system fine looks for any file of any type, but our programs that we run LS is an application Okay, LS there's an executable file which implements LS It's I sometimes we call it a command or an application or a program Where is LS? Where is the file the binary file for LS different ways to find an application which? Which LS which tells you Which binary file implements this command slash bin slash LS So the LS program is in the slash bin directory. There are others. I think where is LS It's a little bit more complicated that where is it's searched for not just the program, but also the manual page LS The program is in bin The man page the help is this file You don't need to know about that, but where is will give you more information about a program There are other ways to search, but that's enough for now. What have we missed? Okay, a couple more on text files when we did our cat on slash I'm using slash ETC services as just an example of a text file We don't care about the content why it's called this, but I just know it's a long text file How long is it? How long is ETC services? Tell me first. How many bytes is that file? Find the number of bytes in this file called services in the ETC directory. How big is this services file? Anyone have an answer? Well a quick way to find LS minus L Remember LS lists files minus L gives us the long format output And it takes as a parameter. We can list all files or list a particular file And again it won't display very nicely, but The output This file is 19,281 bytes in length How many lines? Well, there's a program called WC word count This services file contains 605 lines of text 2,627 words Words are separated by spaces And 19,281 characters Okay, if you look in that text file you'll see 600 lines 2,600 words and 19,000 characters And of course one character is one byte when you store that text file So the size is 19,281 bytes WC word count It's useful to get information about a text file Let's look at some of this text file. Just look at the first 15 lines of this services file Just see what's in it. It contains a lot of different words. We don't care about it Um Sometimes we want to search through a file Find all the lines in a text file which match some particular string GREP is one way to do that GREP Look for the word echo in the file ETC services It uses regular expressions to search through a particular text file In this case any line that contains the word echo should be displayed Of course if you want to you can try other words echo I only did echo because I knew there was some lines in there that contained echo What's missing? We've done directories Files Help file searching Almost there Any questions? Search for all all right. There's your tasks find all PDF files on your computer Hint use find Okay Find all the PDF files everything that ends with dot PDF on your computer See if you can find them What program do you use to find all your PDFs? Okay find and slash you need to say where to look for where to look remember the second parameter or the Our programs take parameters So find is a program the next things we type in are the parameters So the first parameter is where to start the search from If I want to look in my current directory I use dot But if I want to look in the entire file system Use slash because slash is indicates the root directory And the name ends with PDF Okay So find looking in the root directory and any of its subdirectories Because it also goes through subdirectories, which will be everything Any file that ends with dot PDF in the name Some you may see errors like permission denied meaning you as the student user are not not allowed to look in a particular directory Some directories are restricted It'll go for a long time. Maybe you'll find them if you want to stop a program. What do you do? control c control c kills a running program control c For lunch today, so we'll go for another 30 or 40 minutes and for lunch We're just eating in the canteen, but sit will pay. It's a little bit easier We're just going to write down what you want And then we'll order it so it's there on time A few more shortcuts in the terminal How do you run a command that you've recently executed? I just did a find Use your up and down arrows on your keyboard if I press the up arrow It goes to the previous command the history of commands Keep pressing up and you scroll through the commands Up and down will scroll through the history of commands What else If you want to list all the commands type history So the the terminal keeps track of the commands that you've been using And it shows your history all the commands you've executed And it gives a number from from the start You want to execute one or maybe you typed a real long command. You don't want to type it again You want to execute A number a command of a particular Number for example, I want to execute command number 104 Exclamation mark 104 Executes that command Now you need to be careful. You need to know that 104 is the command you want and you get that from the history Exclamation mark. What's the name? It's called bang When there's a bang There's an exclamation So it's often called the bang character Bang 104 There are many extensions to that to speed things up, which we will not cover Uh Okay, what else Questions on the commands we've done any Problems everything okay You don't you may not remember every command use the reference card. Uh, you need to practice to to learn some of them Let's try some different things