 Hello all, myself Manasi Bappat. I am from MTech2. I will let us start with the lab session of day 2. So, the sample files can be downloaded from cac.iitb.ac.in tilde minus cb slash csads. So, please open this in your Firefox. You will see day 2 lab dot zip. You have to download this file. Now, open your terminal and go to desktop and say unzip day 2 dot lab. Now cd to that directory and everybody is done with this much. Now, if you type ls, it shows you the list of files. Now, let us start Linux basic commands are of 5 types. Some are general purpose utilities, some are about file system, some are file handling commands, then compressing and archiving and then we will go to simple filters. So, we will start with the general purpose utilities. First command is calendar. So, you can type cal in your command prompt and you will get the calendar of this month that is September. And if you want the calendar for another month say January 2009, then you will say cal January 2009. For example, cal will enter you the time table. This is about the calendar command. Could everybody see the calendar? So, the next command is date. It will give you the current date. So, type D A T E. It gives a date in a certain format. We will show the systems date. The next command is echo and printf. So, echo will you have to type echo a space and in double quotes you will type any message you want to print on the screen. So, if you type echo and hi then it will print hi on the terminal prompt. Just type echo E C H O space then double quotes and type any message. The message will get printed. You need the root privileges for it and I am not sure whether you really have it. The date command can be used to set the date, but it needs root privileges. You can give date in the format M M D D Y Y. If you want to set the date, you can say date and the date in M M D D Y Y. The second command is just to see the output of date in a certain format. There is a Linux manual with which you can see the information by typing man and date. You will see the options available and how to use them. So, shall we go to the next command now? This is echo. You have to type echo space and a message in double quotes. This will give you a message followed by a slash n that is a new line character and the other way to print the message on the screen is using printf. You have seen it in yesterday's lab for C session. So, printf and a message will not print the last slash n. So, if you want to get the command prompt in the next line, you have to type slash n also. Let me show you echo. Hello will give the prompt in next line, whereas printf will give the prompt in the immediately after hello. This is the hello is printed and immediately you get the prompt. So, you will have to type hello and then a slash n which will give the output same as echo. Slash n is a new line character. If you for printf, if you do not give slash n, then you get the prompt immediately after the output. So, slash n has to be mentioned explicitly in that case. Now the next is about calculator. There is a text-based calculator available in Linux which can be used using command bc. So, type command bc, it will not show you anything. It will wait for you to enter an input. So, if you enter input say 2 plus 5 or 2 plus 7 whatever, this is your input and the output is produced and the next line. You can further write any other input you want to say 4 into 3 whatever 1, 2. It will show you the output once again. After you are done with all your calculations, you have to say control D. Control D will exit and get you to the prompt. There is also a calculator xcalc available in graphical mode. You can type command xcalc and see a calculator opened, which is similar to a Windows calculator. xcalc shows you a GUI or graphical based calculator. The next is a bit complicated command that is script. Whatever commands you are entering right now, they can be viewed later or they can be stored in a file using this command script. So, you will have to type script, a space and any file name you want to say demo file. This will be a file where your session will get stored. After you enter this command, it will show you that script started and the file is demo file. It will again give you a prompt where you can type other commands which you want to. This will be your session. So, for example, if you type echo hi example, it will show you the output in a normal way and this output and the input will be stored in the file demo file, which you can see later. So, for example, again printf if you want to see the difference between printf and hello for example, you will also say slash n. This all these things are getting stored in the file demo file. After you are done with your session or storing this session, you have to type control d once again, where you will see that the script done, the file is demo file. That means, whatever commands you have entered in between, they will be stored into the file and you can see them later. Now, I think everybody knows the command cat to see the contents of the file. So, you will say cat demo file and it will show the session which was recorded. It will start with the time when the session was recorded. So, that you can have multiple such sessions. This is the time and then the command which you entered and the output which you have got. So, though all such commands will get stored and the last line will be script done and the timestamp again. Any doubts? So, this file will remain in your directory. So, if you type ls, you will see this file demo file. So, you can view the contents later also. Since, you said that this is our session file, that is it will store the session part of the session that you want. So, once you exit the terminal and come back to the terminal, will you have the file still or it is lost after. Yes, you do have the file. So, it will remain in your directory. So, it is not like a session per se file where you exit the session and the file is not lost. This is there to store your session. So, it will remain in the same directory day to lab directory. Then you see if you start a new session, then you can specify another file name, the script followed by a file name. Will it be overwritten? If I give the same file name. If you specify the same file, it will get overwritten. If you do not specify any argument, there is a default file in which it gets stored, but it is better to specify the file name. Otherwise, it will get overwritten. So, this will be your demo file. Now, next will be maybe demo file one. Is there an option to append to the same file? Not in this command. There is an option to append or concat the two files using that is. If I am not ending the script by control D, automatically it will end once I close the terminal. Yes, you can type clear to view a clean screen. So, the next is pass wd command to change your own password. So, on the terminal type pass wd and hit enter. Now, it will ask you for current password and if you are changing the password, please remember it afterwards. So, otherwise do not change it. So, since I do not know this password of this system, I will show you what output you should be getting. It will ask for the current password. After that, after you enter the password correctly, it will ask for the new password which you want to set now and you have to type the password again just for the confirmation and after that you will get password updated successfully. So, now, this will be your password for the further use. So, we will go on to the next command type who. It will show you how many users are logged in currently to your system. So, if you have, let me explain using this, this has many users so that there are different. So, first column represents the user name. The second column is for device file. I will talk about it later. This represents the date and time when the user was logged in and the machine from which the user has logged in. So, it is possible to have remote connection to your system. So, it seems that from NSL 42, a connection was made to my laptop when the command who was typed and this TTY 7 represents a GUI, the way you have entered your username and password. You will be seeing another, you will be seeing two entries right. One will be for your GUI and the other will be for the terminal which you have opened. So, for every new session, it will create a new entry in who command. If you open one more terminal here and type who, you will see three users logged in currently and you will see the time when the user is logged in. All these users are from the same system. Nobody has remotely connected to my system. So, I am getting colon 0, 0.0 and all. And otherwise, if you have the remote connection, you will see the machines IP for example, NSL 42 or 10 point whatever. There is some kind of powerful way of knowing what those users are doing on my system. So, type W to see that it gives you another information that is idle time for how much time the user was idle. And it will also show what the user is doing. This shows X session means GUI, some user is typing W command and there is another guest user which is doing some batch operations that is some operations on the terminal. So, this gives you a kind of detailed information with the idle field. If the connection was not closed properly, this idle field can contain say one day or two days or such kind of entries which you will know after typing W command. Now, this is the most important command which I think you will use quite often the manual page. This gives the detailed information and all the options. Generally, the options are more than one page. So, it will show you the first page. For going to the next page, you will hit space or page down and Q to quit. So, for example, man of LS will give the options and it will basically give you the usage and then it will give all the options. So, minus A, it has do not ignore entries starting with dot. This is about the hidden files which you may or may not be knowing. So, these are all the available options here. I would like to explain the option minus L which is about long listing. Use a long listing format. It gives the permissions and the detailed information about the files. So, LS will give only the list and minus L will give the other information. We will talk about this later. It gives you the user, the owner of it and the date, time, etc. So, this information can be got. Now, we will talk about the Linux file system and the file system structure. Here, slash is the topmost directory. You must be familiar with C drive, D drive in Windows. Similarly, you will have several such file types. Slash home has home directory of all users. So, your user name will be present in slash home directory. The privileged user that is root will have its home directory as slash root. Then, there is slash dev which is for device files. So, the USB drive if you connect that will be in the slash dev directory. And when you want to access the USB drive, you will have to mount it to slash MNT. This is a general convention basically. Slash MNT is used to mount the other directories or other devices. So, USB which is the external file system that can be accessed like the normal files using by mounting it to slash MNT. Mount command you can see with man pages slash where it contains the variable data like log files slash USR contains the packages which are installed and slash ETC is for configuration files. So, for my network or NFS installation which you might be doing next tomorrow or day after tomorrow, you will be modifying some files or you will be seeing the files in slash ETC. These are the file system commands we will see. The first could be cat I think you all are knowing it say sample.txt. So, if you want to copy one file to other you will say copy the you will say copy cp the old file and the new file. So, the contents of sample.txt will be copied to another file copy.txt. This will retain the initial the file sample.txt and create a new file. The move or rename can be done using command MV where the initial file sample.txt is replaced by the new file. Now, creating a directory using mkdir and a directory name. Now, if you want to delete a file you will say rm space the name of the file and if you want to delete a directory you will have to say rmdir and the name of directory the directory should be t to delete using rmdir and if you want to delete the directory as well as the files inside you will use an option minus r which represents recursion. So, it will delete the directory as well as the files inside it recursively. So, rm minus r you can see after typing first command say cp command you can see ls do ls and check. So, sample.txt and say 1.txt I have copied sample.txt to 1.txt for example. Now, I will say ls to see that 1.txt exists. If I see the contents of both the files they will be same. Now, I will delete the file if I want to using rm 1.txt. So, let us go further about attributes. If you type ls minus l it will show you these are the attributes which are shown this is the user and the group this is the owner of the file basically this is the date time and the name. So, here ls minus l will list you more than 2 entries it will show. These are in all 10 characters which represent the attributes the very first character is d if the if it is a directory. So, here test is a directory hence the d will come and the remaining 9 characters are can be made of group of 3 each which represent permissions. We will see what are those permissions they are r w and x for read write and execute of a file. A directory is also a type of file we will talk about the read write permissions of after a while. This is about rwx permissions and these are the 3 groups where the first group of characters represent the permissions to the owner of the file. Here the owner of the file is minus e and the group is for example, you people are could be a part of group say workshop and so you will have permissions rwx on a file in your on your laptop and r dash x represents the file the permissions it will represent permissions to the other people in the same group and r dash x basically means it has read and execute permissions and not write permissions. So, write is absent which is shown by dash here. So, the owner of the file can read write and execute on the file, but the group members cannot write, but they can read the contents and execute the file. Similarly, this is for others say a guest login they are neither not a part of the group also. So, even those users can read and execute the file. Now, let us the read write execute on a file is trivial right about the directory every directory has the files contained and the subdirectories. So, the contents of the directory are the files present inside and if you you can read those contents using if you have the read permission to the directory you can write into the directory which means you can create a new file into the directory if you have write permissions and execute is to go into the directory. See you have used cd and day to lab earlier. So, that is because you have the execute permissions on that directory. Now, how to change these permissions? Here you will see that ls minus l will show that the proc.c has only read permissions to the group and the other others. So, you can give w or write permissions to the group members you have to say g plus and w w is for write g for group and plus is to give the permission. So, you can try giving right permission to the group members and in ls minus l you will now see this entry w for the group members. Now, if you want to change the permissions of all I mean you can simultaneously change the permissions of a file this needs this can be done using this you have to give the permissions in number form these numbers are for represent the update information that is 7 means 1 1 1. So, all r w x all the permissions are given 5 means 1 0 1. So, 1 means r is present w is not present and x is present. So, this is the easiest or fastest way to give the permissions to all the users or change the permissions of all yes. Yes 4 means 2 and execute means 1. So, if you have r w x all the permissions then r so 4 plus 2 plus 1. So, the count becomes 7 this way you can set. So, the permissions will be from 0 0 0 to 7 7 7 0 0 0 means even the owner does not have any permissions to the file and 7 7 7 means all permissions to all users. Excuse me. Yes. In that 10 characters representation. Yeah. If first character is d then it stands for directory. Directly. If it is l then it stands for because it is showing here l for 1 5. L is for link basically. Okay. Basically you the way you create shortcuts in windows create a shortcut on desktop similarly you can have links in the Linux file system also. So, l represents link we will go further this is changing permission of the file that is changing the ownership of the file. The command is chown the user name to which you want to give the permission colon and the group of the user and the file name. It needs the privileges basically ls minus l was showing that this file is owned by Manasi which is a group member group Manasi. Now you will say chown guest colon guest which will give which will make guest as the owner of this file now. So, here ls minus l will show that this is file owned by guest. So, let us move on to file handling commands. We have already seen the command cat which can also be used to concatenate the two files. So, if you specify cat followed by file name 1 and file name 2 the files will get concatenated. So, try typing cat sample 1.txt and sample 2.txt. Sample 1 has only one line high and sample 2 has the two lines which will get concatenated. The two files are not modified only they are concatenated on the screen. The reverse of cat is tac where in similar way if you say tac and the file name it will reverse it will print the lines in reverse order. So, it will first print the last line and then it will move on upwards to the first line. And similar usage as of cat tac followed by two files. So, it will first reverse the file the first file and then it will reverse the second file. This is about the long files which may not be able to fit in one page. So, there is an option more and less to see one page at a time. So, similar to the manual for seeing the manual you will see space to see the next page. Now, wc is about statistics of the file the number of lines words and characters. The options minus l minus w and minus c represent the counts. This command is for comparing the two files whether they are identical or not. So, if you copy a file say sample dot txt to say copy dot txt and you will say you say compare cmp you will not see anything because those two files are exactly identical there is no difference. So, cmp basically returns the first difference or the byte which where the two files differ. For the exact two copies it will not show anything on the screen. For the two any other files say cmp sample dot txt and sample 1 dot txt for example, it will show that these two files differ at byte 2 of line 1. This byte by byte information is not always helpful because you do not see which what are the bytes which this is not readable basically you do not know what is the second byte you will have to go to the file and then see. So, there is a command diff for that it shows the lines in the first file which are different and the line in second file it is here you can see that those two files have nothing common. There is another command to see what all common things the files have. So, try typing command comp and file 1 dot txt and file 2 dot txt this will print the output in three columns. The first column is the words in file first file which are not present in second file. The column 2 is for the words in second file which are not present in first file and the third column represents the words common to both the files. So, here you can very well see what are the differences and what are the similarities. So, let us come to compressing and archiving. The very first thing which you did downloading the zip file and typing the command unzip that was about compressing and archiving. There are several commands to do compression and archiving this is basically used for backups. So, the files the I had to give you a set a bunch of files which I compressed and made a single file out of it and then you when you downloaded the file you had archived you had extracted the contents of the file. So, this is about compressing and archiving we will see the most powerful command for compression and archiving this is star command. Compression is basically used for taking backups. So, that you will store a bunch of files will compress for efficient use of space. Star has several options. Option C is to create the archive will actually create an archive afterwards. C is to create X is to extract from the archive. F represents the name of the file which the archive should be that is F followed by output file dot tar dot gz it will produce the output this tar dot gz as the output as the archive. The V is for verbose which lists all the files which are present or which are the files getting compressed and the last option is Z will it is for tar dot gz it is for a special purpose basically there are let me list all the options. The first is tar command there is also a command called gzip there is also the one you have used zip and unzip. So, this Z option enables us to combine both the options of command tar and gz. So, it will first combine the files into a single file and then it will compress the file. So, we will see the usage. So, type tar minus Z C V F here C will represent the creating of archive then test dot tar dot gz will be created out of the file test. So, the test file has the file test slash long file. So, this file will get compressed. Now, if I do ls I will see that test dot tar dot gz is creating created this is your archive which you can store as a backup. Now, if you want to see what is what does this tar file contains then there is an option minus t to see these contents. So, type tar minus it will list what all files are present and now if you want to archive or extract the files there is an option x instead of c. So, it will get you the original test directory again. So, let us talk about the filters. Filters basically take input file and they will filter or depending upon certain pattern matching it will produce an output. So, the first filter is head and tail. Head represents the top of the file default 10 lines. So, for a very big file you will see the first 10 lines of the file. The command tail is more often commonly used which will show you the last lines of the file. There is an option minus n to select how many lines you want to see. These commands are basically used to see contents of log file for example, where the log file gets appended you will see the last updated contents at the end of the file. So, you will set tail and the file name where you will get the last few transactions or last few changes. The next is about cut. Cut is especially for to access a database kind of things where the question which you asked about if you want to see the contents of the file depending upon. So, for example, I have a list of students and their role numbers they are say they are B takes or M takes or whatever. So, I can now see only the people who are B take using this command with cut. The simplest use is cut minus C which will show only a certain set of certain characters. So, here cut minus C and 1 2 3 4 will show me the first 4 characters. So, it will give let me show you what the data file is these are very funny. So, here these are the first 4 contents which you are seeing 1 dot then a space and I these are the first 4 columns. You can also specify them using hyphen which will specify the range that is 1 2 4 1 dash 4. This is about seeing first few characters and a better use is first few fields. So, for example, I want to see the second and the fourth column of a file. So, here we have to say a delimiter. Delimiter is basically the one which is between the two columns. So, generally we use space between the two columns. So, this is the delimiter and minus F will show the field number that is which column you want to see. So, here cut minus D by space means that the input file is cut at the spaces and you are seeing the second column of the file. If you say the first column it will show the contents of the file till the first space. So, similarly for any large database for example, you can see this. Paste is basically to paste the contents of two files side by side. So, the first file was this and I want. So, for example, Isham and see Mohini, we have some other information of the same users. I want them just side by side. So, these are the two files you can try out. So, paste then the two files say unsorted data and sorted data for example. So, it will show you the columns side by side. Sort another important command. This also uses the delimiter and the column number. So, for example, you will have a delimiter as space and depending on the second column you want to sort your file. So, for example, the second column is roll numbers then your file gets sorted according to the roll numbers. If you want to sort by say the last name, last name will be say fifth field for example, then you will say sort minus t space minus k 5 and the sort data. So, sort is also important one of the important commands. Now, these all these commands can be used together. So, for example, the output of first command output of cat command can be given can be sorted and this can be done better way using the scripts. This is about grep command. Grep basically matches a pattern. So, it will scan the file one by one and the a line which matches the particular pattern that line gets printed. So, the file three has some data and if you say grep session in that file you will see the first line printed. If you type say grep is then also the first line will get printed. You can have any other pattern for example, numericals or there are different ways to define the pattern and accordingly the corresponding lines will get printed. These are mostly you can say basic commands of Linux which are used quite often and you can type these commands one after the another in a single file and you can execute this file. This is done using scripts which is in a way easy in a way difficult it depends on what exactly you want to write in the script. So, we will now turn on to the shell and other aspects. Dhaval will cover those things. Thank you.