 Hello all, welcome to the session wherein we will discuss about basic Linux commands. In this session, we will be using some sample files. You can download the sample files from www.csc.iitb.ac.in slash tilde avdhuth. Open your terminal. As we discuss our commands, you can write on your terminals, so we will start our session now. So we will be discussing about basic Linux commands. So this, we have divided this into five things. General purpose utilities, Linux file system, file handling commands, compressing and archiving files, simple filters. So first we will be discussing about general purpose utilities. As I discuss these commands, you can try it on your terminal. So first thing is very simple. We will first try it from very simple commands to then we go on to the complex commands. So first command that you will know about is the calendar. So for example, if you want to see any calendar for any month of an year, you can type cal followed by month and year. For example, here cal April 2009, you can see the month of April and even the date, the current date will be highlighted in that month and next one is date. Date displays the current date that means today's date. So when you type just date, then it will be like you will get the today's date in this format. Then there are actually some options which are available so that you can modify how your date looks like. Like the option small d will tell the day of the month like 1 to 31, then y, the last two digits of the year, hms, hour, minute and seconds respectively and d, the date in that format. So for example, date in the second thing as I have given. So here you can see date plus percentile d, percentile h, colon, percentile m. This produces the date in this specific format. So for any information, for more information, you can see man and command name. I will discuss more about this man command later. Hope that everyone has tried out. With this date command, even you can set your own date but for this, you need privileges. So on the current systems, I don't think that you have the privileges. So if you have root privileges, you can even set the date. That command is same as like date followed by the time you want to set. Then we will see about echo and printf statements which will just print the messages that you want to be printed on your terminal. The usage will be echo followed by message within inverted commas. So for example, echo welcome to the workshop will be printed on your terminal and you can use another command printf which is same as cease printf statement mostly. So you can even print the messages on the terminal using this statement. So you can try it out. These are very simple commands. Now we will see another command for calculator. It's a text based calculator. You have, I think most of you have used Windows machines which has a graphical user interface. It's a calculator in a graphical user interface form. Here also in the line x versions that you have on your desktops, you have GUI calculators that is xcalc but there is another basic text version of calculator called bc. You can type the command bc and then there will be an empty prompt that will expect an input from you. So you can type this input which is here and then the output will be there. So this is a basic small version of text based calculator. Now we will see a somewhat more complicated command which is called script which is, you can record your own session. For example, now for example you have just tried out two or three commands. In future you will be going to do many other commands. Now you want to save those output and even the commands that you have given to the system in a file. So script command will do that. Script commands, command records your session and stores it in a file. So you can start using command called script which will display a echo message called script will be started and file is type script and then you can type any of the commands in this. So this is a sample script session then it will be echoed and till the point you want to just log or come out of the script type control d and there will be a message which will be like script done file is type script. So here when you type just script it will be like the default file name will be type script but you can even type script followed by that file name which will be the commands will be going to be saved on that in that file. So for example if that type script file already exist in the directory that you in which you are typing that will be overwritten the file will be overwritten and you can see the type script file the log file that you have created using script used by cat type script we will see about the cat command later but just use it just to see it what commands you have typed. Now the another important thing pass wd changing your own password. So for example on your machine we have set it the password to be 1, 2, 3, 4, 5, 6. So you can type pass wd command to change the password of your system. So it will be asking the current unit's password that you need to type that is 1, 2, 3, 4, 5, 6. Then the new password that you want to be reflected onto the system and you have to retype the password and there will be a message which will which will say that passwords updated successfully. The next command that we are going to try out is who since Unix is a multi user and multi user environment many user can log into log into the system. So if you want to know who are the users currently logged on to your system you can type command who which will tell you like which are the users which have been logged into your system. So try it out I think mostly nobody will be logged into your system but it will display your own name which one yeah. So here you can see that on my system there were four people who have been logged in this this is the IPs of their machine from which they have logged in under the system. So this is actually when you log into a system the system will actually create a device file by name pts slash 0 slash 1 slash 2 assigned to your terminal that so that the file name I will talk about it later but it is just a device file name which is attached to the terminal that the user has logged in. So this is the most important command that we will be using most of the time the man command. This is a reference manual command man displays the documentation for a command. So the syntax will be like man followed by command name you can type like for example man ls or bc that the commands that you have tried out which one sorry second field okay this one this one is a date. So that is actually so when a user will log into a system there will be there will be a file which is attached to the terminal that is like it is basically everything will be like files in the Unix. So how the data transfer will takes place between the your system that the system the host system and the remote system it will be going through that file device file. So it will be created one. So you have I think you have opened as many terminals you have opened that many files will be created. So if you have opened two terminals there will be two files which will be created. It is used to identify your logins. There is a number of tabs that you open in a terminal also corresponds to the files. So you can type man and command name like bc that you have tried cal that you have tried to see the reference manual for that command we will see this command ls later but just try it out the bc and the cal command that you have tried out. So it will be giving you the description and when you type man and command name so the reference manual will be huge so it will be outputting in a page by page format. So to navigate from one page to another press space bar and to exit the man page press Q. So for example if you want the reference manual for man itself you can type man man command. Man followed by man you will see the reference manual for man. So these were the general purpose utilities that those are very simple commands. Now we will go to linux file system. I will explain briefly the linux file system and also the commands associated with the file system commands like we will be seeing that more. So like in Windows you have seen that the file system is like see different drives c drive, d drive, e, f and floppy it is a drive something like that. Now in linux everything starts from slash that there is a topmost thing topmost directory then the slash dem will contain all the devices that are accessible as files. So as you have seen like the pts0 pts slash 0 pts slash 1 in who command this will be there in slash dev directory. So you can go actually we will see it later. So all the devices like if you for example if you connect a USB to the machine so there will be a file created for each device that will be present in slash dev directory. Now slash var, slash var is a variable contains variable data such as mails, log files. For example let us say that there is a server like apaches like the server which hosts a web page. Now the logs for the logs that who have access the web page what is the user names and password all will be stored in slash var directory under some other directory like if it is apache it is a it will be stored in apache to something like that and slash user slash user usr will store all the most of the packages which will be installed on your machine that will be stored in slash usr directory. So all the configuration file associated with each and every software that is installed on your system will be present in slash etz and slash home will contain the home directories for all the users which are present in the system and slash root is the home directory for the root user which is privileged. That means he can install and he can do everything on the system the root user. Slash mnt is generally used for mounting other devices. For example if you want to use your pen drive or if you want to use your anything you want you first need to mount it on to some folder then you can use it. So these are the things and so we will be seeing commands which are used to retrieve the file attributes. First command will be ls minus ls. So ls is like listing the directory that is the basic command that mostly you will you all know. But here if you want to know the permissions for each and every file then you can type ls space hyphen l command and you will be knowing so the basic the thing will be first there will be permissions owner sorry owner group and the number of bytes then the modified time latest modified time then so on. So first the permissions so you can see drwx r dash x r dash x so this is for file first file may be may be different for your this thing. So here d these are 10 characters the first character if it is d it indicates a directory and if it is dash it indicates a file and now remaining 9 characters are grouped into characters of 3 3. Those 3 characters so you can see that there are only 3 characters which which appear in the rest 9 characters that is r w and x. So r r is for read that is file or directory is readable w is for write that is file or directory is executable writeable sorry x is for execute that is file and file or directory is executable. Now what does it mean read write and execute I will tell you but what are these 3 groups so first group corresponds to the owner of the file or the directory second 3 characters correspond to the group permissions for the group last 3 characters will correspond to the permissions of the permissions given to the others. Now basically first as you can see first file has now this the third column the third column here is which is the owner of this current this file so for this owner that is 3 re it has r w x all the read write and execute permissions and for the group called 3 re it has read and execute permissions but no write permissions okay and for others other than like the users who belong to other than group 3 re or if he is not an owner then he has only read and execute permission no write permissions on the directory okay any any doubts any doubts in this yeah they can they they can be different or they can be same yeah they can yeah yeah so for example if you can create a group which which will be like 4 or 5 users belong to that group and you can give certain files to that group only that that can also be done this is a special case that both are same but it can be different also yeah I will come to that so what does it mean for a directory to be read write and execute if a directory is read then you can read that so first of all everything in the unix in unix are files so even directories are special kinds of files so if a directory is readable it means that you can read the contents of the directory that means what are the files which are present in the directory you can read them right right means that you can write in the directory which means you can create new files in the directory you can create subdirectories in the directory if you have write permission and execute means that you can go into the directory which means you can cd into the directory you can change your present working directory to the to that directory so is it clear or any doubts no not clear execute is not clear so when you open your terminal so it will be the present working directory will be like when you type pwd in your on your terminal just type pwd on your terminal that will be your home directory that is slash home something something and your name will be there or something so by how can you navigate to a to other directory is by using command called cd cd and the directory name so for example the directory if it has a execute permissions you can cd into the directory for example cd dir if you have execute permissions for dir then only you can go into the directory and list the file or do anything if you do not have execute permissions then you cannot go into the directory now will be seeing how the how to change the file attributes like for example if you want to as well as you have already seen the file has all the 9 10 characters as like d r dash then r w x r w x r w x r dashes if you want to change the permissions for example if you want to give the permissions like execute permissions for a particular file how can you do that so there are two ways of doing it the command is actually ch mode with ch mod which means that change the change the permissions like change the permissions of the file so you can actually try it on the sample file that have ch mod first try ls minus l on the directory and you will if you see that any of the files does not have any permissions you can give the permissions as in like this so ch mod o plus x testing dot java means that I am assigning others execute permissions execute permissions to the others now you can see here by doing ls minus l testing dot java have x to others which means others can also execute this file now you can for example if you want to change change the permissions for group then you do ch mod g plus if you want to give write permissions give w read r and execute x and followed by the file name and this is somewhat cumbersome the neat way or easiest way of doing this is so for example you can change the permissions at a time for all the users all the like the owner the group and others by using this another variant of this command ch mod 655 at 655 testing the file name which means 655 are the permissions for that you are assigning the permissions for that file name so six means that so as you have already seen there are ten characters so leave the first character now the nine characters non characters are divided into three groups rwx, rwx and rwx if r is present give it as one so now here when you see here rw dash which means 110 in octal form it will be like 6 now this is 101 this is 5101 which is 5 so you can if you want to give all the permissions to all the members then try 777 which gives all the permissions to the all the members like anyone can access the file anyone can delete the file anyone can execute the file so after after running this command ch mod the number and then file name you can test whether that is reflected in the permissions by typing ls-l ls-l followed by the file name that you have changed the permissions so this number 655 can vary from 0 0 0 to 777 0 0 0 means no permissions to anybody 777 means all permissions to everybody is it clear anybody has doubts in this so another thing here so another if you want to change the another attribute like the owner of the file or the group of the file then you have to use ch-own which means changing the owner of the file so ch-own command is used for changing the ownership and also group of the file to which file belongs to so when you so the syntax is very similar to that of the ch-mod the only difference is ch-own the user name the user id for which you want to give the ownership and the file name so maybe you can't try it on this system because you are maybe you are you don't have privileges or something so and you you can you can check whether this is this has been updated by seeing ls-l ls-l the file name so you can see here that the owner of the file has been changed to guest here I have changed the owner of the file testing dot java to the guest and here it is it has been updated by you can see by typing ls-l and the file name so again this command can also be used to change the group to which the file belongs so the syntax is pretty similar ch-own the user id colon group id and the file name yeah so guest user may not be present so this command may not be executable on all the machines because guest user may not be present so this is this you I think mostly you can't you can't try it on the systems so just noted on that so other file system commands are if you want to delete the file like delete any of the file that you have dummy file you have created so it is rm and file name and then copying and moving the files so to copy the file you you have to type just cp file name followed by the new file name it creates a copy for the file name the original file name original file name will be intact and move move is another command which you may not be like familiar in windows kind of environment because move is like rename rename in windows so for example if you want to change the name of certain file then you have to use move mv command mv first the file name followed by new file name that you want to change so renames the file testing dot java to test java this move testing dot java test dot java it renames the file testing dot java to test dot java now I think yesterday you have seen this how to create the directories by mkdir command mkdir followed by the directory name and for example if you want to delete the empty directories then you have to you can use rmdir so be careful this rmdir is only used for deleting the empty directories not the directories which contains files so if you want to delete the files delete the directory which contains the files first you have to go inside the directory delete all the files then come come back delete the directory there is another powerful command for deleting all those things by using using rm rm command you can delete but with you have to use more options that will discuss later so hope that at least other than rm everybody has tried out some commands so these are the basic line Linux file system commands and how to change the permissions and all those things now we will see file handling commands so first command that we will see is cat so for all these from now onwards you can use the files which have been which you have downloaded and you can like go to the directory cd to the directory and use those files for doing this so cat first command will be cat which is used for concatenating files so cat command is generally used for to display the contents of a small file on the terminal so the syntax will be cat followed by a file name so for example cat sample 3.txt will display you some lines about Unix operating system or something like that cat when followed by one file name it will display the contents of the file name so you can supply more than one file name to the cat command so when you supply more than one file name what it does is it concatenates the contents of each and every file in the sequence that you have given like cat sample 3.txt spaced sample 4.txt will concatenate these two files and it will print echo on the output on the terminal so you can try the sample like cat sample 3.txt space sample 4.txt you will see and there will be no header information you can't distinguish between where the file sample 3.txt ends and where the sample 4.txt begins so that's why this command is called concatenate cat command because it concatenates different files so here instead of two you can give n number of files so it concatenates and throws the output on the terminal so you can try it out these commands hope that everyone has tried out the cat command now we'll come to another command which is reverse of cat it is called tag so as the command states it does the same thing as it states like it a tag command is used to display the contents of the file in reverse order so when you type tag followed by the file name called sample 3.txt then it will display the sample file this sample 3.txt in reverse order so even this command can take more than one file when supplied when supplied with more than one file what it does it reverse each and every file and prints those files in the order like tag sample 3.txt space sample 4.txt will first print sample 3.txt in reverse order then print sample 4.txt in reverse order without any header information that means you can't distinguish between after printing you can't distinguish which portion belongs to which file so there will be no header information like cat sample 4 which file it belongs or something like that so you can even try these commands on the sample files which are present yeah lines so for example A then in the next line B C if there are only A B C in three different lines then it will print C B A yeah 10th line will be printed first and then so on no no no it will not change the it will it will start from that last line and it will print the whole line in the lines in the reverse order hope that this command you have tried out on the sample files let us move okay now we'll see the two commands called more and less which are used as a page for paging like for example as you have already seen if you type man and followed by command name man followed by command name then it will display in in the format of like one page at a time so if you want to for example if you want to see a huge file like there is already one file called sample 1 dot dxt which is very huge so for that you can type more sample 1 dot dxt now it will display the file one page at a time then you can navigate from page to page by pressing space space bar and if you want to quit come out of that command type q so even you can try it out with less sample 1 dot dxt both are like identical commands they do the same thing but less is a standard pager for unique line x kind of systems and in general the less less command is more powerful than more so yesterday you have seen vi small vi kind of tutorial the all the vi commands are mostly applicable in less when you do less followed by file name but not applicable when you try with more followed by file name so for example like more advanced like searching for a pattern and everything can be easily done in using less command so it is more powerful than the more command so you can try it out on your systems so when you try more and followed by sample 1 dot dxt you'll see at the bottom that how much percentage more the text is remaining and when you type less followed by the file name you'll see how much percentage like less it is remaining something like that you can see the statistics below hope that this command these two commands you have tried out let us go through one more command which is wc so it gives the statistic of file for example if you have a text file you have many text files like sample 1 sample 2 sample 3 you can try it on many many different files so wc command is used to count the number of lines present in the file ASCII file words and also the characters number of characters so here the word is taken as anything which is delimited by a space so A space B space C so A will be taken as a word in the characters even space will be one character and slash n will be considered as one line so you can type wc sample 1 dot dxt you'll get these three statistics 65 2776 17333 sample 1 dot dxt so first one tells you the number of lines then number of words and then number of characters and if you want to display if you want to display only the number of lines or just number of words or just number of characters you can use the option so here I would like to tell you that every unix command will be like this command followed by options and followed by some file name or some input or something like that so there will be options for each and every command so you can try options for this command which is like for my if you type wc space minus hyphen l followed by file name it will you only the number of lines which are present in the file and if you type wc space hyphen w space followed by a file name it will give you number of words and similarly for hyphen c it will give you number of characters and if you want to see all of them together just type wc and the file name that's all now this is somewhat important command this command is used to compare two different files so for example if you have two identical files or for example if there are two ascii files how can you say that both are identical or both are not identical or where they where does they differ something like that so this command will be useful in telling you which where whether they are identical or not so the usage will be cmp followed by file name file first file name followed by second file name so it takes two file names for the comparison and the two files which are given as input to cmp command will be compared byte by byte and the location of the first mismatch will be printed so you can try it out on cmp sample 1.txt sample 2.txt both are different so you will get sample 1.txt sample 2.txt differ byte 1, line 1 so even the line 1 is not same in both to check whether you will get correct output when you supply both identical file both files both identical files to the cmp command just type just make a copy of sample 1.txt as cp sample 1.txt space sample 1 underscore copy.txt and then supply this cmp sample 1.txt and sample 1 underscore copy.txt okay try it out this command cp sample 1.txt create a copy of sample 1.txt and now give that file two files sample 1.txt and that copy to the cmp you will see that the prompt returns returns back which means that there will be no output from the cmp command which means that both files are identical we will take a pre-break for 10 minutes and then we will come back