 course on the Linux and programming languages, today we will be continuing our discussion on the Linux, Linux basics today is the lecture 3 of the four part series, so let us before we start our discussion for today, let us review what we did last time, so just recap the lecture one we talked about the basics of Linux, we went through like some of the file system, the kernel, the shell, in the last lecture we started talking about some finance, specifically we covered several common form is a maker to create the directory rmdir to remove a directory then rm to remove a file, we also saw the associated options and arguments and we also saw some dangerous commands that we do not want to really use it, unless we know exactly what we are trying to do for example the rm-rf which is a recursive and forced delete, if you do an rm-r star or star dot star and if you do it from your from the root directory will flash, pretty much like everything can be wiped out and then usually in Linux the once the files are removed it is permanently erased, so it is very difficult to get back, so we saw that and then we also saw some editor commands like cat, we found out how to actually edit the file and then we also like looked at the commands like less and more, then we also did the cp command copy, copying the file from one location to another, we also like saw the variations of the copy commands whether we copy a directory over or just a file over what are the arguments for the things like most, we also saw pwd or the present working directory to kind of like in a map it says you are here similarly like I mean if you do a pwd you can tell you you are here, there exactly we also saw some usage of special characters like the greater than the double greater than bang bang bang dollar in this pipe command, I don't know whether we did that if they haven't been do it in the next section and then also the semicolon, so you know that the greater than the single greater than symbol that means the man to actually add it into a file, so we could do like a cat and greater than in a file name to write into a cat into a file and then if you do a ctrl d then you can exit out of that, so that whatever we write on the terminal we go into the that particular file name, the double greater than is more like appended to the file bang bang is the execute the previous command in general like bang denotes that it is a command needs to be executed, we will see this bang in another other cases too like I mean we talk about that and then we will see how we can do it and then also we saw this semicolon or that is basically a command separator, so in a line you can have multiple commands separated by semicolons and command interpreter will understand that has different command and execute in a serious fashion, so pretty much now we know how to execute contents in a serial passion and also the these various use of various special characters and things like that, so now let us see some activities that we can do based on the lecture too and just assigning you couple of activities one is try to use man we learned about man in the first lecture, use man to find more details on the CP command and also the RM command as you know like CP is the copy and RM is the copy, so just type man CP man RM in terms of activity create a directory called a leg to in your home directory and create a file called a leg to dot text and it should contain the following nation I have mastered how to create a file in Linux this you can do it in two ways so try both ways and then also the copy this file over to another file called my leg to dot text so you see here in my leg to the way that we write it is basically start with a lower case character and then whenever there is a word boundary we take the the next the starting letter of the second word or the next word as an uppercase and then we continue on this particular way of writing is called the camel case form I think this will be preferred way to actually code in variables or filenames etc you will see this more and more in future discussions when we go into the programming itself it's it's easy to read people also do like separate the words using on the score that's another way to do it but I prefer this camel case it is also like very cool and with a lot of programmers today so now let's look at the topics for today's discussion now we will continue our discussion and we will do some more deeper look into the Linux system today we will learn about how to manage the file access what are the commands for doing that and what are each of the what we each characters or various types what do they determine and then we will also go into managing the system resources this is another big topic as to how do we control the program execution we won't go into a lot of detail in today's discussion we will only see how to access those the system resources we will also talk in the next lecture as to how to actually really going to controlling the resources themselves and then finally we will finish today's discussion with how to manage storage which is also another key point because in a general Linux machine the operating system can assume that storage is infinite today the programs are becoming bigger and bigger and as you know like the operating system once we start working on the Linux operating system and if it is a Linux 64 bit operating system you have like all the two power 64 bits as the address space which is like trillion trillion or number of bits to be addressed and so it almost looks as if like it's an infinite storage space but in fact the in reality like a limited storage so then we need to know how to control the storage and how do we get information about how much storage is left so that we can plan and manage accordingly because in reality the systems will have one terabyte this so how do we make sure that we have enough space when we run programs and we also look into like various types of memory and typically like I mean so you heard about hardware resources on the RAM and the main memory things like that you will see like how those terms translate into the system so let's begin our discussion the number one is the file access as I mentioned so in one of the key determiners of the security within Linux is because it has a very strict control on who can access the various files so when you create a file it's not that it is easily portable and basically anybody can access as you know the Linux system it is a multi-user system so even others can actually come and see your directories and things like that but are they really able to see the see the file or they able to write into your file or they can copy it into and they can execute from your place so those are the key things that we will talk about so essentially like the file permission the permissions that you grant so when you create a file you you are the owner of the file and you can grant permissions to others the level of access that they know that it's possible so it's typical way to find out what the level of access from in given file is to use the LS monoclonal and here we will go to the next slide and then come back to this and talk about the permission levels but I want to you to read this on the R means the read only write executable execute permission and then let's look at this so here it's a LS minus L command or more particular directory and then actually it's L minus L or AL which also now gives us the hidden files it start with the part and then the funding so you look at on the left hand side we see that there are some characters so the way to read this is the first one denotes the directory basically if it's D then we know that that is a directory and if it is blank then that we know that that's a file then you have three sets of three characters each and each one is RWX and this is in for this one particular means this R-X and then the third set is also R-X and this is always the same basic is RWX and this could be RWX to and this also can be RWX so the way to read this is essentially like the first one as I said it's mostly then denotes the body where it is a directory or more the first set of these RWX characters that denote the user permission meaning what permission do you have as an owner of this file to access this this particular plan so for example the auto SSK you only have read and write permission so R stands for read W stands for write X stands for execute so in this this particular auto FSK you have just read and write function and then the second three the second set of RWX that denote what is the access function for people who belong to your same group so in this particular instance you see the the third column and the fourth column the third column denotes the owner of this particular or if it's called the user of this particular directory and then the second column or actually like one two three fourth column is actually the group that this particular user belong to so in the second set of the three characters is the permission that you are giving to the the group and finally the last three sets you are saying that it's for everyone else so so for example in this particular is the particular directory is readable writable and executable there are any executable by this particular user and this group it's also called root the group get the permission to read as well as execute that means that you can copy any files from this directory and everyone else also gets the read and the executable permission so that they can also copy as well as execute in this directory so the same thing like if you look at this particular example the file not out you can tell me what it is again it's a file that you know and then the this person who is mad if the user gets the read and write permissions and then all the others get just the read permission the fairly simple for example this media gets the read writing group of everyone so let's look at how we can control the access then we then we have like others accessing this form these files so the particular command called change mode is allows the users to change the permission on for a given user so in the change mode again we can specify the various options which are essentially the user group others all and then what is the permission and then the argument is the file file name or the directory name actually like the other yeah mostly it is the file name and we see like how we can change it here and then you can change the group permission of a given file just by changing by using the change group and change ownership is essentially if you want to transfer the ownership of the file from you to somebody else another user so then you can use the change or the CHM so let's look at an example here the change mode it gives 750 and filing so one thing that I mentioned was for the first set of three second set of three and third set of three these numbers can be expressed in binary option so you can think of this as a one bit screen essentially starting from the first RWX because the D is actually denoted by just the directory or not so now we if you look at this one it's all like it assigns one bit at a time so there are one two three four five six seven eight nine bits total and each set of three can be can go from zero zero zero to one one more so now tell me how many combinations are possible so as you know since you are all like electronic engineers you know that actually there are eight combinations possible so you can represent numbers from zero to seven so so for each of them you can represent either zero to seven you don't combine it and then we don't use any other thing basically we like go up to a radix eight notation so the change mode has this radix eight notation so here then we say like 750 that means that the user gets the complete permission which is read write execute and then comes the five for the group which is only the read and execute so the middle number is nothing basically and then finally the others cannot even read or write or execute no permissions so here essentially like I mean so we can we can look at various things and see what the corresponding number is so can you tell me like I mean what the number for this copy directory is you look at it it's 755 what about say the desktop or the desktop it's actually six because it's one one zero right and then six four and four easy enough we will give you some more practice ones that you can go through this exercise and then see how to do use the change mode and this particular shell also offers some uniqueness essentially like and we talked about this in the first lecture or the second lecture I think where it actually color codes the filenames so that you know what is what for example the AXI RTL is actually it's a direction and then AXI RTL dot zip is like executable or it's a binary file and then the green is the text file things like that that we already know about this so we will see as to how the operating system determines what type of a file it is and then how it can actually put together actually in this case like the main file is actually more like treats it as a script so I didn't make it so let's look at that and now we go into like some more system one is how to report a date so the command is just the date you do the date it tells you like I mean what is the current date and the time so it gives you the the day the date and also the time and it gives you the time zone and the year so a simple command essentially this is used in programs then you want to print the start point you just issue a command date and then once the program finishes your issue another command date and then now you can actually compare in between how much time the program took and then you can take meaningful actions based on that information okay and then the next one is the change shell command essentially this is to change the user's login shell it so you can actually like issue this thing and then the system will prompt for what the new shell is if you just type enter then it retains it as the TCH H otherwise it's changed to bash for example so it's an easy command to move from one shell to another sometimes like some programs are they do want a particular shell and they want to execute in a particular shell because it demands certain resources and certain control of resources so this is the easy way to actually change the shell now let's look at how can we change the password this is one of the important command so here the command is just pass is WD or password and then you can give options I would like you to find what are the options available and password or something like that but in general when you type password the system will prompt you to enter the new password and it checks against certain pre-specified rules in this case actually it is checking against dictionary so if you specify a dictionary word it rejects that password because it doesn't want a password to be in dictionary so that somebody can copy it the system administrator can set up various rules for governing the password so he can demand certain length of the password and demand certain special characters included in the password today most passwords in minimum of 8 characters needs a special character a number and that is different so that that kind of gives like lot more authentication and so for the user so once it use type in a valid password then it updates the existing password and there is a password file where all these passwords are kept and I think like you can tell me like what will be the permissions for that one so if you have if you are listening to the earliest like the permission for that file that is protected only protected and it is only system administrator can actually change that value so in general what happens is when you type password the password command actually gets control of that particular file and then it lets you edit that file only for your input and then once you enter then it is again put back and then the permissions are reverted back and then only the system administrator or the root user can really access that point it is a it is a not read not write not execute I mean maybe execute only by the user so in terms of the the numbers that we saw earlier it could be like 0 0 or actually it should be 1 1 actually sorry I will take it back it is 7 1 1 so as a as a group person or as an others you can only do just execute because you do not want to see others password and you do not want others to see here. Now we go into our second topic this will take a long time today's discussion we already started talking about this but I wanted to highlight what is a process in terms of in the in the context of Linux so one key thing is and we talked about Linux we talked about the kernel we talked about the shell we talked about the file system another key thing is also a process in Linux any instance of the running program is called a process here this is the exact quote from the Linux manual which is actually listed here the reference it's a program or way they define it is as follows a program is a set of machine code instructions and data stored in an executable image on a disk and it is a passive entity so a program they call it as a passive entity which is be there in the disk hasn't been executed but a process can be thought of as a computer program in action so when the when the program moves to the shell and starts executing that's what is called the process so what are the types of processes for example the shell by the nature it's there and it is getting executed that itself is a process and any command that you type in and then as soon as you press enter that is a process that becomes a process so how do we know that what a process is so the operating system itself assigns a unique process ID the process ID is also called PID to every process so it is the number that the operating system assigns to the particular process so as soon as I mean internally what happens is form as soon as you type in a command and press enter the operating system takes over it looks at the command it first assigns a process a process is a specific set of resources required to run the program and then it starts that process and it assigns that process ID so that it can track at any point what is happening to the process because the states of process is very important the state could be running running the process or it's a waiting process or it's a stopped process or a zombie process so we will see how we can distinguish these processes in a much later state but at least like I want you to understand what the way the commands are run is by using these processes so one of the key things is how do we unfold these processes and how do we report these processes that's what we will be learning in the next few slides so to view the processes that you are running the simple command is called ps or process show essentially if you do a ps-all or ps-a that displays all the processes that are running on that particular CPU again this is a multi CPU system the next but the way and it's also a multi user so in and multi tasking so the multi user and the multi task is all represented in the ps so we can just type ps-a and in this case actually ps-a ux which is essentially which stands for the processes that are all the processes including the user processes and the processes that are executing in the background which is without terminal display all the information that is the pux and then you can also specifically say like ps-u and then the username and then it will display the processes specific to that particular user and here we use some command this we will learn in the next section called the grapple and I also mentioned earlier that this pipe command which is essentially the way to do inter-process communication so inter-process communication we use many many things one is this pipe command the pipe command gets the output of this ps-a ux process and then feeds it into the next command so we know like semicolon separates the various commands so far we have been calling them as command but once they start executing like now that we know the term called processes we should really call them as processes so the semicolon is that process separator where it separates from one process another whereas the pipe command actually takes the output of one of the processes and feeds it into the next one so here also like the program execution is still going to be like serial but output can be fed into the next one we will also like encounter other forms of with inter-process communication there are something called T and semaphore which we will learn about in a later stage so let us look at how this ps command is issued and what is what are the outputs so in a in a simple scenario when you type ps this is a single user this particular machine is used this by all this particular session is used by just one user and now it displays essentially like this information which is the PID I mentioned the process ID which is 30380 that's assigned to this the shell so it starts from this this particular terminal pts5 and then it started at time 0 and the command itself is the case in shell and then since we type the ps that ps actually started another process that ID is 30494 and the process command is ps so simple enough and we can it can be more complicated than this but at least like we will know how to display these processes now the process display is a passive display meaning it's given at the point of time but how come how can we look at at least the system resources on an ongoing basis we want to see how things change on a continuous basis and then we are running a program we want to know how much the program is taking because there is no point in actually like running ps every time we have to do it like every month so there is another command for that which is the top the top command is used to view the CPU usage of all the processes it's basically just type in top and then this process doesn't stop at this keeps running so unless you press q to actually quit from that so here you can see much more details number one it tells you how what is the time that this particular CPU this particular operating system is up and running so in this case it is running for two days 42 minutes and it has multiple uses six uses in total and there are 133 tasks total of which one in one is running 132 are sleeping and then nothing is stopped and there are no zombie processes so the task is synonymous with the processes and as I mentioned like the states are running sleeping stopped and wrong so how much is the seeded the cp utilization here it's only like 0.7% by the system and then 0.1% is for the sorry 0.7% is a user path 0.1% is the system path and various others basically and then here we also have a concept of the memory so usually there are two or three types of memories actually one is the main the memory that is available there is also some concept of virtual memory which we will talk about and then finally the swap the soft space so the so here we see that basically this has about 200 206 megabytes of which about 117 actually it's about 2.6 gig are available total and of which like about 1.1 gig is used in another 894 meg is free and then there are buffer allocated already in this one and then there's a soft space which is a separate one which is of another five gig and then everything is free in that soft space and now you see actually the real meat of the command which is it displays the process ID who is the owner of the process and then the various notations this we will talk about it later so here there is also like the virtual memory which is displayed as to how much virtual memory is ticking how much is resident memory it is ticking and then this is the shared memory and then finally the CPU percentage and then how much time it is running so and this particular display is updated very frequently it is not like it it displays once and then it comes out basically it keeps changing continuously it is very similar to the task manager that we start in those program and it also displays on a continual basis as to how the CPU and the memory consume same thing here and you can see that there are multiple processes and and various parameters on that and PR denotes the priority and then this is the knightness basically so we will talk about these additional things in the next lecture. So now an important thing basically once you know like how you know how to run the process how to start a process it is essentially give a command but now how do you kill the process this is also another key important things essentially the command is essentially kill so the kill is to terminate the process and you can use the process ID as as a way to identify which process to kill and then there are there are options available for this particular command again the argument is the process ID and then the options are essentially the signals so here the kill minus 9 means 9 is the highest level of the that particular signal which means that immediately kill and don't even worry about anything like nothing just kill the process so the essentially it generates this signal called sick kill which is essentially to kill the process for sure there is no questions asked let's kill it the kill 0 essentially means 7 is all the current processes except your shell so anything else is running like this is like even because in argument just kill 0 and then it will kill all the processes that are running on that particular CPU so once we also like know how to communicate and how to use the network you will see like other commands to work with the load balancing systems probably like we will learn about that in the fourth lecture so here this is the top command or actually it's a ps-u where it displays all the processes running by this particular user and you have the process ID so you kill this one it's actually right here the this particular side the 305 08 is right here and that's the top so that one you can just kill it using the skill minus mode okay so now let's go into some more commands to identify to use it for identification purposes so the number one is who as we mentioned the Linux is the multi user system but you can know who are all logged in to the system by typing the who command and it gives you the the name of the user and also which terminal that they are using very useful command to see if your friend is logged in your system also you can see if there are any spurious person logged in into your system so just typing the school will get you like all the all the active windows and from there they are connected to and then so these are their IP addresses and then basically like when did they start and then you can also again very similar to the PWD which is present working directory where I want to know where exactly I am in this whole file system similarly you can also ask a who am I essentially and the command is this who am I and that gives you the details about that particular window and that particular user who is using this sometimes what happens is there are systems that are left by somebody else maybe like in the wrong windows that are open which you are not sure whether it's you are the owner and you need to kill it or you need to keep it well so who am I is anistic man to figure out whether it's indeed you who logged in into the system into that particular window or was it somebody else so there are two variations here one is if you know exactly this is this one is who that who space and space I and that gives you more details and if you continuously type in this who am I in one word then that gives you just your username doesn't give you like a lot of details more than that now we come to the the third section which is how do we control the disk space or essentially so one thing to notice in Linux we said that basically everything is through the directories and essentially even this can be mounted in various directories so various one points are also given as for the entry so you can it's very easy to add additional this space that if you want or remove a particular disk also so at any point people could remove stuff or add more stuff into the system so one of the key things that we need to know is how do we what is the availability and how much this space is there that we can use and also if there exactly is that this located so the commands that we study right now are du which is essentially it stands for disk usage and gives you the options I mean you can give the option as well as the argument argument is the directory or the file gives it gives you the exact amount of disk space in use essentially so we will see like how this command gets executed if the du-sh the file or directory that gives the size of the file of the directory and then the other one is the df command the df-h and the df-kh this one gives you the available state mounted on a file system so the du is more like the particular file the particular directory itself essentially as to how much it is getting how much space it is being used is being used by that directory whereas the df will give you more information regarding the whole disk itself as to what is the available space how much where is it mounted anything like that and then free is another command which gives you the amount of free space in the system so let us look at an example these so here so there is this only team which has various files in the directory so you do the LS and then you know all those things now you want to know like I mean what is the size of this text one dot text so you can say du-sh is the text dot text text one dot text and then it gives you it is about 14 you can get this information also by just using lf-l that you already know about assuming and that gives you on the fifth column I think will display the amount of space that the each of the file is taken typically for directory if it lists as 0 so the du-sh directory will also specifically will give you the amount of space taken by that direction then the df-h here actually gives you the particular file system and as I mentioned the disks are even though they are hardware objects they are they become directory so which is in slash dev slash is the 10 so slash dev is all the the disks are mounted on bottom and then here it is a 112g is the size out of which 110 is being used and the use is actually 100 percent because you cannot represent it so it is really 100 percent so you need to go and like change the song and then there is a something called none and then basically one gig is there and then all the things are available and that is mounted on lash dev shm so now you also have this command free and that that gives you like I mean how much is the total memory how much is used and how much is free and then there is a shared memory some of the buffers that are that are special types of memory the cache area is another special one and then how much soft space is all the soft space is essentially required for swapping program with another one so processes when you solve processes this soft space so I think this is probably the end of the lecture two so again we talked about several things I just wanted to recap one more time the the things on the lecture three essentially like we looked into more deeper into the Linux system we understood how to manage the file access the various permissions like RW and X and then the various groups the user group and the everyone else so how do we give access as well as how do we change the access of various files we also talked about managing the system resources from the perspective of what are the what is the process and how do we control the process so again we talked about one key aspect of the system resource which is the type command essentially how to pass the output of one process into another process we will talk more about the processes in the next lecture where we go into some more additional commands like T and the and fork a fork is essentially like T and then the other one is the semaphore basically which is a concept to understand how the inter-processing really works we also talked about the storage itself we differentiated between the memory the swap the virtual memory etc there are special memory elements like buffers and cache areas which are locations but you cannot write into it because those are used by the system itself for writing and then we also saw how we can control or at least get information regarding the usage of the resources from these from using the commands like du and df and the free command one thing that I will add is we talked about the various colored representation by the always regarding which file it thinks it is so as you know in in linux or in with any the unix type of copy system you have you can write scripts that we will see more and more and also we have regular files the platform so the way to use the or write a script is essentially we need to preface the script with whatever the shell that we want to use usually in the form of hash bang then we will specify which shell that we want to use like maybe user bin wish user bin just SH will also work so if we specify that line as the first line in the file then the interpreter treats that file as a script and then it actually runs that the script itself it knows that it can you still need to give the file permission as the permission but the difference between a normal file and executable file is I mean executable file in the form of the script the script is essentially it is a human readable program so usually that one you will have that that has the first line so once again I want to thank you all for listening this lecture and we will pick it up on the next one on this point thank you very much