 Hello everyone, this is lecture 2 before I start the lecture I want to recap give you a little bit of recap as what we have done in the past lecture so we covered the history of Linux and Unix mainly it has about 50 years of history at this point started somewhere in 1960s Unix people started working on Unix with mini computers then around 1991 the Linux came into being the main person who invented Linux is line of course we also looked at why Unix is the popular operating system and then why Linux popular operating system the main reason why Unix is popular because Unix provides excellent security features and it also allows multi-use or multitasking and multi CPU or multi processor capabilities we actually saw and we define all those terms what it means and then Linux actually provides more features on top of that first of all Linux is an open system so you get the source code along with the Linux operating system and then we also saw how it also has very solid verification features it's globally verified so to speak because there are so many users using Linux and going through all the programs all the features of Linux verifying them every day more than 30 years of verification experience in Linux and then it's an open platform and the companies also use some of the commercial aspects of it and then we also saw the main parts of Linux operating system the kernel the shell and the file system we defined each one of them as to how they interact with the user as we saw the kernel is the lowest level which mainly like it provides the interface to the hardware systems so it manages the resources for the resources various units and then also the memory and IO all those different parts are managed the shell actually sits on top of the kernel and then that provides the interface power from the user to the hardware so in between all these things is the file system which is essentially you also define what a file system is how the files are structured inside the Linux operating system and one key thing that we noticed was all the devices are represented as files so if you want to actually put something in the at the terminal we simply write to a file and if you want to read from a keyboard we simply read a file so that facilitates all kinds of interaction much more easily compared to say even Windows operating system where you have to actually start a process and then basically use the process to communicate to your IO devices we also saw how to use the shell the what exactly a shell is form it is essentially a command interpreter so basically it when you invoke a shell it comes up with a prompt the prompt could be shaped like a dollar percentage a greater than sign things like that and each one represents various shell and these are couple of shells like the Berkeley C shell the bond shell or the BSH and then the bond again shall be a SH or bash the Berkeley C shell is also notice it is called the TC shell which provides additional capability from top of the original Berkeley shell then we start some basic introduction into the commands the commands like LS LS is the list command we also saw the command structure inside the Linux operating system which is command followed by options followed by arguments and then we saw like a couple of commands LS on CD LS is the list command which lists all the files in a given directory and then we saw like various options LS-X LS-L LS-A LS-T LS-R various options that we saw and then also like on CD CD is the change directory which allows us to go from one directory to another and this is essentially by again it has the minimum options and also like arguments it needs one argument minimum which is I wouldn't say like it needs one argument you can also like give it no arguments and you see like I mean I want you to see what happens when you do just a CD with no arguments where does it go where where does it take you try that experiment it is very it is a fun experiment otherwise you need one argument with the destination the lecture if you don't specify any destination what happens so that is something that you can do when you get to play with on the Linux platform. So I also have a couple of activities for you based on the lecture one this is something that you can try it out when you get a chance to play on the Linux platform number one is you can type man we also saw this man command which is a manual to get details about any commands so man bash bash is we know with the shell see what happens whether it is man bash and both man PCSH these are two shells so you can get more information about the shell how to move the shell what are the options again the shell also follows the very similar command rules that we talk we know about already which is followed by the options and then the arguments so try it out see what happens I also ask you to do this other activity which is you have a file structure which is you know the flash represents the root and then there is a B there is a directory A and then under the directory A you have B and C and then under root you have also under the directory B under that you have directory E so I want you to write two CD commands to go from B to E basically one will be an absolute command the other one is a relative command relative command means using there you are and then there you want to go that is a relative command and then the absolute command is just follow from the root whatever the absolute path so try it out I think it is a it is a fun exercise this gives you some more understanding of how the silicon works so with that we will start today's lecture today I am going to cover more of the commands themselves we will look at various commands and see how we can make use of them I am going to start from there we left off this is the the last I just wanted to again reinforce on the CD command a couple of things we did not talk about some of the stuff we talked about the tilde tilde to represent the home directory you can also type CD slash home slash which takes us to the slash home it may not be your home directory your home may be like slash home slash your username in this case let us say like the AACPR is the username so it goes there now you can also type in like from home CD KACPR and that takes you to the next level and then from there like I mean we know that the dot dot actually moves back one level up so if you do a CD dot dot it takes us back to the slash home and then if you do like CD dot dot slash dot dot from the home from your ACPR then it takes you to the root directory so you can see like I mean how to navigate and now go from one directly another and as I said like the if you just do the previous exercise that will give you like a good grounding as to how to navigate using the CD command let us move on the next command that we are going to talk about is the MK DIR or in short we just say make the so make the command allows us to create new directories and the new directories can be created under the current directory or if you give like an absolute part it will also create wherever you you want it to be created so here essentially the syntaxes make do followed by the directory name so again here make there is a command and the directory name is the argument you can also use certain option for example the dash P this will create the directory tree directory the three essentially like I mean it it creates this whole tree which is there one followed by the two followed by that thing meaning the there one is the top level under that you have the two and then under that you have the two and then you can also do make there the five which is this creating a new directory called the five and then we say CD pound dollar so the pound dollar has a meaning here the pound dollar means the argument the last argument of the previous command so anytime you start with a bang it has basically like the bang denotes the command so we will see some of the shortcuts actually like I will tell some of the shortcuts as we go along but this bang followed by the dollar the dollar denotes the last argument from the previous command so when we say like CD bang dollar that bang dollar is a shortcut for verify so when you say like CD bang dollar basically it moves from the moves the cursor from the current directory to the file because we already created the file which is a very very useful socket I think like I mean many of us for use this pretty often the other shortcut is also like bang bang if you do the bang bang that that's shortcuts for the previous command and then you can also say like bang however like I mean put in negative integer and that takes you back so many levels of for example bang minus 2 is the command that not executed prior to the previous command so so bang minus 1 is the same as bang and then similarly like you can go progressively behind how many ever commands that are there and we will see some more commands which allows you to get these kind of shortcuts and then we can do the kind of navigation so the next one that we will talk about is the use of semicolon semicolon is the usually a command separator so this allows us to actually concatenate multiple commands so in this one for example you can say make their their five semicolon then CD to their five there is no period actually so once you do that for example is shown here it creates the directory and then moves the percept to that so now you can see the prompt actually here it is actually greater than time that is actually now in this root slash the two and then here also like I mean we already learned about this the CD minus which is essentially going back to the previous command or previous directory where it came from this is not that it is going up one level but whichever directly that was there previously for example I can say like I mean the I can be in like the root slash say like the one then already if I created a under under the root there is a root dot the root slash the two and then if I say like for example CD to slash root slash the two under one and then if I say CD minus it actually takes me back to DER 1 not to slash root so this is the important distinction that I want to keep in mind something that you know notice in this particular even window is the shelves on these in this particular window with various tabs so you can actually click and go to those things again this is all like the features of that we already know about when we learned the beginning of nature so now the next command that we will learn is cat cat is the short form for cat init or attenuation essentially like I mean when you say cat and the argument is a filename once you give the filename the command interpreter just opens that file and displays each line and until the end of the line then it then puts it back puts the prompt back so this is like I mean you cannot do any edits or anything but it is only like displays the content of the file so for example like I mean there is this text file a CPR dot text that we have and when you say like cat a CPR it just rolls through that all the lines and it displays line the line so it is well as it is an verification for very long just a very long all these VMM OVM and another OVM or UEM actually so all these are displayed and then and then even there is an empty line in this file if you notice the end and then it brings back to the prompt so this is again another useful command to see what is inside particular file so now the question is how do we use it I mean just by displaying a file like I mean through all the lines doesn't seem that useful correct but there are many ways that we can use it for example you can copy a file into another file and that you can use a just a cat command to do it so how do we do it let us look at that so here there is a special character another character which is the greater than sign so when we say like cat to a file so in this one actually like I mean we can keep typing whatever we type in that goes into this file called fly 1 and then when we do the control D it comes back so this is one way to enter or edit a file not really like useful in the sense that we cannot go back and change things around or move things around this is like just line by line it is input so say like I mean if you want to type in like some some notes into just a file you can just do this cat and redirect to a file and then just start typing your notes and then it will just create that it is a useful in some sense basically I mean you can also say like I mean in fact cat file 1 and then redirect to file 2 that actually lets you copy that file so you will now have two files file 1 and file 2 both have the same information so this is the this is where I am actually you are using two things one is the cat command also the redirection operator which is the greater than so in this case some when you say like one greater than time it creates this new file and essentially like I mean write into that file and if the file 1 is our fly 1 is already there then it will not usually write into that it will say that hey this file is there I cannot overwrite it in some shells it also allows the writing of the content so here actually if the file 1 is already exists then it overrides the kind of file 1 it is true but sometimes some shells actually will not do that and then it comes back with an error so it depends on like the kind of shell that we are using but you can again this is one of the features of they have to be the customization that we already talked about so now let us let's see like I mean how we can use this one so the next slide it gives you an example of there it is getting overwritten here we displayed initially the cat cat forward of text that displays the content this we already saw but now when we do the cat greater than text and then we start typing the success is not a destination and then we do a control D and then now when we issue the same cat command the previous command we see actually that file has changed and we get this again try try this out try various combinations of this and I think we will understand it better that way now let us go to the next one which is a little bit more interesting which is double greater than so it is two arrows see here what does this do this actually is slightly different than a single arrow this the two greater than signs actually makes you to append to a file what that means is the fly one in the previous example saw that it contains all these things now if you take cat to greater than and then take that part of text and then when you type in the success is not a destination and control D it will contain all these things and the next line after this empty line will be this one so that is the big difference between the single greater than and the two very long so again why how can you use it so here there is one way to use it which is fly one cat fly one file two and then you are saying greater than what happens into this is actually on catnates both these files and write it into the file now the question is how do you append fly one into pile two the simple thing is like eliminate this file to you and then you can say cat fly one double arrow file two and then whatever the content in file two will be will have fly one appended to it at the end if you want the reverse one like the file two to go to go after the fire fly one then you need to reverse the auto say like cat by to happen to fly one and then that it's up and so again another one command to save it I encourage you to actually try this out and try it out multiple times and various combinations to just understand how this man works so here is an example again the first typed in whatever the text as such this is not a destination and then followed by control B to break this man now the next one is cat and two arrows and cat product text and then it's a progressive journey and then now we get those two lines that we enter so this is another way to enter the data into a file but you know is still we are we know like now how to create a file how to actually you know work with the file but it's still not very clear as to how we can write some programs and how to navigate through a file you will talk about some of the commands later on in this course but let's let's go go on with this knowledge now the next one is now we know that how to copy using the cat but Linux also supports a regular copy function which is the command is CP and CP also has again all number of options but it has two main arguments source file and the destination file so if we without any options we say if the file one file two it copies the content of file one into the content of file into into file two so this is another this is a very useful command we use this a lot of times actually in the real life and the Linux also allows you to actually copy many files to destination you can also specify a directory here instead of the file and then it will create the file one exact copy of a file one and call it also as file one under this particular direction so here we can say CP-PRF again all these things are having a meaning and then we will see what what they mean then it takes this the files and directories and sub directory from this pepper area from pepper into the HDD backup area and it creates exactly like all the files into that so here you see that actually it is not the arguments are not a file but in insert they are the directors so that is why like I mean it is left as as vaguely as it is the source and destination the source could be file name or a directory destination could be a file name or a direction and they are directories then you need some options to make sure that which files are getting copied and even like in source you can use wild cards which is something we will learn for example the star denotes star denotes all the possible files and then you can also like filter them by specific characters and names so now let us look at why we specify these options the PR and F what do they mean so here is a brief look into the options the dash I is an interactive and it prompts before overriding so if a file exists in the destination directory and you are trying to overwrite it will ask you hey do you want to overwrite you want to happen you want to cancel this or skip this file so then you can you can use that particular option to either copy it or to skip it or whichever one that you want to be dash F is the source option which is essentially it does not matter whether the file exists whether it is it's preserved whatever it is it basically forces it into it will just remove it and then it will try again dash P is the preserve mode where all the ownership the time stamps and all the things are preserved and we will see like what that means like this is a special section on what is file ownership what kind of thing that you can do and also like what are the modes that you can work on a file and then the dash R is a recursive mode it is a recursive copy which means that it goes and finds all the subdirectories and subdirectories of the directories and then it copies everything so a copy minus RF is a force and recursive which is used many many times and the dash U is the update copy only when the force file is newer than the file or if the destination file is missing so here essentially if you already have something new and if you are trying to overwrite the previous version it will prevent copy from the previous version so very useful feature so the CP-RF is as I said like I mean more than what you can imagine in day-to-day operations now if you want more details do you know how to get it or you get more details on CP so there are two ways we talked about this earlier one is the man CP try that out see what what you get and also like CP dash help which should give you all these options and what are the different arguments a short version of that the man will give you like more details so now let us move on to the next command this is MV MV or we just call it move the move command is different from CP come on because move command basically takes the file and then moves it over to the new destination so in the windows world analogous to cut and paste whereas the CP command is more like a copy and paste so again the arguments here are the source and the destination and you can also rename a file which means that the destination could be specified as a file name rather than the directory name if you specify the directory name the names are preserved and if this copy it moves over to the the new directory but at the same time if you specify a new file name as a destination then it moves it and also changes and rename the file to the name that you wanted that you selected again there are many options here there is one one of the options that I which is interactive which is if it is trying to overwrite a new file it basically ask you to conform whether you really want to do it or not again another nifty feature again for getting more help on this command I want you to type in the man move to get more help so let us go to the next one the next one is the RM command RM stands for remove so essentially like you use RM to remove any final again you have to use it with use it extremely carefully unless you want to do it don't do it because the deletions are permanent in Linux and so once you delete a file it goes to the the heap and essentially the contents are lost forever the government should use this you can't trace any of them anyway so RM filename that's the command again it has many options RM minus I basically it's an interactive where it prompts you before deleting a file it asks you if you really want to delete this file and that and then only RM minus RF is the recursive and force as you as we saw so it basically goes and recursively delete all the file from the directories directly from under any of the the source or the argument that you specify and RM minus RF also does not prompt when it tries to delete the file so it's it's really a dangerous command if you vote the root and then they say like RM on the product boom everything gone so don't try to do this and then here actually like an effect RM minus RF that's star the little star here this means all the files in fact you can also set the way star dot star it also means the same thing whether there is a character or not I mean there is a file it just really so this is the most powerful command I will say in any of the Linux platform so don't ever do this one RM minus RF star if you do it from your home directory the entire home directory is gone you do it the root directory the root is more so I mean there are several mishaps that happen because of RM minus RF star or RM and startup startup so now let's look at the next command this is RM DIR or Render again Render is used to remove any directories so as you know as we saw like RM just the simple remove command is typically used to remove a file even though like I mean if you use the RM on forward the associated directories can also remove but Render specifically removes a different so here in this example you do an LS of the home directory and see like all these files AXI RTL XRTL there copy copy the star all those things now there is a like a cat per and cat per one so see the color differences right so this OVM reference is green all this TC Raghu has 40 copy and all these things are blue and then you have red and then there are black ones so typically the black ones are the ASCII files the red ones here are the binary files and then you get the blue ones which are mainly directories and then the green one is some other type that it cannot detect so basically it's a PDF we move on actually so it is tagged as green so this is one of the things that some of the shells provide it kind of colorates the various files based on its symptoms so it is very easy to see that okay how many directories are there okay I have cat per as a directory cat per one as a directory AXI RTL as a directory OVM TC is a directory and then Raghu is put in the directories so now I can go and actually remove it they are under act for one which is this particular direction and then if you do an element that particular thing is missing and here you can also say like the OVM TC but then it comes back with the comma with the form saying that hey you are trying to remove a directory which has content in it which has some files in it so I cannot do this so that is that is this message that directly no mention of it so if you want to do it there are two ways of doing it one is you can say like RM OVM TC slash star and then first remove all the files and then you should are in the OVM TC that is one way to do it or the other way can anyone guess it is the RM minus RM so recursively you go and remove and that also removes this particular way so in Linux actually provides good features to actually work on this to for all the commands so that you don't have this one way multiple ways you can be very creative in your approach so now let us go to the next one the next command that we will learn is the PWD PWD stands for present working directory so what does that mean so this is there prompt is almost saying that this is today and what is today today is where you are right at this point of time then so essentially the PWD when you when you say it gives you which directory that you are currently working on or where your prompt is okay so again you are in now flash form we know that actually first one and then you have various files did it an LS command so one thing that you notice is also like I mean the 404 this could be a machine name currently like I mean that is what it looks like some shells also display the command number so if you are running the first command then it is a 1 2 3 4 in this case it looks like this is a machine cat per 404 so the cat per 404 you go into the home directory you have removed the cat per one did another LS and then the OBMTC that is this is all like the previous command basically there we try to remove that and then it said basically the director is not empty I cannot remove it now you issue the PWD command basically it comes up with what where it is today where it is currently this is the slash form that's why it's a flash form here and then then it continues on so this is again a very useful command because sometimes the directories can be like very long like you can be under a slash B slash C slash B slash E slash F it can go all the way up to like say V and then in the prompt it only displays probably like the V so now you want to understand what is my person working directly so the PWD will give you the exactly where you are okay so this is something like like a GTS so now PWD gives you where you are but still you have to know where you want to go and then based on that you can do like CD commands LS things like that so this again very useful command if you know so now the next command that will study is the less command so we saw already the command cat so less is very similar to the cat command in fact we should start with more and then we can say like less but more and less are pretty much more or less the same similar type of the maps the only difference between the cat and the less is in less actually this pays the file but it doesn't go back to the prompt so it stays within that file and then so it lets you go up and down the file and the interface is similar to an editor interface even though you cannot edit the file but you can navigate inside the form so if file is too big then it first displays only a portion of it it doesn't display the whole thing like how the cat does basically it just runs through the thing and then it comes back to prompt instead of that the less command actually displays the file one page at a time and then it lets you navigate usually it can go forward by just pressing the spacebar or you can go back by just typing be this pressing be and then each be will go back one page there are some other additional stuff one is the use of slash to search within the file so you can say slash and then followed by a particular string and then that's the command will search for that particular string inside the file to see whether it is present where it is present inside that and then for quitting the less you just simply type Q and then it will there are additional commands inside of less which is one is the percentage command percentage G which takes you to which displays where what is the current percentage or the current line how much percentage of the file is covered by the current line or where exactly the current line is in the file the lowercase G and uppercase G actually they take you to the first character of the file and then the last character on first line of the file and the last line so uppercase G takes you to the last line and lowcase G will take you to the first line so again this is the less command is mainly used for inspection and you can also specify like the additional options like dash C will clear the screen before displaying so if there is any residual stuff and it's all five you will still like see from the top of the terminal all the time and then plus n is where n denotes the number of line so say like plus 10 it starts printing only from the 10th line on it so this is again another thing to inspect files so you want to actually look at a file without actually editing it touching it then the less is your command to do that again touching is another another thing then when you open a file for reading alone you are not changing the timestamp you don't want to say that hey I edited the form it's only read reading if you want to edit the file then as soon as you edit the timestamp changes and then it is new timestamp will be put in based on when you write the file or when you started reading by the right option also so we will talk about some of those things in the last section where we will talk about the file system and how to interact with the file system now here is an example of less command so in this one it's a very short file so basically it displays this in the entire screen and then just in the end so now if you queue if you type in queue then this is this window input you can actually navigate using the g and minus g and up to the g that I mentioned and in this file is too small so much but if the file goes into multiple pages then it takes you to the first character and the last character perspective here actually even the prompt is missing because I think I did this to the whole page and then basically once you do the queue then it will display go back to the prompt here it doesn't look that interesting but in reality if you have a netlist for example you can search through the netlist to find a particular component you can also search through timing reports to understand where the maximum delay is in fact that so so again the less command has a lot in today's program in terms of inspection mostly okay so let's go to the the next one next command which is the head the head displays top part of the file which is the starting point and then you can also make it display more lines but the default is 10 lines so if you just say like head and then the filing it displays the first 10 lines in that file and then the dash n essentially allows you to change the number of lines to be shown so you can say like dash and 4 then it will display the first four lines if you can if you so the various options are there like so here the example is head dash n 50 file of text displays the first 50 lines of the file of text head dash 18 filename without the n also it also works display the first 18 lines of the file so why is this again important the reason is the head command is used in many places where you want to make sure that the file created and the file has all the proper input recognized another one is if you know that there is a splash bar to denote a particular program and you want to know like version from the program itself then you can do a head of that program or the log file and then you know that okay which word is using yeah other ways are basically if you display the first 50 probably that's where all the I use are all covered so you know exactly like how the what are the I use that I needed to run the program okay so we will see an example of head here the Linux text essentially displays the first 10 lines of that so so you can do this many many many different ways so now the complementary to head is the tail command we will also see this one a tail command actually displays 10 lines of a file but it doesn't display the first line but the last so the same as head command but only thing is this displays the last 10 lines of a file second why is this important okay we will see in a bit and so here also like you can give the same options the dash n and the number or just dash number this changes the number of lines differently and there are other options to one of the options that we always use is the dash f option the dash f option actually gives on a continuous basis the last 10 lines so it constantly updates it it is does not go back to the prompt so why is this important or why do you need this from a feature because the tail dash f and then file name it could be a log file and then you can actually track how the program is working and how the log file is changing over time so now you can say like I mean how the program is actually progressing and then if you see anything wrong with that you can put a stop to it if you control C and in fact to break the tail minus test you are you need the control C to come off of it and the same thing basically when you can apply to the program itself if you see something wrong in the running of the program you can put a stop date and this is it does not change the timestamp on the file name so if the file name is getting written out and you are worried about changing the timestamp you should not worry about it if you are using a tail minus so now let us look at how the tail is used in a file so here we specify tail minus tail just Linux text and it displays the content of the particular file but only the last ten lines so if it has more than ten lines those lines are already omitted in this example so as I said earlier when we talked about the less command the command that goes along with the less is what is called the more so more is very similar to less displays the files and it is it displays one screen at a time and again as very similar to go and again it has many options the dash C clears the display before actually clear the screen before the display of actual display and then dash n displays the first n line from file and the plus n displays the lines from that particular n and then you can also just see the the next set of lines next page full of lines by just pressing enter the same concept basically in the less you be pressed the space bar here we press enter to advance to the next page so one use of the more command is shown here so we do a LS LS is the list command we know about that and then we know that minus la L stands for the long form and then a is basically all the files which includes the dot files so here you see like the auto SSK the dot the auto mount is the file that says which I see it also displays these files which are missing when you just said LS or in LS-L so and then it also displays all these things so here there are a couple of things to note in this command one is the LS-LA which we already learned about and the slash which is the root directory that we know about there is a special character which is the pipe we call it pipe command it's actually a command and then the more so the pipes and keys are something that we will learn later on these are the commands to change the the command flow itself basically so here in this one what we are saying by using this pipe is do the LS-LA on this particular directory and send that output to this program and this program is more so it displays your directories page the page the first page has all these elements then it will say like more so if you press like enter then it will show the next page usually the more command exits out when it comes to the end similar to the cat essentially whereas the less will still be inside the program so I think like that is one of the probably the difference between more and the less but I guess this gives you a very good understanding about additional commands we will take up from this point onwards the next time around we will go into more deeper into the Linux now now that we understood pretty much the basics you will see what do all these characters mean what does this mean what does this mean then your how then the date time your extra are represented even like these these things what do they mean so we will learn about those kind of things in the next session so again thank you very much thank you for listening again during the next time I will again recap the this particular lecture and then we will continue from that point thanks once again