Transcription
[Music] Linux has dominated the operating system space for as long as anybody can remember. Despite its beginning as an open source operating system, Linux has evolved to rule the whole world; developers now rely on Linux to ensure that they are on the right track.
Hello everyone, and welcome to this session. We are currently watching an edureka Linux full course video. By the end of this video, you will have a thorough understanding of Linux, all the way from theory to the practical applications. But before we go ahead, if you love watching videos like these, then subscribe to Audio Records YouTube channel and click the Bell button to never miss out on any updates from us. Also, if you want to learn more about Linux after watching this session and wish to obtain edureka's Linux certification course, then please see the link in the description below.
[Music] Begin with our agenda, where we'll have a brief overview of what we'll cover in this Linux full course video. We'll start with the fundamentals of Linux, where we'll learn what Linux is and how do we use it. After which we will see different shells in Linux. Next, we will see how to install Linux using a virtual box. Now, once this is done, we will see Linux commands on Ubuntu. After which we will also see some Linux commands for DevOps, followed by a detailed explanation on the Linux file system. Now it's time to deep dive into the technical aspects of Linux. We'll start with the package management in Linux. Now, once this is done, we will then understand Linux administration and learn how to configure a DNS server. After all this, we will see what is shell scripting. We can then see some shell scripting interview questions with answers. We will then compare Linux to Windows and Linux to Unix. We truly hope that this session assists you when getting jobs in the industry. In order to accomplish so, we will look at some essential Linux interview questions. So stick till the end. Now let's begin with the fundamentals of Linux.
[Music] The next becomes popular. Well, uh, before I talk about uh, you know, why they became popular, let's look at the birth of how things started off. Okay, so back in 1969, there was this person called uh, you know, in fact, there were two people: Dennis Ritchie and Ken Thompson. Right, so they were working in the AT&T Bell Labs, and what they did was they created this C programming. Right, so we're all aware of programming. Right, so we're all aware of these basic programming languages. Right, so C is one of the most basic and one of the most effective and the root of all the other programming languages. So that was C, and it was them that developed C and the Unix operating system. So that was what happened in 1969. Okay, and then in the decade that followed, okay, so basically in the 1970s, people started developing or contributing to the development of these two things. Okay, so they started contributing to the development of the C programming language and the Linux operating system. So in our session, we'll discuss more on the Unix operating system and uh, since it's about Linux, right, so Unix is basically the mother of Linux because Linux is based on the Unix operating system. Okay, I'll tell you uh how that's the case uh in some more time, but that's why we are starting off with the Unix operating system. Okay, so I'm now going to cover about uh C and getting back to our slides, so it says growth of Unix because of open source collaboration and there was commercial sale of Unix. Now what this meant is that, you know, the product that Dennis Ritchie and Ken Thompson created, right, that those were, you know, something really attractive; they were some amazing software and operating systems that would, you know, power machines and computers. Now what this meant was uh, you know, they had to be developed to become even better. Right, so they made it open source; it was uh, when we say open source, it means that it was freely available to use by anyone. So anybody, any person, any scientist or any engineer or anybody could just get access to the source code and start improving that source code, and if they feel that they have improved the software in any way, then they can just, you know, give that code back to the developers. So basically it was all about collaborative development. So that's what happened with Unix operating systems in the 70s. Many hippies, scientists, they all collaborated together, wrote their own code, their own version of Organics operating system, and contributed to the development of the Unix operating system. And since AT&T, they were the ones who built Unix, or the ones they were responsible for founding Unix, they were the ones that gained a lot of benefit; they got help from other people for uh, you know, developing the operating system. And what they did in turn was they made it a business. Right, so they made money out of that by, you know, starting commercial sale of Unix, and uh, this was something that did not go down well with many people, and this did not go down well with the other developers and scientists because it was their effort which contributed to the growth of Unix, but however they are not getting any benefits of, you know, Unix because AT&T was making money out of somebody else's work. So that's what happened in the 1970s.
Okay, and then came the 1980s, which was a little more different. So instead of, you know, buying, you know, Unix from AT&T and uh, you know, having two different versions of Unix—one was a FreeBSD and the other one was the paid AT&T version of Unix—so instead of going to go for them, companies started developing their own Unix. So IBM came up with their own Unix version called the AIX; Solaris came up with their own version called the Sun operating system; and HP came up with their own version of Unix called HP-UX. So there are other versions also like POSIX and all these things. Now since there were many versions, right, many flavors and many dialects of the same Unix operating system, it was becoming a little problematic because each of the dialects would be a little different. So the IBM's Unix would be different from HP's Unix, and Solaris Unix or it would be different from POSIX. Okay, so each of them would be different, but however they're all based on the same thing. So it was unnecessary uh, you know, confusion there with so many versions of Unix. So that is when this person called Richard Stallman came up with something called as the GNU project. Okay, so I told you earlier that Linux is just a kernel and not an operating system on its own. So what this person did was, you know, he came up with something called as a free software movement. So he wanted something like, you know, back in assemblies when everyone could collaborate and work on the same one single operating system like that; he tried to bring back that era, and this free software movement, this idea led to the GNU project. So the GNU project was all about people being able to access an operating system for free and, you know, developing that operating system. So that's what uh this led to, and uh, that's what we call even today. Right, so GNU is basically the operating system, and the uh Linux is the kernel that powers the operating system. So a combination of these two is what results in one of the distributions of Linux. So we have multiple distributions like Ubuntu, CentOS, Red Hat, Debian, Fedora—all these things. So all these things are flavors, a combination of one of the operating systems and the uh, you know, Linux kernel. Okay, so that's what they are. So this is what happened in the 1980s, and then, you know, mid-to-late 1980s was when Richard Stallman came into the picture, and he came up with the GNU project where people could develop, you know, and use a free operating system. So that's what happened here, and the event that happened after this is what is a result of today's world.
Okay, so so after that, then in the 1990s, so probably 1991 or 1992, that was when this person called Linus Torvalds, who was still back in college at that time, he put the Linux kernel source code online. So he was trying to use the POSIX version with one hardware called 386, and he thought that it's compatible only with that hardware, and so he put the source code online for anyone to use, and later they found out that it could be used with the GNU, and that's when the whole thing gained popularity. So that's when we uh, you know, came up with something called as the Linux plus GNU—this whole term of having a kernel plus this operating system and getting them to work together. So that's what happened here. All right, so guys, uh, that's how Linux was born. Okay, now without wasting any more time, let me go to the next slide and talk about the various distributions of Linux. So I told you that there are many versions like Ubuntu, CentOS, and also let's talk about those, and uh, when we talk about distributions, the most important and the most famous ones are those of Red Hat Enterprise Linux, Fedora, and Debian. Okay, so these three are primarily different companies and Enterprises. Well, Debian is basically not one company; it's kind of, you know, let's say a group of developers developing this uh version of Linux. Okay, this version of Linux and the Ubuntu version. So that is what Debian is, and the Red Hat is basically not a price; it's a company that is commercially selling the Linux distribution. Okay, and it's probably the most used and the most popular of them all, uh, why? Because they are very stable, they are very reliable, and as it's written here, servers and workstations. Right, so it's the preferred Linux distribution for servers and workstations, the Red Hat Enterprise Linux. So they have a free version, so that's called the CentOS, and uh, today's demonstration I'll be showing it to you on CentOS only. Okay, so they have that, and they have various other distributions; in fact, even Fedora, right, that which we are going to talk about next, even Fedora is a company that's funded by Red Hat itself, so it's again one of the variations of Red Hat, and Fedora has its own set of, you know, distributions under it, and that's about the Fedora distribution. Then comes the Debian. So this again I spoke about Debian, so Debian is, you know, the Linux distribution that is developed with the help of many developers. So this is not developed for commercial purpose; it's basically free and open source software, and anybody with the skills can start contributing to this software. And you have many other distributions. Okay, so these are among the important and the commercial ones, and if you're talking about some of the free distributions which people can use, then they are Ubuntu, Linux Mint, CentOS, openSUSE, Gen 2, and many more. Okay, so there are almost 100 Linux distributions today, and you can use any of them, you know, if you're getting started with Linux, then I would suggest you to either start off with Ubuntu or CentOS because uh, CentOS is, you know, something that's really reliable and that's really fast. Okay, and Ubuntu is the most popular Linux distribution out there. Okay, and so I read somewhere that Ubuntu is the third most used operating system. Okay, so that's what Ubuntu is all about; of course, it's not as fast as CentOS, but Ubuntu is, you know, a very popular and very handy tool. And Linux Mint is uh the other distribution which can be used for playing movies and uh listening to music because this gives you more of a Windows-like interface. So that's what Linux Mint is. So we have various distributions like this; you can start off with one of these distributions mentioned here; you can either go for the Red Hat Enterprise Linux or the Fedora or the Debian or the other operating systems which are based on them. Okay, so the CentOS here, it is based on Red Hat Enterprise Linux. Okay, so uh, the RHEL, right, we call them RHEL, so they have the free version that, you know, they provide for uh Enterprise users is that of CentOS, and uh Fedora again, for that matter of fact, you know, they have multiple distributions under them, under their name, and Debian are the people who are the founders of Ubuntu. Okay, so Ubuntu is a distribution that is based on Debian, and since Ubuntu is so popular, there are different versions of Ubuntu itself. Right, there are other distributions like Xubuntu or edubuntu—all these things, and they are the other, you know, versions of Ubuntu. So that's about the uh different Linux distributions, and you guys can probably, you know, if you're newcomers, then I would suggest you to go for either Ubuntu or CentOS, like I said earlier.
All right, great. So let me go to the next slide then. Okay, so now we are in this slide, and uh, let's talk about the features of Linux. So the Linux features, you know, when we say features, it's basically those compared to the other operating systems, compared to Windows and compared to Mac. Okay, compared to them, how does Linux perform, and, you know, what are the benefits with Linux? And uh, first of all, we have this feature of, you know, the updates being very easy to be performed. If you have any software in your operating system or if it's the operating system itself which you want to update, then it's really easy; within us, it's just going to be one command that you need to run, and you know, you can run that command from the terminal. Okay, for those guys who don't know what a terminal is, so let me just open my Linux version and show you what a terminal is. Okay, so this is my uh CentOS version of Linux. All right, and then you have different options here. Right, so the terminal that you see here, this is what I was talking about. So when you open the terminal, there's another window that opens. Okay, now this is the command line interface. So when I say command line interface, uh, this is where I can put in my commands, and I can get my uh, you know, software or my kernel to listen to those commands and perform actions by creating a process for those commands. So the whole benefit of Linux is this CLI because CLI is really helpful. If you're going for Windows or something, you have a very good GUI. All right, so even in Linux you have a GUI. So let me show you the GUI aspect. So similar to Windows, you can just go to the computer, and you can go to the file system; you can open various other folders and directories. So you have multiple directories and folders here. Right, I mean, directories are basically folders; folders is what you call in Windows, and here you call them directories. So I can go into any of these uh, you know, directories, and I can close them like this; I can access any of these directories; I can access any software or anything that's installed anywhere. So Linux basically provides a GUI too. Okay, but the thing with Linux is that you also have a terminal. Right, this terminal is basically a command and interface where you can, you know, put in your commands, and you can get the software to behave the way you want to; you can run certain commands; you can install software; you can run programs; you can run codes. So that's what the advantage with the CLI is, and this is basically the reason why uh it's very popular among all these software developers. Okay, so I told you earlier that it's a software developer's favorite tool. Right, or not? So that's because Linux is the free version of Unix, and it's also, you know, possible to develop and create so many programs. So that's the thing with Linux; so that's why it's so popular. So back in the slides, I told you that it was very easy to perform updates. Right, so those updates can be, you know, easily performed by just running a few commands here; you know, by writing one single command, I can update a particular software. Supposing I have Java installed in my system, then I can just write a command for updating that; I can just say sudo yum update and the package name; if it's Java, I can just put the Java version; if it's any other language or if it's any other software, then I can put that software name over here and update the application. So that's how simple and that's how easy uh, you know, it is to update softwares over here. So I was talking about uh this aspect, so let me go back to the slides and talk about the other features. Okay, so that was how updates can be easily performed, and then another feature is that the software is free, but you don't have to pay for uh Linux. So because Windows, of course, you all know that Windows is paid; you can't, you know, have a pirated version; if you're caught having a pirated version, you will be fined. Of course, home, you know, desktop users and home users don't really have that problem because there are no routine checks, but companies cannot use uh the pirated version of Windows because if there are audits, they can come and seize the computers and put a heavy fine on the company. So that's what we say when the free software licensing is there in Linux because you don't have to have any license; you can just, you know, get all the folks in your company to work on Linux for free. So that's the free software licensing aspect. And then you have the access to source code. Right, so when we say access to source code, I told you that back in the 70s, people could just collaborate together and develop the operating system. So that is what I'm talking about here. So the entire, the source code for uh running this OS, the basically the Ubuntu or the CentOS source code is available to you, and you can customize it, and you can uh, you know, change it the way you want; you can make it behave the way you want to, and if it's a really good feature that you've added, then you can also share your discoveries and your, you know, features with other people, with other fellow developers; you can do all these things. So you have complete uh, you know, access to the source code, and you have complete freedom with what your OS can do and how it behaves, but the same thing cannot be said for Windows. Right, so Windows, you cannot change it completely; you don't get access to source code at all, and you can't change all the features the way you want to because that's proprietary tool, and it's a program to behave in one way, and if you try changing too many things, then your uh, you know, Windows will crash. So that's what is going to happen. So that's about the access to source code feature. And then we have another feature that is multiple distributions. So I spoke about the different distributions in the previous slide. So the basic distributions are those of Red Hat, Debian, or Fedora. Right, so you have various versions of them itself; you have different flavors in the Red Hat, and you have different ones in the Debian, and again Fedora has a lot of other distributions; before that, many distributions are based on them. So you have so many options, and if you don't like one of the distributions, then you can work on another distribution. Right, so if you don't like CentOS because uh, you know, you don't get support for everything, then you can use Ubuntu. It is the most popular operating system, and it has support for almost every application and every software, so you can use that, but if you're unhappy with the speed of Ubuntu, then you can probably switch to CentOS. So you have all that flexibility, and all this flexibility without any cost. Okay, no cost with respect to uh energy or having to learn something new because all these are Linux at the end of the day; the commands will be the same; almost 98% of commands will be the same; there are just going to be minor differences in the commands that will be executed in the different uh distributions, but yeah, 98% of them would be the same; you won't have a tough transition time; also, you'll have, you know, you can gain so many benefits by using Linux. And the last but not the least, right, so this feature is probably the highlight of Linux. So it says better malware protection. So when we say better malware protection, we say that it's the ultimate. Okay, in Windows, if you people uh would have noticed that you need an antivirus because uh it's prone to viruses and attacks and bugs and all these things, so people can easily hack into your system. Right, so the same thing cannot uh, you know, happen with Linux; you don't need an antivirus at all; you're not just completely antivirus-free. Okay, 100%; you don't need an antivirus, and in fact, you don't even have an antivirus, but of course, it doesn't mean that, you know, it's completely secure also. Uh, security is something that's really good, but it's still developing in Linux, but it's definitely better than Windows. Right, so you can be
Sure that no one's gonna hack your system so easily; so that's what Linux is all about. So guys, that brings us to the end of this light overview of Linux features. Okay? And if you guys have, you know, any doubts even now about Linux and how good Linux is, then now that should have been clarified and put to rest by now. Okay? So moving on, so enough with the theory now; let's straight away get started with our Hands-On. Okay? So I'm gonna show you how to run commands and how to do various other things with the CentOS operating system. Okay? So first of all, the first part of this Hands-On session is going to be about, you know, an introduction to the terminal and the various commands, and the basic commands, and how to browse through the different directories. Okay? So we use commands like PWD, clear, LS, and CD commands. Okay.
Now let me go to my CentOS. Okay. In case I uh forgot to mention it earlier, then guys, I am using a VM here. Okay? So I'm running my Windows operating system on my laptop, and I have a VirtualBox installed, and in the VirtualBox I've instantiated my Linux virtual machine. Okay? So my Linux distribution here is CentOS. Let me just show you another thing. Okay? So this is the VirtualBox that I was talking about; this is what I'm running in my Windows, and I have, you know, multiple options, so I can choose any VM that I want to. So this is the VirtualBox, and all these are the different VMs that we have in my VirtualBox. So currently I'm running this VM called Master. Okay? And later on I'll be running on even this VM called slave. Now I'll be doing these two for uh showing you how SSH works. So I told you in the agenda slide that I'll, you know, get two remote machines to access each other, right? So for that purpose I need these two VMs, and of course both are CentOS, and uh yeah, as you can see the information, it says that it's a little bit CentOS system; I've called it or named it master, and this one is named as a slave. So similarly I have the Ubuntu also; so the Ubuntu 64 bit is this. So let me just turn on the Ubuntu and show you how Ubuntu looks like. Okay? So let's just wait for some time. Okay? So let me just enter the password for the user, and here we are; this is my Ubuntu OS, right? So even this is being hosted on the same VirtualBox, so I, I'm kind of running two different virtual machines at the same time. Okay? So we have options uh to browse the internet and again open the terminal here; the terminal option is right here in my Ubuntu operating system. Okay? So I just want to show you the uh Ubuntu operating system, so let me just quickly turn it off and uh go back to my CentOS and start running a couple of commands. Okay? So I was showing you the CentOS, right? So, Noggin. Okay? So this is my terminal, and uh first of all, the main difference that you people need to understand between Windows and Linux is that in Windows it was, you know, the storing uh files or folders; it was all in drives. Okay? So we had a C drive, we had a D drive, we had many more drives like that, and we could store our documents all in those folders. Okay? But in Linux it's a little different from how Windows works. In Linux we have something called as the root directory. Okay? So we have file system here, right? So basically whatever folders or documents or directories you have, everything can be accessed from the file system. When I clicked on file system, then you would have noticed that I got a forward slasher. Okay? So this forward slash basically means root. Okay? This means I'm in the root directory, and in the root directory every document and every folder is present in this root directory. Okay? Now whether it is me storing some kind of uh, you know, important files or MP3s or videos and everything can be accessed from the root. So you can think of this something like a tree hierarchical structure. Okay? So you have one root and all the other branches and all the leaves and all those things; you can consider them to be the different directories and the files inside, so they can all be accessed from the root. And if you want me to show you where uh one minute.
Okay? So now this is your desktop, right? So you have the different icons here; on each of these icons are for a different operation. So you have it Breakers home, and then you have a terminal, and you have an LMS. So this is a folder, and this is a document. Okay? Readme is a document. So uh what I'm going to do is I'm going to browse to the desktop folder. So from root directory if you go to this folder called home, right? So under home directory you have other option; you have edureka and Uzi. Okay? So now if I go to the edureka directory, then you have other options of desktop, documents, downloads, music, and all these things. So if I go to desktop, then in this directory you have the files and the different things that are present on my desktop. So LMS was a folder that was present; readme this is a file that was present; the terminal was present in my desktop, so that is available here. So Eclipse IDE is present here. So all this was present on my desktop, so I get the same thing accessed from here. And similarly if you're downloading something from the internet, then that can get downloaded to this folder, the downloads folder, right? So you have a documents folder; similarly you have a videos folder, a music folder. So all these files or folders will be stored in some place, right? So they will be stored in your /home/edureka. Okay? If you are downloading them and uh, you know, if not, if it's going to be softwares which you're going to install, then you can install them in any other directory here. In fact, most of the softwares that you installed, they'll be by default they'll get installed in this directory, in the bin directory, right? So you have the bin directory, you have the lib directory which will have a list of all the different libraries that the OS would use, and then you have the sbin; you have all these things, right? So they can all be accessed from here, and that's about accessing them from the GUI aspect. Okay? And the same thing can be done through the terminal. Okay? Now uh let me go to my terminal and show you how that is done. So this is my uh terminal. Okay? This is the command line interface where I can put in my commands, and when those commands are executed by the kernel or by the shell, then program will get activated and some kind of features will run, all right.
Okay, guys, uh so before I get started, let me go back to my slide and show you what are the different basic commands that I want to run first of all. Okay? So as you can see, it says Nuts provides a CLI to communicate with the operating system, right? So that was the terminal that I showed you; the CLI is called the terminal, and the CLI is basically, it's better for tasks which cannot be performed with the GUI. You know, uh I showed you the concept of going to different directories and different folders, right? So it was a little tough; I had to go to go through multiple directories. So through the GUI that's one kind of uh, you know, drawback; you'll have to spend a lot of time navigating, but with the CLI it's easier; it's just one command and you can access the directory that you want to; that's the advantage with the CLI. Okay? And this is just one basic example that I'm giving you; there are many more advanced concepts and topics which is not very easy to perform with the help of a GUI. So in those places you can just use the CLI to perform those tasks, and the CLI is also much faster in quite a few ways. Okay? So that's the advantage with the CLI and running the commands. Basically the first and foremost you have the PWD. Okay? Now this stands for print working directory. Okay? And what it does is it displays the current working directory of the terminal. Okay? Then there's this forward slash, and I told you that the forward slash represents the root directory. Okay? Now let me go to the terminal and show you these two things. So uh right now we are in the home directory. Okay? Now let me just type it down; let me just put PWD, and when I put PWD it prints the current working directory. Okay? The presently working directory, so that is home/edureka. Now if I go to the computer and file system and home and inside this address, then what you see here, right? So this is the folder that I'm accessing through my terminal because the present working directory is set to this folder. Okay? Now if I want to, you know, say I want to change the directory, it means I want to change from this particular folder to a different folder. So there are other options like desktop folder and documents folder, right? If I want to move to one of these folders, then how will I do it using the terminal? So I'm just going to show you how that is done. I just want to minimize this a little bit. Yeah, the command for that is CD space the name of the folder. Supposing I'm going to go to the desktop folder, then I can just put desktop, all right? And when I put enter, then I'm inside this folder. So earlier you had you saw this option, right? So this represents the directory I mean. Okay, I was in fact in the home directory, and right now I am in the desktop directory. So desktop is uh the directory inside home. And if I want to, you know, list down the contents in the desktop, then I can run the ls command. Okay? So when I put LS, it basically lists down the different folders and the different files that are present in that directory. Okay? So we have the eclipse, we have LMS which is a folder, we have readme which is another file, we have all these things. Okay? So let me just go to the desktop folder and show you the same. Okay? We have the terminal, we have the LMS which is a folder, and similarly going back to the terminal, if I want to enter this Linux folder, then I can again uh, you know, just say CD and space LMS. Okay? When I do this, I'm inside this folder. Okay? Now if I put LS, then I have the list of the folders or documents that are present in this LMS folder. Okay? So uh LS is basically the command to list down the photos or files in that directory, and yeah, CD space the file name or the directory name would move you to that particular directory. Now that is the same thing that I've discussed in this slide here also. Okay? So I spoke about the present working directory which displays the current directory that your terminal is in, and then you have the root directory from where all your directories or folders are marked, right? So everything can be accessed from the root directory. So that is this, and then you have something called as the echo command; you have the su and the sudo commands. Okay? These are something a little advanced, so before I show this, let me show you the clear command; let me explain the clear command. Okay? Now getting back to my uh terminal, when I type clear, the whole uh CLI is cleared, right? My terminal is cleared, so whatever commands I ran previously, those are not present anymore, but what happens is those commands, they don't get deleted or something; they are just scrolled down. So as you can see, they are still present here. So when I scroll down uh what happens is, you know, it just makes sure that the other documents or the other commands that are specified earlier, those are all hidden and um showed something new. So that's what happens here. Okay? So that is this. Now I told you that, you know, by giving CD you can go to the directory or the folder that's in the present working directory, right? But how about going back to the previous directory? So basically from edureka folder to go to desktop, we clicked on this, and then we entered this folder, right? So from this directory by clicking on LMS you go to a different directory, right? So you go in here, but using the GUI you can just click on the cross mark here and you can exit that directory, but how about you're doing that with help of the terminal? How would you do it here? So to do that we have the option called CD space two period marks; period marks or full stop, so that's what we call it, right? Dot. So if you have two dots after CD, this means you want to navigate to the previous directory. So we are currently in the LMS, and when I just enter, and back to the desktop folder, right? The desktop directory. Now again if I give the same command again, then from a desktop I need to go back to this edureka directory, correct? So there we go till this symbol here; it represents that we are in the home directory. Okay? So the home directory is basically uh I can also access the home directory by just giving a CD and enter. Okay? That I can do it from any other directory. So let's say I am just doing an LS and I'm changing directory to uh downloads. Okay? d-o-w-n-l-o-a-d-s. Okay? So just you gotta remember to give the exact name of the folder or the directory that you want to travel to; so only then it will work; otherwise if you just give dow it won't really work. Okay? So after this if you give enter, then you go to the downloads uh folder, and uh do we have anything inside downloads? No, we don't have any other folder or directory under download. So now let's try going to the home directory from here straight away. Okay? So I initially told you that by having two period marks after uh, you know, a CD you go to the previous directory in that path, right? So instead of that if I uh just give a CD, okay? And if I give enter, then I'll straight away go to the home directory, and this with respect to any directory; no matter in which directory I am in. So if I just give CD, then we'll go to the home directory. Okay? So that's what the benefit with the CD command is; you can give CD to move to any directory. Okay? So I have a question here from Shashikant, and Shashikant is asking me uh should we have to do CD and LS every time? It seems a little complicated. So Shashikant, you don't need to really do that because uh I was just about to get to that point. Okay? If you want to go to a different directory or a different folder, you don't need to give a CD and LS every time. Okay? So LS is basically only for you to figure out or understand what are the different directories inside a particular directory. Okay? So if I know the path, then I can just feed it right away in one command and enter that directory. Now let's say I am currently in the CD directory. So this is uh CD; so this is my home directory. Okay? Now if I click on desktop and if I click on LMS and then you have another folder here. Okay? You have hbase. Okay? Now supposing I want to go to any of these uh directories from my terminal, then I don't have to, you know, put CD three different times and uh followed by LS and then go to those directories; I can just uh justify this thing in just one command. So what I'm going to do is I'm going to say CD space or since right now we are in the home directory, I need to give desktop. Okay? Now one more thing which I want to show you people is there's this option of a tab on your keyboard, right? When you give tab, then the command here will be autofilled, right? The option will be autofilled. So uh let me explain that again. So I'm just going to go back. So in the your home directory, right? So you have different options; you have desktop and documents. So what I'm going to show you is by clicking on CD and space and then if I just type three or four characters of desk. Okay? I want to go to this directory, but I've just typed dsk. Okay? Now if I click on Tab, then the remaining uh characters of that particular option is already uh filled. Okay? It gets autofilled. So that is what the tab would do; by clicking on tab it'll get autofilled. So similarly under desktop you have the option of LMS, right? So I'll just put l, and if I press tab, the remaining will get autofilled, correct? And inside the LMS you have different directories; we saw that we have hbase, we have Hive, and all these things. So let me go there and show you what are the different directories that are there. So we have hbase, Hive, map reduce, and Uzi. Okay? Now uh let's go to the terminal again. Supposing I want to go to Uzi directory. Okay? Now when I just click on capital O and if I click on Tab, then it kind of autofills the directory. Okay? But in case, let's take the example of Hive or hbase over here. Okay? Now since both start with h, I'm going to type h, and if I click on Tab that doesn't work. Okay? It gives me further options of hbase and Hive. So that is because there are more than one options for uh, you know, starting with h, right? There are more than one folders or directories that start with h, so that's why you're getting further options; that's why it's not autofilling. But if you see the second character here is B, and the second character here is I. So if you either give B, and now if you press tab, then hbase is what is going to be picked up. Okay? Because uh after hnb there's only the only option is uh of hbase; there's no other folder that has HB as the first letters of the name. So so similarly if I just type hi and if I do tab, then Hive gets autofilled. So things like that. So since our mission was to go to the hbase directory, I'm just gonna say hbase. Okay? Now inside the hbase I want to go to one of the directories in here. So let's say we go to Advanced hbase practicals. Okay? Now for that if you want to go there, then you just got to give this. Okay? So this is your complete path to access that particular folder, and when I give enter, then I am in the advanced hbase practicals module 9. Okay? So I'm in this particular folder or this particular directory. So that is what you can do with the help of feeding a path after cd. So now if I want to go back to my home directory, I'm just going to click on CD and put enter. Okay? So that is this. Now let me go back to my slides; I'm just gonna close all these uh folders. Okay? Now going back to my slides, actually the print working directory command and actually the root directory and I'll show you the clear. Okay? So the echo and the sudo commands are something that I did not show you, but I also spoke about the ls and the CD commands, right? So what I'm going to do is uh before I go into details of CD and LS, right? I'm gonna just show you the echo command and the sudo user. Okay? Now going back to my terminal, the echo command, right? So what is uh the echo command? So uh what is the echo command? Echo command is something that writes its arguments to standard output. So when we say arguments, it means whatever we type after uh echo, we'll type echo space and followed by that whatever we write, so that will be specified to standard output, and when we say standard output, it is the output that will be displayed by the CLI. So in your terminal whatever output you get, so we'll get specified to that particular standard output. Okay? Now let me show you a practical example; only then you will be able to understand that. So let's just clear the screen. So another shortcut to clear the screen is Ctrl+L. Okay? If not, you can just give the clear command like this. Okay? This will clear your screen; otherwise you can just give Control+L, which will again uh, you know, just clear the screen; it's a keyboard shortcut. Okay? So I told you that I was talking about the echo command. So when I say echo and if I give enter, then there is nothing that is displayed, but if I say echo and say hi
See what the output came. So when we executed this command, this was the output that came back. It says hi. And if I say "Echo hi my name is uh Vardhan," when I say this, then whatever was specified as arguments, right? So this was basically specified as arguments to this command. So the argument is specified as the output. This is the takeaway from the definition. So the definition was basically that whatever the argument is that is specified to standard output, so that's what it happens; so that's what comes here. So this is one thing, and in fact, there's another functionality also. Now, uh, we were all aware of the concept of variables, right? So we can assign some kind of value to a variable, and we can also print that with the help of the echo command.
Now let's say that we have a variable X, okay, and let's give it a value 100, okay. So now if I uh just say "Echo $X," then the value that is stored in this variable, right, that we printed, uh, because uh "Echo" is something that's just going to print the argument to standard output, okay, it will display the value that is present over here. So if it's just a string, then that will be printed, and if it's a variable that I'm specifying, then even that will be printed. So the difference between the variable and string is this dollar, okay. Now if I just give "echo $X," then I've set the 100 value to X, right? So that 100 will be printed here. So like I told you how it is printed, but uh the same thing if I give "echo X" without the dollar, then see what's printed: it is X, which is printed. So that is the difference between the string and a variable, okay. So you can, you know, have again a variable uh called "name," or you can have a variable called "Warden," and you can store the value of 10, okay. But if you want the value to be displayed, then you gotta append a dollar before the variable name, okay. So that is about the echo command, and in fact, there are a lot of advantages with this command, and I will talk about the other features and the other places where this is used later during the session. But uh, till then, this kind of introduction is enough for now, okay.
So going back to the slides, what else do I have? Uh, okay, so we have the "su" command, correct? So as it says, "su" is used to switch to the root user, okay, uh, so that superuser permissions can be used to execute commands, all right. And then you have "su username," used to switch to a different user. And then you have the "sudo" command, which executes only that particular command with the root or superuser privileges. Now these three, what they essentially mean is that you get more permissions. So if I go back to my terminal, so if you guys remember, then I logged into CentOS with the edureka user, right? So that is displayed here also. So it says "edureka@localhost," right? So uh, this is the username of this account, and similarly, you have something called as the root user, okay. This is my user, and then you have the root user, and what the root user is is the root user gives you a lot of permission. So that's like the ultimate uh superuser of this particular system. So basically, if there is any folder that cannot be accessed uh by my user, okay, my username is edureka, and if I do not have the permissions to access that particular directory or that particular folder, then we can use the root user because root has the ultimate privileges. So any command that is executed with the root user, then that will be executed, okay, so because root has all the privileges, it has all the permissions. So that's what the root user is, and uh, you know, there are certain uh functionalities which need the "su" user or the root users' uh permission, and I will show you all those things later. But for now, what you need to understand is by just giving "su," then you can switch to the root user, okay, and it asks the password; of course, you got to know what is the password for your root user. And when you give the password, you will be logged in as a root user. So you are not at edureka anymore, okay. And as you can see here, you are "root@localhost." So this is the hostname, and this is my uh username, okay, root. So earlier you might have noticed that there was a dollar symbol, okay, but now it is a hash. So this basically this hashtag represents that we are inside the root user, and we are accessing their, you know, executing commands as a root user. So that's what it means. And if you want to get out or exit the root user, then you can just type "exit" and give enter. So now you're back as yourself. Now we are going to be executing commands as at edureka user, okay.
And uh another thing that you can do is if you have multiple users, okay, and if you want to switch to one of the other users, then you can also give the "su" command and and go to switch to the user. Supposing the username is, let's say, "ABC" is the username, then I can just give "su ABC," okay. Now since I don't have any user uh, you know, a user account called "ABC," it will probably throw me an error or tell me that it does not exist, okay. But the point that you need to notice is that if you have any user, then you can just switch to that user from the terminal by using the "su" command. Okay, "su" space the name of the user account. So again, uh, later during the session there's a topic about creating and deleting users, so at that time I will show you how you can switch to another user from the terminal, okay. So let's park it first for later because it's a little complicated if I tell you that right now. So uh, I think I've covered pretty much uh everything about "su," and there's one other command called "sudo," okay. So "sudo" basically lets you execute a particular command as a root user. So when I give "sudo ls," then what happens is this particular command, "ls" command, which will list down all the other directories or folders in the current working directory, right? So this would be executed as a root user, okay. So uh, similarly, so earlier I excluded the "su" command and I gave a password for that. The difference between the two is that with the help of "sudo," then only that particular command will be executed as a root user, but whereas with "su," then the entire set of commands after that will be executed as the root user, as you will be logged in as a root user itself. So let me just show it to you again. So this was the "ls" command which I executed as a pseudo user, okay, as a pseudo user order as a root user. But if I just give "su" and if I give the password, then I enter, and I can enter the same details, okay, I can put the same command "ls" as a root user. So basically, the kind of results I get will be the same, okay, but just the difference is that the user that will be executing that particular command. So I hope this clears your doubt, okay. So I'm just gonna say "exit" and clear the screen, and if I go back to my slides, I'll just read out the definition. So "sudo" basically executes only that particular command with the root or the superuser privileges, okay. And when you give "sudo username," you can switch to a different user. And when you give "su," you can switch to the root user. So that's what I showed you, the differences between the three. You first give "su," and then it'll ask you for the password. You specify the password, and then you'll be logged in as a root user, and then you can execute your comma as you can execute any number of commands you want to, and then you can exit that particular root access and then come, come out of it. And if you want to execute another command with the root permission, okay, and if it's just one command which you want to execute, then you can just give "sudo," and then you can put your command there, right? So I will uh, you know, talk about these things later, but for now, what you need to understand is the basics, and these are the basics, okay: the "pwd," the "echo," the "su" commands, because all these things come in handy when you go to the advanced concepts.
Going on to the next slide, we have the "ls" commands here, okay. I showed you one command, that is what happens when you just put the "ls" command. So now there are different options that you can use along with the "ls," right? So basically, "ls" stands for listing all the contents in the current working directory, okay. And uh, if I go back to my slides, right now we are in the home directory, and if I give "ls" here, it will list down all the directories that are present in my home directory, okay. So let me just clear the screen and execute that again: "ls." So right now we have "desktop," "downloads," and "music." So these three are some folders. We have "documents" with another folder; all these things are folders, and these are documents, okay, documents and files. So these are the directories or folders; these are the documents or files. So this is what you get when you execute the "ls" command. Now if you go to the slides, then you will notice that you have certain options that you can type along with the "ls." So when you say "ls path," then you can, you know, probably list down the list of contents that is there in that particular path, okay. Let me go back to the terminal. If I say "ls," and if I say the path where I want to list the contents, okay, right now I might be in the home directory, okay, but what if I want to list down the contents that are present in the desktop directory? Then at that time I can use "ls path." So what I'll do is uh, I can just put "desktop," okay, and inside "desktop" there are many other folders. If you remember, there was one folder called "LMS." So if I put "LMS," okay, this is the path, right? So I have given "ls" followed by the path "desktop/LMS." Now if I give enter, then the folders or the directories are to be present in this particular directory or this folder will be displayed to me; that is "hbase," "hive," "mapreduce," "Uzi," and "ping." So that is what "ls" and "path" does.
Now if you go to the slides, there are other options, right? So these options, they can be also referred to as flags. So uh, there is a hyphen followed by one letter character, okay. There's one character here that is "l," there is a character called "a," there's another character "s." So all these are called options, or they're also called as flags. We refer to them as "l" flag or "a" flag or "s" flag, all these things, okay. Now if you give the "l" flag, what happens is it lists down all the contents similar to uh just giving "ls," but along with its owner settings, its permissions, and the timestamp. So when we say owner settings, permissions, and timestamp, it is with respect to the particular folder inside that directory. So let me show you an example of that. So by giving "ls," you have all the different folders that are present in this root directory, okay. Now if I give "ls -l," so the same directories or same documents are listed down here, but we have additional options here, right? So we have additional information. So these are the set of permissions that a particular user has. We have different, we have username, and we have the hostname. We have the memory size, we have the date, the timestamp, and all these things followed by the name of the file. So if you see "desktop," "desktop" is something it was created on this day, and this is the size of it, and all these things, okay. So this is called the long format. I will explain each of these permissions and what each of these stats for, what one stands for, what is uh "edureka" here, and what is here. I'll explain all these things in some more time because before I explain those things, there are other commands which I want to show with respect to "ls," right? So in "ls," other than "ls -l," you have "ls -a," you have "ls -s," okay. Let's see what happens when we give the "a" flag. It should ideally show you the list of all the hidden contents in the specified directory, okay. And then if it's uh, if you're using the "s" flag, then list down all the contents in that directory along with its owner, correct? So let's try executing "ls -a" first. So when we give "a," all the hidden directories also should be displayed. So as you can see, these were the other folders which were not visible when I gave just "ls," because "ls" just shows the list of contents that are available in the GUI, right? So in the GUI, if you go to network and if you go to desktop from the GUI aspect, you only get to see these, okay. So these are the regular files which are not hidden, but of course, there are going to be many hidden, and those can be accessed by uh the terminal by giving the "ls -a" command. Okay. So that is what this uh helped in doing. Now if I give "ls," and if I use the "s" flag, now see what happens: you have the author also. So instead of having the username and the hostname here, you have the author of that particular document. So if this is the particular folder or file or a document, then who is the author for that? It is edureka because I am the user, right? So the author name will be present over here followed by the size and the timestamp it was created and all these things, and we get the list of contents for all the directories or folders which are present in that particular directory. So that's what "ls" does, okay.
So guys, uh, that is about the "s" flag, and in case we want to use a combination of these flags, then even that is possible. So I showed you earlier that there is this "ls -l" flag and then there is "ls -a" flag, right? So "-a" uh displays all the hidden contents in that directory. So let me use a combination of them. So let me say "ls -la." Since there are two flags which I want to use, then I'm just going to use one hyphen symbol for two different flags. So when I do this, then all the hidden contents will also be displayed along with their extended long format, okay. So uh, those are the different folders or directories which are present in this home directory of mine, okay. So that is the combination of "ls -l" and "ls -a." So we saw a combination, and again, so similarly, if I instead of those flags if I use the "-s" flag, then it will sort that entire list by the size, okay. And let me show you an example of that. So we use the "ls -l" right now. If I use "s" over here, it will sort this entire list of directories with the size; the higher the, the follow the larger size will be on top, and the one with the smallest size will be at the bottom. So as you can see here, it was all jumbled; it was uh, this is basically the size block, right? So this is basically for the size block here. If you see the previous time and I just ran "ls -la," then it was in a different order. But since I ran "ls -laS," this has sorted the result in as per the size of the blocks of the folders; the folder with the highest size is displayed first, and the one with the lowest displayed last. So that is about the "ls -s." So there is one more command that I want to show you which can be executed with the help of "ls" command, okay. We executed the "ls -laS" flags, right? So we executed this one previously. Now what if you want to store these details? So whatever the output here was, if you want to store it into another file, how would you do that? We have an option for that, okay, and that is this symbol, greater than symbol, okay. It's called the direction flag, input/output direction flag. And by using this flag, whatever the result or the output of the command that comes right prior to this symbol, those will be stored in the file that precedes this symbol. So let's say that, you know, I want to create a new file. I'm going to create that, okay. I'm currently in the home directory, right? So let's not execute it here. What I'm going to say is uh, let me first change directory to "documents," okay. Now in here, of course, uh, I don't think there are any uh hidden documents either, so there are no folders here. So what I'm going to do is uh "ls -laS," okay, and I'm going to run the uh this command at the home address directory, okay. I'm gonna basically run the same "ls." So basically, the same results I will run them by specifying this uh directory, and I will be storing this file inside my new file, okay. Now let me name that file "file1.txt," okay. Now uh, the reason I moved to uh this directory is because I can store the file in this directory, okay. Had I not moved to this directory and had I just executed this "ls -laS" followed by uh this direction, then what would have happened is it would have just created this new file in my the home directory itself, okay. So if I give an enter here, there's a new file that would have been created under my "documents" directory, okay. Now when I run "ls" inside "documents," there was no folder, but now let's run "ls." So now you can see that there's a new file that's created, and that is called "file1.txt." Now that is because I uh used this uh direction symbol, nothing but the greater than symbol, and when I do this, whatever result that gets generated from this command, right from these options on these flags, those would be stored in a new file, and the file name needs to be specified over here, okay. So that was the wrong command that I used; it's not "ls." So uh, what I need to do is let me just view that file, okay. So to view this particular file or any file, we have to use the "vi" editor, or we have to use a "gedit" editor, or we can use the "cat" command, okay. Now the most common one is the "vi" editor. So let's just execute the "vi" and open this file from here, okay. And the reason that this "ls.file" did not execute was because it lists down the files, right, and this is a wrong usage. I did a mistake by specifying "ls" and by not giving a directory. So I've used "vi" instead; so that's why that did not come. But anyways, if I give "vi" and filename, then that file opens, right? So the file which I created, and this file has the output that was displayed earlier, okay. So basically, whatever was generated by the "ls -laS" flags of "ls," so that result, instead of coming in the terminal, it got stored in a different file, okay. Now uh, let's just exit this "vi" file and explain the same thing. So what you saw inside this file "file1.txt," the content is the same as this one, okay. So we run the same command "ls -laS," but it is that instead of getting the output in the terminal, we gave a direction command over here to uh save it in a different file, and we stored this file in the home edureka directory, okay. Now supposing if I want to store this file in the same directory, then even that can be done, okay; it's not a big deal. So this is the command, right? So if I remove the path over here, then what happens is whatever the output gets that gets generated from this option and this command, that will be stored in the "file1.txt" inside my home directory, okay. If I'm inside the "documents" directory actually, right? So let me just go back one path. So right now I am inside the home directory, right? So here if I execute that command, okay, then a new file will be created with the name "file1.txt," and it will have the same details. So um, I've done that, and uh, let's see what are the contents of that file, okay. So it's nice, right? So you can uh, in this way, whatever output that you have that you can directly store it into another file. So it's a very...
handy uh command and very handy option, and I'll talk about more such advantages like this later. Okay, so for now, I just wanted to show you how the direction works. So uh, getting back to my slides, I think I've shown you how to work with the ls command, and in the previous slide, I showed you the basic commands with respect to present working directory and clear directory, and the sudo and the echo commands. So I've done with ls also, and now I'm going to show you how to work with the CD directory. Some of the CD directories I showed you earlier; also, I showed you how to switch to a new directory. So when you type CD, it will just change the directory to the home directory. Okay, so the /home/editoraker. Okay, now that is my home directory; my home directory is set to that path. So if I go CD, it will go to that particular home directory. And similarly, if I uh, you know, give even CD and space tilde symbol, as you can see here, then even this command will change the directory to the home directory. Okay, but however, if you give a CD space just /, this will change it to the root directory. So change the current directory to the root directory. That is because the forward slash here, it represents the root. I told you this a number of times earlier. Okay, and if there's any other path or any other folder which you want to move to, then you start from the root; so you specify the absolute address, right? You start from the root, you say /, and then you put the folder name, you again say /, and then you put the next folder name. So uh, it is similar to that; the first forward slash represents the root directory, and the subsequence slashes are to differentiate between the different parent and the sub directories. So that's what they are. So this will change you to the root directory, and then you have the CD hyphen .. Okay, two period symbols. And when you give CD space ., right? If you give two dots, CD space .., then we'll change to Parent Directory. So supposing I'm inside the desktop directory, so desktop's parent is home directory, right? So it will change me to the home directory. But supposing if I was inside, let's say the uh, if I'm inside a directory called dietary C, and if C's parent OSB, then by running CD space .. from the C directory, then it will switch me to the Parent Directory, which is B. So that's what this does. And then we have one more command here, that is CD within single quotation marks, we have some kind of path. Now this is useful at times when your folder name or your directory name has two words. Okay, so if you have two words, then if you have a space in between, then the space will be considered as an argument. Okay, so terminal will consider that as an argument. So if you want to switch to a document in that kind of a situation, you know, or if you want to switch to a directory which has a space or a document which has a space in the middle, so in that kind of situation, you can use a single quotation mark or double quotation mark. Okay, so it's uh, you know, you also have the comfort to switch to double quotation marks. So I'll exclude all these things and show you. Okay, so first I'll show you the uh, the CD ~ then with the forward slash, then with the . mark. This of course I showed you earlier also, and then I'll show you how to switch to another folder with, you know, which is having two different names with a space in the middle. So going back to my root, so right now we are inside the home directory itself. So if I give a CD - desktop. Okay, now in here we have my other directories, and if I do CD and LMS, I'm inside the LMS directory. Okay, now from here if I go CD and if I give use the ~ option, right, then it will switch me to the root directory. So see this was the ~ symbol earlier. Okay, so this utility symbol represents a root, and since I said change directory to ~, this which implies the root, it basically uh decodes it as a change directory to the root directory. So when I did that, I have automatically switched to root directory while earlier it was LMS. So similarly, if you are in the LMS directory and if you also just press CD, right? If you just give this command, even this will switch you to the root directory. So basically a CD and CD space ~, they are both the same. But however, if you give CD with forward slash, then it will switch you to the root directory. So when I give enter, as you can see, see I am in the root directory. So if I give ls over here, I have a list of other directories which I showed you earlier. So in in your file system, right? So yeah, so inside your file system if you open this folder, then you have the root directory. So inside this directory you have home and network, and this is where desktop and documents are all present as a subdirectory of this Parent Directory. Okay, so this is the root directory where everything is stored. So any document or any folder in your Linux operating system, they can be referred or they can be accessed from this root directory. Okay, now going back to the terminal, let me show you an example of that. I've already moved to the root directory. Now let me say a CD bin and uh, okay, we have this. So now when I uh give CD space bin, then it moved me to the bin folder inside my root directory. So I ran the root; actually, I did an ls, which listed down the list of uh folders inside my root directory. These were the options uh, bin, boot, dev; these are all the different folders. And when I said change directory to bin, it uh shifted me or it moved me to this particular folder okay, inside the root directory. So right now I am in the bin directory, and inside the bin directory I ran the ls command, which basically uh means listing down all the contents, whether it's documents or whether it's folders or directories, all those will be listed down. Okay, so these are the list of all those uh contents in the uh bin directory. Okay, now that we're in bin, let me go back to my root directory by giving .. Okay, so from bin it again I go back to my uh root directory. Okay, so this / represents root directory like I told you earlier, and if I do ls, then I am back to this directory where we have bin, boot, dev, and etc, home and all these things. So now what I'm going to do is uh, so now that I'm in the root directory, now let me say change directory to home, and inside home there is erica. I want to go to erica. Inside edureka, let's go to desktop, and then there is LMS. Okay, and uh in here if I do ls, then these are the list of folders here. Okay, now I'm going to change directory to hbase, and if I do an ls over here, then you can see that there is one particular folder called Advanced Hbase Practicals Module 9. Okay, if I now just say CD and if I put ADV space hbase, then I will not be able to autofill the option. Okay, that's because the terminal or the CLI is not able to recognize this particular command because there's a space over here. Okay, so it reads ADV as a separate folder, but since it's not able to find any folder here as ADV, that is the problem. Okay, let me show you where the GUI what it looks like. So we are in the desktop, and inside LMS we have hbase, inside hbase we have advanced hbase practical. So this was what I was talking about, this particular folder, correct? So let me minimize this for you. Okay, now this is a classic situation of when you need to use double quotation mark or single quotation mark. Okay, now if I just put the same name uh, like say ADV and hbase, then it can autofills automatically, right? So even the quotation mark ends over here, so that indicates that this is another folder that's present. So if I uh, you know, just put enter, then it will change my directory to this particular folder. So that is what the quotation mark does. So when I do enter, then I'm inside this folder. When I do ls, I have the list of photos and directories inside this Advanced Database Practicals folder. All right guys, so I'm just going to do a CD to my home directory, and I'm here, and that was about the different uh CD commands that are available which I want to show you. Okay, so let me just go back to my slides now and go to the next slide. I showed you all the uh different commands here. Okay, so the next set of commands that I'm going to talk about are those of cat, grep, sort, and pipe commands. Okay, so uh let's first go to the next slide and start off with cat command. Okay, so when would we use the cat command, guys? So it's pretty obvious, right, from what it's written here; it says when you're working with files, that time you can use the cat command. So uh, the cat command, it is basically used to display the content of the text files and concatenate several files into one. So uh, what this means is if I have a particular uh, you know, I have a text file. So earlier we created one text file having all the file permissions, right? So if I have that kind of a text file and if I want to uh display the content of that text file, then I can use the cat command. I can say cat, and if I give the file name, then that content will be displayed. So when I use only the cat command with one file name, it's very similar to how the vi uh command works or how the nano command works, right? So it will display the content in the terminal itself, correct? But the difference with cat command is that with cat I can list down the contents of multiple files. So it's not just one; okay, I can have I can even display I can specify three different file names, and if I put enter, then the content of all the three files will be displayed in my terminal. The same thing won't happen with vi. So if I say vi, then only that particular file's content will be displayed. Same thing with nano, right? So uh, let me just go to the terminal and show you an example of the cat command. So right now we are in the CD directory. Let me just maximize this. Okay, I'm gonna clear the screen. Present working directory is the home/regard directory. This is the home directory, and from here let me go to uh documents. Okay, if I do an ls, there is this file1.txt which I created earlier, correct? So this was where the different file permissions were present, right? So if I do cat - file name and if I give enter, then I get the list of the contents of that particular file. So in that file there are only uh these three rows because this was the latest updated permissions that I uh specified in the filemon.exe. Okay, so guys, I earlier told you that you can enter uh details to a file by uh using the direction Command, right? So that was the greater than symbol. So I'm going to use that kind of a symbol over here, and I'll create a new file by adding details by using that command. Okay, initially it was I used the ls -l, but this time I'll use the cat command itself and uh say I'm going to give the Direction symbol here, and I've done with that. Let me give the name of the new file, let's say file2.txt. Now when I hit enter, the command is not executed completely. Okay, so I'm inside this place where I can enter the text. So it's basically going to create a new file. Okay, now whatever text I enter here, that will be stored inside this file. So uh, let's say hi my name is uh radhan, and effective enter, I can go to the next line, and uh here let's say welcome to Linux tutorial by edureka. Okay, now if I want to uh, you know, just add these two lines to this particular file called filecode.txt, then I can press Ctrl D now. Okay, by pressing Ctrl D, I come back to my uh command line. So what this command basically does is this cat command would have created a new file filecode.txt, and the text that we entered below it, right uh, this will be entered inside this text. So if I do cat file2.txt, then whatever I typed earlier that got saved in this file. Now similarly, if you see the file1.txt, the contents are these. Okay, so this is the contents of this one, and this is the content of this file. Now I told you that with the help of cat command you can display the content of two different files. So let me show you that option. Okay, I'm going to say file1.txt and then I'm going to say file2.txt. So in this way I'm going to basically display two files; cat, I'm going to display file one and file two. When I go enter, first the file one contents will be displayed, and then the file two contents or the lines and file2.txt will be displayed, right? So first these are the permissions that are there in the first file, and then uh this was what was there in the second file. All right guys, now uh this brings us to another important concept of how to append files. So cat basically stands for concatenate, right? So that's the most important option. So if you want to concatenate a particular file with, you know, some kind of lines, then I show you how that is done by creating a new file. What I did was I I created a new file file2.txt, and I concatenated these lines into this particular file. So if I just give cat and if I give file1.txt and if I give >>, okay, so double Direction marks, which is uh nothing but the greater than symbol, okay, we also call it Direction marks. So if you give file1.txt and followed by this if you give file2.txt, then what's going to happen is whatever contents are there in file one, those will get appended or concatenated to this file2.txt. Okay, so in my file1.txt we have these two lines, okay, hi my name is Vardan and welcome to Linux tutorial by edureka, and file one has these three lines. So basically when I uh enter now, there will be a file two in which there'll be extra lines. Okay, so let me uh do a cat file2.txt. So as you can see, initially when I ran my uh cat file2.txt over here, I had only these two lines, right? But now after using the bi-directional symbol, okay, the Direction symbol, what has happened is I have three extra lines. So it says hi my name is vardan, welcome to Linux tutorial, after that I have the permissions which was present in the previous file. Okay, so uh that's what happens here. Okay, in fact it's actually four other lines; thanks for pointing that out. Uh, so Heyman, you know, who's another person on the session, he said that there are four lines in the file1.txt; actually he's correct, so total eight. So this is the first line, and these are the other three lines uh, so you can also see that from uh here. Okay, so the first time when I ran cat file1.txt, right, I first got total 8; this was the first line, and after that I got the permissions. Okay, so this is the first line, and then you have the list of the other contents. So when we ran the ls -l, the total number of entries were right, so that was what uh the total 8 stands for. So these are the four lines that got appended to my file2.txt. Okay, but however, there won't be any changes to my file1.txt because I didn't make any changes there. So let me anyway show you that also. If you see here again, the contents here are the same; it's only that the file two has got these four lines extra. So that is what the Direction symbol does. So these are the advantages with the uh cat command. All right, right, so what I'm going to do now is let me go back to my slides and show you some more options. Okay, so we have flags like we have the -b flag, the -n flag, -s flag, and -e flag. Let's see what each of those stand for. Okay, so when we use the -b flag, it's going to add line numbers to the non-blank lines. Okay, so whichever line there is some text, so those lines are going to be numbered. Okay, and when you say -n, then it is used to add line numbers to all lines; it doesn't matter if it's blank lines or non-blank lines; it's just gonna add numbers everywhere, line numbers. Okay, and when you give the -s flag, it is uh basically to squeeze all the blank lines. Supposing you have three blank lines one after the other, then it will squeeze all those blank lines and it will reduce it. Okay, so that's what the -s does. And then the -e flag is uh going to show you a $ at the end of each line. So let me go back to my terminal and show you this option. So first of all, let's see the cat file2.txt, and let me use the flag -n. So this will list the number of lines, right? So there are basically four lines from file one, and these were the two names that are earlier present. So these are the six lines in total we have in this file2.txt. Okay, let me just clear the screen because it's a little uh tough to see everything, right? So yeah, so when I ran the -n command, the file2.txt, the lines in there were numbered. Okay, one to six uh, and then we have another uh flag called -b flag, right? -b flag will add numbers to also the non-blank lines, so but for that we need to first have blank lines over here. So what we'll do is uh I'm gonna do a cat and do this and file2.txt. So when I do this, I'll be adding uh lines to this file2.txt. Okay, I'll be appending lines over here. So let me just give one blank line, enter, some random text, and then enter, you know, blank line, and then random text. Okay, so this is what I'm going to just enter or append to my file2.txt. Okay, you press Ctrl D to exit this, and now these would have been saved to my file2.txt. So let me just run the same command again. Oh, sorry, I should have ran this cat file2.txt. Okay, when I do this, as you can see, uh it starts from here, and these are the other lines that were appended. Okay, and now if I use the cat -b flag, okay, see what happens; only the non-blank lines are numbered, right? So these lines are not numbered, but if I use the -n which I used earlier, what it would do is it will number each and every line. So that's the difference between -b and the -n flag. Okay, so -n numbers all the lines irrespective of it being empty or not, but whereas -b numbers only lines which are non-blank. Okay, so that is uh this one, and there is another flag which is the uh -s flag. Okay, so it's not capital S; it is a small s, right? So when I say -s, then you get the list of the documents. So as you can see here, all the uh spaces are squeezed into one; seems like there were no multiple spaces, right? No multiple blank lines. So what we'll do is let's edit the file2.txt again. Okay, or in fact let me open it via the uh vi editor. Okay, so when I do this, these are the uh existing ones. So when you uh press insert or when you press I button or insert button, you can start entering text details inside this file. Okay, now uh right now I'm here; let me add multiple blank lines here. Okay, so as you can see, there are around uh three blank lines, or one, two, three, four; there are four blank lines, and here there are three blank lines. Okay, now uh let me press Escape. Okay, now if I give Escape, okay, so now we are in insert mode. So what I do is uh I'm gonna press escape and then followed by that if you give :wq, this would save this file. Okay, so
I've made changes, right? I've added lines here so it would save those changes and it would quit the vi editor mode. So if I give enter, I'm outside that file. So now, if you see the cat file uh two dot txt, then it has additional lines, right? So uh now I'm gonna run the command that I ran earlier: cat hyphen flag s and then the file name. When I do this, all the uh multiple blank lines are squeezed into one. So as you can see here, there have been multiple lines here when I ran the file 2.txt, but here when I ran the cat hyphen with the yes flag, then all these multiple blank lines are squeezed into one. Okay, and so that is uh the option with the cat command. Okay, so I think with that, I think I've covered all the different options. Okay, there is one left; there is uh the minus E option, right? So okay, now let me show you what that does.
So when we use the capital E flag, okay, there's a dollar sign that is appended after every line. So uh the first line is total eight, or let's say the first sign is this one; so there's a dollar sign here, and after this line there's a dollar sign, after this there's a dollar sign, and uh since you have blank lines, you'll only find the dollar sign here and again after this one you have a dollar sign, and uh you know, blank lines have dollar signs, and yeah, so that's how the e-flag works. Okay, so every line's end is uh appended with the dollar symbol. Okay, so with this, I'm done with all the chat commands. So going back to my slides now, let's go to the uh next command, that is grep.
Okay, so uh grep command, working with the grep command. So what does the grep command do? You guys have any idea? Okay, well I don't expect you people to, but uh yeah, so if people, if any of you know, if you have an introduction to Linux, then you can answer it, but it's fine if you don't, because I'm going to explain that; it's my duty. The grep command is basically used to search for a particular string or a word in a text file, right? We have a file document like the one which we created now, like we have two documents like file one.exe and file2.txt, and what if you want to search for a particular string, right, or a particular word? So in this case it's pretty simple because you can easily find them, but what if you want to do it to uh, you know, a very big file document which has like millions of lines, right? So supposing you have any document, then you'll have multiple lines, right? And if you want to find one particular word or if you want to go to one particular string, then how will you do it? So in Windows you have the control F option, right, but via a CLI you can't use it, right? So via CLI you use the grep command. Okay, and the format for executing the command is this: you specify grep, and then you specify the string that you want to search for, so options, the string that I have searched in this command, and then the file name. Okay, and this will return the result of the matching string option. It's so similarly, if you use the I flag, then it will return the results for even case-insensitive strings. So basically, if you do not use the I flag, then it is uh case-sensitive, right? So it will only search for options with these letters, but if there is a word called options with a capital O where the first letter is capitalized, then in that case, only when you use I will even that particular result be uh shown. Okay, so that is the advantage with the I flag.
And then you have the N flag, which is the grep hyphen n, which will again return the matching strings along with the line number; in which line was that string or that word found? So that's what n does. And when you give minus V flag, then what happens is uh you will not be shown the list of lines where the results were present, but instead you will be shown the list of lines where the results were not found, where there was no matching string, right? So those lines will be printed with the help of the V flag. And then with the c flag, it returns the number of lines in which the results matched the search string. So supposing you have like four words, okay, you have a big document, and uh your word, your string matched four times, then uh if you use the minus C flag, then it will display the number four instead of displaying the search string. Okay, so let me go to the uh VM, let me go to my uh CentOS and uh show you how to execute these commands.
Okay, so right now we are in the documents folder. If I want to execute that, then we need to edit this in a different way. Okay, we need to have a different text, and this directory has uh these documents, right? So let me just quickly go to the documents folder, and here if I do an LS, we have the two files which we created: we have file2.txt and file1.txt. So what I'm going to do is uh I'm gonna see what's there in file one dot txt. Okay, so let me edit this file, okay, or let's say let's just create a new file. What do you say? We can create a new file by uh doing this, right, by giving the Direction symbol followed by the name of the file. Let's say automobiles, Auto mobiles; this is the name of my uh file automobile.txt, and I can start listing down the automobiles that I want. So let's say car, or let's say motorbikes. Okay, we can say train; well, train is technically not an automobile, but uh still, or let's uh go into details of the companies. Okay, let's say Maruti, let's say Ferrari, Lamborghini; these are some of the most famous companies, right? So when it comes to bikes, you have Yamaha, then you have uh Honda, right? You have Suzuki, you have Aprilia, and uh name a few more; we can add some more companies like BMW, you can add Audi, we can add Volkswagen to this list. Okay, now if I do Ctrl D, then this will be the list of content in my automobiles.txt. Okay, let me—I'm going to clear the screen now, and if I do the cat command here, then it displays a list of contents here, right? Okay, now let's use the grep command to search the content that is present in this text. So I'm going to do a grep, and uh the string that I want to search for is uh let's say am, because in Lamborghini we have the search string am, and even in Yamaha we have the EM, right? We are supposed to get two results for this, so in this case, so if I uh just say grep jam and if I specify the file name automobiles.txt and if I go enter, then I get the two different words, right, the two names where this was present, where am was present. Okay, now if I use the same thing with the uh I flag, then it will uh display the list of files in a case-insensitive fashion, but in my file there's no uppercase file. I'm going to say say automobiles.exe; I'm going to append, I'm going to append this word called Amber. Okay, so Amber is another automobile company, and when I do this and if I run the cat command now, okay, you will see that along with these names it was there initially; there's Amber has been appended. Okay, and this time when I searched for JM, right, so it should not show me this because even though there is am here, uh the A is capital here, but I'm searching for uh small a, so it should not show me this result. Okay, I should get the same result that I got previously. So if I uh do a grep am like earlier, I got the Lamborghini and Yamaha as the only options. Okay, but now if I uh append this with minus I or the I flag, so what happens is I'll get the option of even Amber along with this because it would search for the string in a case-insensitive fashion. Okay, so this time, as you can see, Amber is uh added to this list because uh you did not consider case-insensitive words, letters. Okay, so that is about the I flag, and uh there is another n flag, right? So let's see what the n flag does. So every time you use the minus n flag, then it will list down the line in which the word was present. So that's what I mentioned earlier. So over here, in line number six and line number seven, we have Lamborghini and Yamaha, right? So the line number is measured. Okay, now uh so that's what the N flag does. Okay, so we have the V flag and the C flag left, so let's execute them and see what happens. So when I remove n and when I execute V, as you can see, all the results except for Yamaha and for Lamborghini would be present here. Okay, but if I give minus IB, okay, which indicates IV flag, then even Amber would not be present in the output I will get now. Okay, when I give enter, as you can see, Amber is not present because uh amber is part of the case-insensitive option, right? When we included I, this should be chosen as a search result, and since it's considered as a search result, we will display only the result, uh the set of results which were not found, so the other lines in which text was not found were these, and that's why we got these options. Okay, now we have one more flag which we need to see, and that is the C flag, and when you enter the C flag, then it displays the list of the number of times that string was found. So am was found two times: once in Lamborghini and once in Yamaha, so that's why we got the answer as two. Now if I use C with the combination of I, all right, I'm gonna get three; that's because even Amber will be considered in this case. Okay, guys, so uh this is uh what is uh there with respect to the grep command; I spoke about the grep command. Okay, and now in the next slide, let me talk about the sort command.
Okay, and so we use a sort command to sort the results of a search, either alphabetically or numerically, all right, and uh we can sort either files or file contents or directories. So what this means is uh whatever results you get, right, or I mean not just results, or even if it's the list of items that is present in a particular directory, even when you run an LS command, right, you'll have a list of files and the list of folders that are there in that particular directory, so we can sort even those things. Okay, now that result can be sorted, and also we can sort anything else; we can sort the contents of a file, right? We can sort the contents of the file, or uh you know, all these things. So that's what this means. So without wasting much time, let me just uh show you how that is done. So you can give sort and the file that you want to sort; alternatively, you can also uh sort two files at the same time by giving 501.txt and file2.txt. Okay, so on the, on the syntax for that is a sort and the file name. Okay, when you say sort on the file name, then the contents of this file will be uh returned in the alphabetical order. Okay, if you want to sort two files at the same time, then you can uh in arguments you can just give both the file names, and it will sort the contents for both file1.txt and file2.txt. Okay, and again, if you want to uh display them in the reverse order, then you can specify the r flag, and uh for case-insensitive sorting you can do the hyphen f flag, and then if you want to sort the results based on the number in a numerical order, then you can now use the N flag. Okay, guys, so let me first of all go to my terminal and start executing them. Okay, so what I'm going to do is I'm going to clear my screen, and currently let me just list on the contents of this directory. So we have automobiles uh file, we have file one, and we have a file two. When I just give a sort and press enter, then I enter the interactive mode. Okay, so here I can type all this; I can type random words. Okay, I can say uh JB CD, or I can say bcda, or I can say efedf g, all these things. Okay, and then when I press Ctrl D, it gets me out of the interactive mode, and when I exit the interactive mode, the text that I typed in, right, the input that has been sorted, so this up till this line was what I entered as input if you remember, and uh up till Ed FG, right? So basically this text has been ordered as per alphabetical order, and since a comes first in alphabetical chronology, this is first; the bcda is second, and then you have the other lines. Okay, these have been sorted in an alphabetical uh order. Now if I give sort with the file name, okay, that is uh automobiles.exe, and if I give enter, then this particular file will be ordered in the alphabetical order. Okay, the contents will be listed down in the alphabetical order. Uh let me clear the screen and show that again. So let me first just do a cat and show you how the order is. Okay, now let me run the sort with the file name. Okay, so now if you see it was in this order initially, right? So car was the first option, motorbike was the second, train was the next, Maruti, and then came Ferrari and Lamborghini, but uh if you look at the sorted uh result, then it's in the sorted manner, right? So first comes Amber, then comes Aprilia, then comes Audi, and then the others. So that's what sorting does. Okay, and the same thing can be done for two different files at the same time. So this was the automobiles.txt; supposing I want to list down even my file two contents, then I can just type File 2 dot txt here, and the results of both the files will be in my terminal. Okay, but before that let me just clear the screen so that will be easier for you to view the results. Okay, so now that I've cleared the screen, let me uh sort these two files. Okay, so let's—the command is sort, and this is what I had previously, and let me add file two to it. Okay, file 2.txt. Now what this would do is the results of both these files, right, Automobiles and file two, the results of those would be sorted in the alphabetical manner. Okay, now if I give an enter, as you can see here, first initially you have blank space. Okay, now that is because blanks are ahead of the capital a, right? This is the alphabetical order, correct? So first comes blank space, then comes uh white space, and then comes the characters. So once we are done with those things, then we have Amber, Aprilia, Audi; this was the order in which uh the files were listed in the Automobiles, and right after CD comes. Okay, now this line is part of the file one; well, these are part of automobiles; this was part of file 2.txt. So yeah, these results were a part of the automobiles.txt file; the blank lines here, these were part of the file 2 dot txt, and uh again these two lines, right, these were part of file 2 dot txt. Okay, so this is what happens when you give two files as arguments. Now uh there are other options that I want to show you though. So there were flags like the r flag, right? So the r flag lists the results in the reverse order. Okay, I'm just going to clear the screen, and yeah, for clearing the screen the shortcut is Ctrl L. All right, guys, so let's say sort automobile.txt. Okay, it's cat, right? I don't want to do cat; I want to do sort automobile.txt, and I'm going to use the flag minus r. So when you use minus r, it will display the result in the reverse order. So we have the reverse order in which Yamaha comes first and Amber comes last. So that is the reverse order, and we have another flag here; the other flag is the F flag, which will return the results in uh the case-insensitive fashion. Okay, so that is the minus f, and then if you go back to the slides, there is an n option, right? So n will return the results in the numerical order. Now let me go to my terminal and let me use the N flag now, but of course I don't think it will sort anything because there are no numericals here. So what I'm going to do is I'm going to uh use the file 2.txt here. Okay, file 2.txt. Okay, so there are no numericals here either. What I can do is I can edit these details. So let me go VI and uh save file 2.txt, and I'm going to enter the insert mode; I'm going to remove all these unwanted lines. Okay, so I've removed all the blank lines. Now I'm gonna put one here; I'm gonna put two here; I'm gonna add three to this line; I'm going to add four to this line. Okay, all right, guys, or let's say let's give the order seven here. Okay, you have two here. Okay, so there are some kind of numericals ahead of, you know, before every line starts, right? So when we run the minus n command now, the sort command with the N flag now, then it would sort these lines with respect to the lines with the numerical order. Okay, so first this line would be uh shown, the blank line. Okay, then you would be shown the uh uh you know, the total line, then you would be shown the third line, and like that. So let me just Escape, colon, and save and quit. Okay, now let me run that same sort command: sort hyphen n file2.txt. So as you can see, the alphabets are first sorted. Okay, so the lines where there are text characters or alphabetical letters, so those are displayed, and after that the lines that are formatted after that are in numerical fashion. Okay, so if I don't give the N, it would be a different uh fashion altogether. So earlier uh the file was just displayed in the regular numerical order. Okay, so where one, two, three, four, five, the numbers came first, and then came the text, but since we ran the hyphen n, the alphabetical letters or the characters came first. Okay, after that it was sorted by uh numerical letters. So that's what the N flag does, and that brings us to the end of the sort commands.
Okay, so uh after the sort command, the next one that we have in line is that of the pipe command. Okay, so this is referred to as the pipe. You will find this in your uh you know, keyboards, right, above the enter button, okay, uh where you have the backward slash. So in that button, if you press shift and if you press that button, you will get this pipe command. And what the pipe command helps you do is it lets you perform two operations in the same command; like it'll uh let me search—let's take the example that's specified here. Okay, we are using the grep to search for a particular string from a file, and uh we are using that, and then we are sorting that result. Okay, now since there are two operations involved, okay, one is a sort and one is a search; still, there are two operations involved in the same command; we separate the two operations with the help of the pipe command. So that's what this is, and uh as the definition says, the pipe command is used to output the result of one command as input to another command. Okay, the same thing can be said over here also. So we'll first search the file for a particular string, and whatever result you get, that will be given as input to the sort command over here, right? So this saves us time in not having to mention the file name after sort again. So we'll just be performing one grep search, and then we'll just—whatever result comes, that result will go to the operation that's performed over here, right? So let me just go to the terminal and show you an example of this. I'm going to clear the screen, and uh let's run the grep command to search for am from the automobiles.txt. Okay, I'm going to use the pipe command and sort this. So these were the two results, right? So when you do a cat command or when you do—when you just run the grep command with am, right, so what would happen is you get these two results because these two
Lines or these two words have the same characters inside. Right now, when you give the sort, it would sort it alphabetically. Right, and if I, if I want to sort it in the other way, then I can just run the same command with the r flag. So when I do R, then this result will be sorted in the reverse fashion. So Yamaha comes first and Lamborghini comes first. So that's how the pipe command can be used to get the output from one operation and feed that output as the input to the next operation. Right, so uh, this is relatively uh smaller topic, okay, and we quite often we'd be using uh the pipe command when you want to use multiple uh operations in the same command. So that's about the pipe command. Okay. So let me just clear the screen and get back to my presentation and see what's my next slide all about. Okay.
So now that I've shown you how to sort the contents of the file, let's go to the next slide. Right. So the next section of uh this Linux tutorial is going to be about the copy, move, make directory, remove, remove directory, and the user permissions. All right. So let's get started with this section. Okay. Uh, CP stands for copy, and that will be the first slide that we're gonna talk about. Okay. So as you know, uh, copy is basically used to copy files or directories. Okay. The point—notice files and directories. So in Windows, you have the option of right-clicking on any uh file or any folder and, you know, saying copy or copy-paste or cut-paste. Right, that's in Windows, and you can do that even through the GUI in Linux, but how will you do it through the CLI? Right, through the terminal? You specify this command; you specify CP, and if you have any flag, you enter the flag, and then you specify the source and the destination. Okay. So the source is basically—this will be the path of the folder that you want to copy, and this is the place where you want to copy it to. All right. So uh, let's uh get back to executing and showing you a demonstration of this. So I'm going to go back to my terminal. So uh, first of all, we're in the documents directory, and let's see what is there in this directory. Okay, there are the three files that we created. Right, there is automobiles.txt, there is a file1.txt, and file2.txt. Now what I'm going to do is I'm going to copy the automobile.txt and paste it in my uh desktop. Okay. So let me just minimize this. So this is my desktop. Right. So right now I don't have the automobiles.txt, but through the terminal I'm going to run a command which will copy the automobiles.txt to this folder. Okay. So I'm just gonna minimize the terminal now to show you that it happens okay, real time. So what I'm going to do is uh LS, and I'm going to say copy automobile.txt—this is the source—and the destination is a root home address, and in edureka it's the desktop folder. Right. When I hit enter, there will be a new automobiles.txt file that will be created over here. So as you can see, the new file got created over here, and uh, yeah, so it's a very simple command that you can execute. So you can do the same thing to even directories and files. All right. Uh, so what I'm gonna do is uh I'll go to the home directory, and from the home directory I'm going to go to the desktop directory and copy the LMS folder. Right. So the LMS folder is again uh, you know, it's a folder—this time it's not a file. So last time we copied a file; this time I want to show you how to copy the folder itself. Okay. I'm going to copy this folder and paste it somewhere else. So let me go to the terminal. CD, and I'm gonna go to the desktop here. All right. So we have for LMS here. So I'm going to say copy LMS. All right. So I'm going to remove the slash from here because I'm going to copy this folder now, and this would make it the source; that would make LMS the source, and the destination is—we have to put the absolute path here. Right. So we got to start from the root directory and go to home address, and let's say I'm going to put it in the uh documents directory. Okay. Something that is present in the desktop directory that is uh being copied and pasted inside the documents directory. Okay. So when we give enter… So guys, uh, we're getting an error here. Right. So it says copy CP omitting directory LMS. Can you all guess why that is the case? Can you like understand the meaning of this error? Formatting directory—don't break your sweat too much—because uh the meaning is simple: You're—it just—it has just omitted the directory. Okay. Now the reason is—so that is because uh the CP command, it by default it copies only files. Okay. If you want to copy directories also, then you gotta uh add another flag called R flag. So let me just quickly go to the slides and show you uh the functionality there. Okay. As you can see here, uh we have the r flag. Right. So CP -r, it is for recursive copy, and that's for copying directories also. Okay, and it copies also hidden files, if there are any hidden files, or if you have directories which you want to copy inside that directory, then it will uh it will copy that—that itself. So that is the thing, because you cannot copy your directories without the r flag; you can only copy files. So that is the meaning here. And we have—have another flag here called the V flag, and that is verbose. Well, what verbose means is it prints informative messages. Supposing you are executing a command, okay, and supposing the command is going to take time—like it's going to take a good five, ten seconds—then during that time it would print the status of the system. Like supposing it has completed like step one to step three, okay, and it's stuck at step four, then you would print that message, and as an event therefore is completed, you will get a message uh saying that's completed. And yeah, similarly, it's like progress-wise; it tells you what is the progress and what are the actions that the system is taking and what step it's performing. So it just prints such informative messages -V. Okay. Okay, let's first start off with the I flag. Okay. So we have something called as a CP flag I. Okay. So when you give the I flag, it enters the interactive mode. So when you say interactive mode, it is because uh at times you might have files which will all be already be present in in a particular directory. Okay. Uh, you saw me copy automobiles.txt once from documents to desktop. Okay. Now if I do the same operation again, if I run the same command again, at that time it will automatically overwrite the file. Right, because uh the file name is the same—the automobiles.txt is the one that is there in my documents folder, and again even over here on my desktop it is documents—sorry, it's automobiles. When I copy them, what would happen is that file would be replaced. Okay. Now uh in that kind of a situation uh when you're copying multiple files, you might want to be notified before something happens. Right. So if you specify something like the I flag, then you will get an interactive mode. So the system will not take a decision on its own, but instead it will not use any defaults. Okay. That's what we mean by on its own. Okay. So it would uh, you know, ask you; it would prompt you for an answer. It will tell you that okay, this file already exists in this directory, and do you want to replace it, and then it will give you an option y or n. y stands for yes; n stands for no. So that's what the CP and I flag does. And when you give the N flag, it will not overwrite the file. Okay, because by default it overrides the file, and if you specify the N flag, it will not overwrite the file. But the whole concept here is it is based on the file name. What if the file name is the same and the file contents are different? Okay. At that situation you might want something like the flag U. Okay. Now what the flag U does is it will update the destination file only when the source file is different from the destination file. So by using the N flag, you will make sure that the file is not overwritten. Okay. But then if you use the U flag, you will have another benefit. Okay. What will happen when you use the U flag is—so first it would check the file name. If the file names are different, then it would create a new file. If in case there is another file by the same name, then it will check the contents of that file. If the contents of that file and the file that's being copied, if they are the same, then it would not get copied, and it would only get copied when the content is different. So at that time you'll have two different files with the same name. So that's the advantage with the CP and U flag. Okay. So let's try executing uh these options. All right. So I'm—I'm just going to go back to my Domino here. So first and foremost, let's execute the r flag. Okay, it's capital R, so do note that. And uh when you say enter… So the item is copied. So if you go back to your documents folder, you can see that there's a new folder called elements has been created. So this was initially not present, and it's present now. Okay. Now what we'll do is I'll delete this. Okay. I'm going to minimize this, execute the same command along with the verbose flag. All right. So as you can see, the status of the system was also displayed in the meanwhile, even though I entered my text somewhere here… Yep, it's right here, correct. So this was the earlier uh command that I executed without the verbose. Okay. Here it just straight away copied the file. Okay, the LMS—sorry, the LMS folder—to my documents folder. But when I gave the—informative message also came. Right. So it—the step-by-step process, what all is being copied, came. So first this was the first folder being copied; this was the first subfolder being copied, and after that all the other files that are being copied—each and every document, step by step—it is all listed down, and uh you'll get all those details here if you give -V in your command. So that's what the -V does. Okay. So I'm left to show you the i, n, and U flags. Right. So what I'm going to do is uh let's say I just want to clear the screen now. Okay. I'm gonna remove this command here and go back to the documents folder and show you that the LMS has been copied okay, with the verbose when I created this folder. Okay. Now what I wanted to show you is I'm going to show you copy with the interactive mode. So earlier, if you see the uh desktop, there's already an automobiles.txt. Right. So what I'm going to do is I'm going to copy automobile.txt—I'm going to copy this one again to the desktop—but this time it should uh, you know, I'm going to use an i flag, and it will not overwrite the existing flag. So I'm going to say CP automobiles.txt to destination is uh home/edureka/all right, I think I'm in the wrong directory right now. Okay. So I need to go one path back. Switch to documents. All right. Now here I need to copy the automobiles from here. Right, and put it in the desktop. So home/edureka/desktop. Okay. So I'm gonna copy the automobile.txt over here. So when I just enter… The automobiles.txt has been copied here again. So let me just go back to my desktop and see that even though I've run—run this command two times—one now, one uh one earlier and one uh now just a couple of seconds back—there has been no duplicate that's been created. That's because this file has been overwritten. Okay. The one with the name automobiles has been overwritten with the latest command. So what I'm going to show you now is I want to use an i flag here. Like I told you, i flag is what gets you into interactive mode. So you will start interacting with the Linux kernel or the Linux shell over here. So as it says the home address desktop automobile.txt, it says overwrite: Do you want to overwrite this particular file because it's already present? If you want to overwrite, if you say y and if you enter, then the file would be overwritten. Okay. But if you give n and enter, then that file would not be overwritten. So if I say unknown, if I enter, then that copy would have failed. Okay. But if I do the same thing again and if I press y, it would have overwritten—the file would have been overwritten. So that is uh what the i flag is. And then you have another option okay, of the N flag. So the N flag, what it does is it does not override the file by default. So for that option, I told you that uh by default it overwrites. Right. So I also showed you earlier that uh no duplicate was created, and the existing file was overwritten. Supposing you don't want to do that, then you can just use the N flag, which would automatically indicate and tell the Linux runtime mentioned that not to overwrite this particular file. Okay. So you can have any number of files there. So even if the contents are different here. Okay. So even in case the new file that's being copied has a different content. Okay, but it has the same name, then even in that case, by specifying the N file, it will not be overwritten, because there's a good chance that you might have made changes to the latest file, and by copying another file with the same name to that same directory, then there's a good chance that you'll be losing out on the changes that you made. Right. So at that time you can use the N flag. So in fact, let me show you that with an example. What I'm going to do is—right now we are in the documents directory—so I'm going to do a cat and Automobiles. Okay. So these are the contents here. And let me update this. Okay. What I'm going to add is I'm going to add another company of another bike. Okay. Let's say we are adding KTM to that list. Okay. So when I do Ctrl D and exit the interactive mode, and if I do cat automobiles.txt, then KTM would be added over here. Okay. Now this uh automobiles file in the documents—right now this is the updated one. Okay. But in the desktop, the updated file is not present. Okay. In the desktop, the file with only this much of content is there. Now I'm going to execute the command with the N flag. Okay. So with the N flag, it's basically indicating that you're not supposed to override the file. Okay. So when it says that—when it finds out that automobiles.txt is present over there also, in the desktop also—it would not copy the file at all. Okay. So when I have enter… And of course… So there's nothing here. Now if I go to the desktop. Okay. If I click on automobiles.txt here, you can see that KTM is not present. All right. But however, when I close it and if I uh remove the N flag. Right. If I remove the flag and execute it, and if I go back to the automobiles.txt, you will find that KTM is updated. Awesome. Right. So that's the power of this N flag. Okay. So that is the end of all the different flags that I was about to show you from my PPT. Okay. So additionally, there is one other thing that I want to show you. Okay. Now I showed you how to copy from source to destination. Okay. And now you know—what if you know the path of something and you want to copy it to your present directory—to where you are currently? So this is basically—I'm just teaching you this option to, you know, save some time. Uh, you know, at times you might want some shortcuts or some hacks. Right. You don't want to provide the complete path everywhere. So at that situations—at that scenarios—you can use this hack. And let me explain that before I execute it in my terminal. So what I'm saying is uh right now I'm in my desktop, and I have only my Automobiles and my readme text files. Okay. Now but in my documents folder, I have three other texts. I have 51.exe and file2.txt. Okay. Let's say I just want to copy the file2.txt. What will I do if I want to copy my file2.txt into my desktop? I'll have to go to my documents folder, then put the CP command, and then enter the file name, and then copy it to this folder. Right. I have to specify the path of this desktop. So instead of that, there is another hack over there. Okay. Now instead of doing that, what I can do is I can just go to my terminal. I need to first go to the desktop folder button. Okay. So I'm gonna go one step back. I'm gonna say a change to desktop. And here… Yes, there is only automobiles.txt and there is readme.txt. Now what I'm going to do is I'm going to run the CP command such that I copy file from this particular directory to the current directory. Okay. So the file2.txt, if you remember that is present in my document directory. Right. So I'm going to specify the path to the documents directory, and the path to document directory is /home/edureka/documents. Okay. And the file name is uh file2.txt. Okay. I'm gonna copy this file which is under this path to my current directory. Okay. Instead of having to specify my complete current directory, I can just give one dot. So this one dot represents the current working directory. Okay. I'm currently in my desktop, and uh what this command would do is it would copy this file into this uh current directory. Okay. Now when I give enter, and if I go back to my desktop, you'll see that the file2.txt has been created. Okay. That's because it went to this path, picked up this file, and pasted it in my uh current directory. Okay. So that's what this is about. All right. So this is what I want to show you guys. This was something additional which was not there on the slides. So I'm done with that. So moving on to the next slide. Okay. So uh next up we have is the move command. Okay. So the MV—like CP stands for copy—the MV here stands for move. Okay. And this is uh used at times when you want to cut-paste something. Okay. Uh, this would—when we used copy, then the original copy of that file was also present in the existing directory, and it was created in another directory. Right. But if you use the MV command, then it's gonna basically work like cut-paste, where it will remove the content from the source directory, and the only copy will be present in the destination directory. All right. So uh let me straight away get started; it's not too much of an explanation needed over here because uh it's self-explanatory. If you use the i flag, it basically enters into interactive mode again, like before. So the U flag is again the same as what it was in the copy command; it updates the destination file only when the source file is different from the destination file. And the MV -V again, it would uh, you know, move—it would print the in-system state. Okay. Print the source in the destination files uh gets into the interactive mode where the—okay, not interactive mode; it basically means uh the system status will be displayed over here. Okay. That's what the verbose is all about. Uh, so let me go back to my terminal and uh show you how this copy is done. All right. So let me clear the screen, and currently I'm in my desktop folder. Okay. And here I have these five—I have automobiles.txt and readme and file2. Okay. Now what I'm going to do is uh I'm gonna use the move command to move file2.txt to another destination. I'm going to move it to the LMS. Right. So when I give LMS… Okay, this means that this move command will work such that this file will be moved to LMS folder. Okay. Let me give enter and go back to my desktop and find that it's not—it's missing. That's because I ran a command over there. If I go to LMS, however, I'll find the file2.txt over here. All right. Awesome. Right. So that's what the MV file does, and uh supposing I want to uh, you know, similar to copy here, you can move multiple uh files at the…
Same time, all right. So I can move, you know, supposing uh I go back to my desktop, okay, and I'll find that there is Automobiles and readme. Suppose I want to move both of these to the uh LMS directory, then I can do that also. I can just simply give move. I can give automobiles.txt and readme.txt and specify the destination. I can move to any other folder, or I can move to the LMS folder. If I'm moving it to the LMS folder, then I just need to give LMS. Okay. But however, if I am moving to another folder, then I gotta start from the root, say home edureka, and from your, let's see, I want to go to downloads. Okay, so downloads, if I want to go, I'll give this path. I'll give enter. And if you notice, both are missing from my uh desktop, and if I go to my edit Recon, if I go to downloads, I can find the two files over here. So that's how simple it is, guys. So that's the move command.
And if you want to see the system status, then you can use the V flag like we use for CP. So a similar log will be generated and shown. If you want to enter interactive mode, then you can use the I flag. All right. If you're moving like two files right at that time, you might need the interactive uh interactive file. So similar to a copy where if we are moving to the destinations folder where there's an already another file with the same name, then at that time you might want to use the i flag. It would ask you whether you want to override it or not. If you don't want to override it at all, then you can just give the N flag. But there again, if you don't want to use the N flag either, then you can use the minus U flag, which would update the destination file only when the source and the destination files are different. Okay. So these are the uh different flags that can be used with mv. So the basically the flags that can be used here are the same as the flags that can be used with the copy command. So guys, uh that's it with the move command, and we can go to the next slide. Okay, we can go to the next topic. But before that, there is one more functionality that I want to show you with respect to both copy and move. I uh actually forgot to show you this aspect. Okay.
Now uh for this, let me first show you the GUI aspect. Okay. All right. I go to my edureka, and if you go to my documents, you'll find all these three text files and also my LMS folder. Right now, whether be it copy or whether it be it uh move commands, I've showed you how to copy like one file or two files or three files. Okay. But what if we have like 25 files? Right. So what you have like, I mean, just think about this, what if you're a proper uh Linux user and you want to just transfer all your files of some particular format? Right. You want to just transfer it to another folder. You want to take a backup or something like that. What would you do instead of, you know, you can do a control A over here and choose all the files. Okay, or you can choose one after the other like this. But to the CLI, how do you do it? Correct. So you have such problems, right? So for that, you know, we have options also for CLI, and those work with both CP and the move commands. So what I'm going to do is I'm going to show you how that is done. Uh so for that purpose, I'm gonna first go to my documents directory. I'm going to make that my uh PWD. So I'll just go on back, and here I am. Go to documents. Okay. Now I'm here. So what I'm going to do is I'm just going to clear the screen. So of course, for clearing the screen, the shortcut is Ctrl L. Okay. If you guys have forgotten that, and uh I also mentioned that earlier, so Ctrl L is the shortcut for that. Uh so yeah, we have automobile.txt file one and file two and LMS. So we have these four files and one folder there. Okay.
Now if I want to move this one as a directory, then there's another option. So what I can do is I can use something called as regular Expressions. Okay. Uh regular Expressions is one topic which I'm going to cover in detail later during the session, but just because we're in the CP or in the move commands stage of this demonstration, I'm gonna continue on, and I want to show you this also. Okay. I want to just get finished with this part. So you will get an idea of what I'm saying when you see me do this. Uh so here we have these four uh files. So first let's use the copy command. So if I want to copy all the files which are in the form of a file. Okay, so they're all in the dot txt format, right? So what I can do is I can just do a cp. I can click on dot or rather asterisk dot txt. Okay. Now what this essentially does is instead of searching for the text file by its name, it is it searches for all the files with the dot txt. Okay, which is ending with a DOT txt. So that's what this would do. And when we say CP followed by asterisk dot txt, it means copy all the files that are ending with DOT txt. So in our case, we have automobiles.txt, file1.txt, and uh file2.txt. Right. So what this command would do is it would copy these things and put it in the path where I suggest here. So let's say I want to put it in another folder. Okay. Let me start off from the root home edureka. Then here I think we have, you know, we have these options, right? Okay. This is the documents. So in the edureka, we have okay, we have the music folder, we have downloads, pictures. Okay, downloads, of course, I've already copied something in there. So what I'll do is I'll move that to the music folder. Okay, so the music directory. So I'm going to say this and give enter. So your copying has been successful. So if you go back to the music directory, you'll see that there are three new files: one is automobiles, the other one is file one, and the other one is File 2. Okay. Now the same thing can be done for even move. Right. Uh the same way we executed a copy, we can also execute the move command. Move is going to completely move it; it's more like cut pasting. Okay, similar to how you remember from Windows. Let's move it to pictures. Okay. So currently in pictures there's nothing, and in music we have these three. So when I execute the move command, this folder should become empty, and they should all go to the pictures uh folder. All right. So move. Okay. But we have a problem for that. What we need to do is we gotta move to our music folder, right? So it would this would probably show an error. So I'm going to first go back or rather go to the music folder. Okay. We are in documents, right? So what we're going to do is uh CD music. All right. And I have my commands here, right? So here I'll execute that move command. So it was this one. I'm just going to replace cp with mv. Okay. So from my uh music directory, it's going to move all the folders or files which will have the dot txt format. Okay, all the files, not folders; it will move all the files with the dot txt format, and it will move it to home/edureka/let's move it to pictures, what do you say? Okay. So when I give enter, that would have moved. So let's go back to our folders. Music, there's nothing here. This has been cut pasted to the pictures directory. All right. So this is what I'm going to show you. Okay. This is what I missed showing you earlier while executing the CP command, but yeah, here we are. I've done this. And similarly, if you want to go also uh you know, if you are from the music directory and if you want to move something to the present working directory, even that is possible. Okay. So another possibility which I would like to show you is that of going back, going to pictures, and then we have all this here. I'm going to clear the screen. LS again. We have Automobiles, file1.txt, and file2.txt. Right. So uh we can do a move command and uh so right now we are in the uh so let me clear the screen again. So I'm going to do a CD. I'm going to clear the screen, and uh currently I'm going to do an LS. So some of our items are present in pictures. So what I'm going to do is I'm going to uh move back to music. If I do an LS, there's nothing over here. So what I'll do is I'll say move /home/edureka/pictures . okay, asterisk first .txt, and I want to move it to the current directory. So when I do this again from the pictures, everything would have moved back to music. All right. So that is the other uh thing that I want to show you. Okay. So similarly, it works for even the copy command. I'm pretty sure you'll understand how it works, so I'm not going to waste too much time on that. Okay. I've cleared my screen, and now let's uh start with the next topic. Okay. I'm going to go back to my slides, and yeah, the next topic is uh make directory commands.
Okay. So the next topic is uh make directory. Okay, that's what mkdir stands for: make directory. All right. It's simple again. If it's all about creating a new directory or creating a new folder. Okay. So uh to create a new directory, you just specify mkdir and uh the path, okay, the directory path. Okay, that would create a new subdirectory in that path. Okay, guys. So currently we are in the documents, right? So I'm going to do an LS. I have these many things. So I'm going to do a mkdir and create a new folder over here. So that folder name is going to be uh let's say folder one. Okay. When I do this, a new folder is created. So when I do the ls command again, so you can see that the folder one is extra. Okay, it was not there the previous time that we executed the ls command. Okay. So that's how you create a new folder. So it's pretty simple. Now comes the other question. Okay. I can go into uh the folder one. Okay, of course, there'll be nothing inside. Now what if I want to create multiple folders? Okay. And uh parent directories, let's say something like I want to create folder one inside which I want to create a folder two and create a folder three. Is that possible? Okay. I'm gonna try doing that and show you if it's possible or not. Okay. So I'm gonna say make directory folder one/folder two. Okay. This would be foldable because I'm already inside folder one. This would be folder three and folder four. Okay. So this basically will run the make directory command inside folder one, and it will make a directory of two, three, and four. Now when I give enter, this folder should be created. Ideally, they should be created. Okay, ideally speaking. So let me just verify everything once and show it to you. So it was documents. This is the new folder I created, folder one. There is nothing inside. Okay. Now uh from the terminal, if I click enter, it says make directory cannot create directory folder two, three, and four. Okay, because there is no such file or directory. Okay. Do you know why that is? I as well specifically can we do it? That is because when we try to enter one directory, it's possible. Okay. When like in this case we specify just one directory, right, just folder one, so it created the directory once. But in this case, there are too many directories that we need to create. Okay. It's like two, three, and four. How can make directory create so many folders? Because this is going to be in the form of a parent-child or a subdirectory, right? We are creating folder two inside which there's a folder three, inside which there's a folder four. It so in this case, mkdir is not enough. So this is when we need to use another flag called the hyphen P flag, that stands for parent. Let me go to my slides and just cover that aspect once. So as you can see here, there's a flag called hyphen p. Okay, and what it does is it creates both a new parent directory and a subdirectory, and it's essentially used only when you're creating like two, three directories, and I mean, you're creating one directory and a couple of subdirectories under that directory. Okay. So that's when you use this. Uh alternatively, you can also use this hyphen p, parents. All right. And uh if you want to create one parent directory and multiple subdirectories inside that directory, then you can use these flower brackets. Okay. Inside the flower brackets, you can have the different folder names. Okay. So let me just quickly go to the terminal and show you that aspect. So make directory. These were there, and now I'm going to give -p. And when I execute this, everything would have been created. So let me do a CD folder two. Now do an LS. There's a folder three. Now let me do this and enter, and let me do an LS again. There's a folder four. Of course, here there would be nothing, right? So let me uh enter this folder four, and here there will be nothing. Folder folder. So that's what I was talking about. Okay. Let me also verify that once from the terminal. Folder one, we created a folder two inside which is a folder three, and there's a folder four. Okay, guys. So this is what we just created. So what I'm going to do is uh I'm gonna just go back to my folder one here. Okay. In fact, yeah. Okay. Folder one should be good. Now I want to show you executing the same command with the flower bracket. Right. I told you that creating a flower bracket will let you create multiple directories inside that directory. So if I'm gonna say make directory folder, because it's inside folder one, I can create one here, folder two, I can say comma folder three, comma folder four. Okay. And if I close this flower bracket, then these three subdirectories of folders will be created inside my folder one. All right. So we've given enter here. If I go back to my GUI, so I go inside folder one, so initially there was one folder two. Okay, that was the folder which I created earlier. Okay. Now I created folder two, all in small small f, small f, and small f here. So folder two, folder three, folder four was created. Now folder, this one was created earlier. Okay, guys. So that's how uh you know, you make directories. In fact, you can even append this with a parent. Say you are supposing you're now in folder uh one, right? You can say make directory, you can say F2, put a slash, and then inside this F2 folder, these subdirectories will be created. Okay. Now if I give enter, I know what the problem here is. Uh it says because F2 is not created right now. Correct. This is the time when you got to use the hyphen P command, parents command, right? So which I showed you earlier. So now that our views of -p, so the parent is created and the children are also created. So if I go back to folder one, this was F2 is what I created recently. All right. So inside F2 there should be folder two, folder three, folder four. All right. So this is uh what we can do with respect to make directory commands. All right. So let me close this and go back to my slides. Okay. And uh go to the next topic. Okay. So uh next up is the rmdir and the rm commands.
Okay. So this is the remove, and this stands for remove directory. Now there's a subtle difference between the two. Okay. Now uh when you say, okay, the basic difference between the two is that when you say remove directory, it will only remove that particular directory, but when you say remove, it can also remove the subdirectories or the child directories inside that one. So let me just go to my terminal and show you how these are executed. Okay. I'm going to go to my terminal. So currently I am in my folder one, right? So let's go to folder two and then do an LS. CD folder three. LS. CD folder four. Okay. Of course, there's nothing here. So what I can do is I'm in folder three now. Okay. LS again. Yes, I'm in folder three, and if I want to remove this folder, then I can do a remove directory folder four. All right. So when I do this, this particular folder would have been deleted. Now from folder two, I can again remove folder three. Okay, similar to how I remove folder four. But how about I go one more path back? Okay. So right now I'm in LS. Okay. So if I do a PWD, you'll find that I'm in folder one. Okay. And when I do an LS, I have F2, folder two. I have a capital folder two. This is where my folder three and folder four is present. Okay. So I have that, and then I have a folder three and I have four and four. Now however, if I try doing a remove directory and if I try to remove folder two, right, it will not work. It failed because the folder two which you are trying to delete, right, from inside folder one, we are trying to delete the folder two. This is that folder two, and inside this folder two, there's another folder that is folder three. Let me just show it to you once so that I can remove your confusion. So inside this folder two, I have folder three. Okay. And because I'm trying to delete this folder two, it's not able to delete because there is already a folder three inside this folder. That is a problem with remove directory. So guys, I just cleared the screen, and now let me just do an LS again. So now I'm going to show you how to remove these folders. I showed you removing folder four. Okay. So inside this folder three, I went and I removed folder four. Okay. Now I'm gonna show you how to remove multiple folders okay at the same time. Now let's say I'm running the same remove directory again. So I'm going to say remove folder two, and uh when I give enter, it says failed to remove folder two because the directory is not empty. Okay. Uh do you know what the problem is? It's telling right, because the directory is not empty, it's not able to delete. So because folder three is contained inside folder two, it's not able to delete this folder. So if I want to delete a folder two also, then what I want to do is, you know, I got to first delete the folder three and then delete the folder four. So I have to provide the absolute path of the child directory. Okay. So I'm going to say remove directory. Okay, same like before, I'm going to say folder two/folder three. When I run this command, then my folder three will get deleted. Okay, the child will get deleted, but the parent will still be active. Folder two will be active. Okay. Because uh when I use the rmdir with folder two and folder three, only folder three will get deleted. Let me show you uh why that's the case. When I go enter, when I do an LS, folder two should be available. See, folder two is available, but when I do a CD folder two, there's nothing in here. Okay, there's nothing in here. So if you want to do that, if you want to delete both the parent and the child at the same time, you got to use a -p flag. So let me show you to uh use a -p flag. Okay. So I'm just going to make the folder three now, and I'm going to show you how to use a p flag. So similar to how we use while creating a folder, we got to use the same remove directory. Okay, rmdir with the -p in folder two and folder three, folder two/folder three. So in this case, both the folder two and the parent and the child will get deleted. Okay. Enter. When I do an LS, I don't have a folder two here. Okay. This one is also deleted. So that's what a -p flag does. Now let me just create, make a new directory, and uh what I want to show you is the verbose. Okay. So I'm gonna make directory. So again, the ones which I deleted, I have come back again, would have been created again. So I want to show you the usage of the verbose directory. When I add a v here, as per the slides.
It said, right, the verbose. So when I add a v here and when I hit enter, okay, I've done the Mig battery again. So I have to actually remove the directory now. Okay. Now when I say remove directory and when I uh try to print the uh verbose hyphen PV, so it says first it's deleted the folder three. Okay, if it's done inside folder two, after deleting that it has come and deleted folder too. Okay, so that's what this is all about. This is what, you know, you need to know about the remove directory commands. Now, uh let me just clear the screen. So guys, uh now let's uh see how the RM command works.
Okay. Now, uh the RM command here, as it says from the slides, it can be used to remove even non-empty directories. Okay, if we use the RM with the r flag and if we use uh the R and P flags together, then it removes the non-empty directories including the parent and the sub directories. Okay, so the one limitation that we had with rmdir command was that we could not remove non-empty directories; we had first empty them and then only delete them. Okay, otherwise we had to specify the entire path and then uh, you know, use the P flat to remove all the parents and all the child sub directories in that path, right? That was the limitation that we had with remove directory. But with RM, we don't have a problem because uh, let's see. Okay, in LS we have so many folders. Okay, so if I try going to F2, okay, and I do an LS here, then I have three different folders: folder two, folder three, folder four. Okay. Now if it's an RM dir command, it cannot technically delete this folder called F2. F2 is basically a non-empty directory. Inside F2 there are other directories like folder two, three, and four. So let me just uh show to you once. So inside F2 we have three folders: folder two, folder three, and folder four. So with the uh RM dir command we cannot definitely remote, but with F2 we have a chance of removing it. Okay, that's because we can make use of the r flag here. Okay, but however, this will also—it will delete F2 and its subfolders. Okay, so let me do an LS and uh if you can see here initially under folder one we had F2 and these three, okay, but now we don't have that under F2 because that whole F2 folder is missing. If I go back to my folder one here, you'll see that the F2 is uh missing over here too. That's because they're removed, right? It removed the whole F2 folder in spite of it containing some folders. Okay, and that's what the r flag does; that's the advantage of using the r flag. Okay, so if the same thing, if we use the r flag with the V flag, then it will print the status also; it's like the verbose, right? It'll print; it'll tell you what all has been deleted and how it has been deleted. So that's the advantage with using RM over uh rmdir. Okay, at times this is more beneficial. So I'm just going to clear the screen and getting back to my presentation. I'm done with all the concepts in this slide, so let me go on to the next topic. Okay, so the next topic is going to be that of working with user permissions.
Okay, it's very important for a Linux administrator to know what these user permissions are. Okay, because uh the different files will be there, different directories will be there, and he has to determine what kind of access will be available for which user, right? So that's what is controlled here. So uh the different permissions are basically read, write, and execute. Okay, R stands for read, W stands for write, and uh execute is X. Okay, so uh initially you'll get this kind of uh an output. Okay, you know what, let me go to my terminal and show you what happens when you run an LS; LS hyphen L command, because user permissions is something which will appear and which you can control via the ls hyphen L command, right? Because when you do that, all the different file contents, whether it's a directory or whether it's another file, all those things along with their permissions will be visible in Long format, right? So let me go to my terminal first and uh go to CD all. Right. Now when I do an LS, I have a list of all these uh documents. Okay, but however, when I do an LS hyphen l, I get it in Long format. Okay, so I get it something like this. So for each folder I have the permission set, so for desktop I have the permission sets and then I have the other components. Okay, I'm going to explain what this entire component, what the entire row means, so do not let you get too complicated. First, I'm going to explain only this part. Okay, the first 10 characters, if you see here, the first 10 characters are these, and I will explain this part first and then I'll explain this set, these three blocks, and then I'll explain the remaining blocks. Okay, so getting back to this uh first block in my slides, you can see that the first block it determines what is the file type. Okay, it's either the file or directory type. In fact, if that is a directory, then it would be represented by D. Okay, if you have a d as the first character over here, then that's a directory. Okay, as it says, but it can also be any other thing. If it's a hyphen like this, then it means that it's a normal file. Okay, but in the first letter if it's a c, then it means it's a character special file, and if there is B over here in the spot of the first letter, then it's a binary special file. So basically there can be four different letters over here; it can be either a hyphen or a d, b, or c, representing four different aspects. Okay, so uh that is the first information that you have about that particular file, and then you have three different blocks. Okay, so the next nine letters are going to determine the user permissions, okay, and those nine are divided into three, three, three. Okay, so the first three represent the user permissions. Okay, the second block having three uh rwx representatives uh are those of group permissions, and the final block represents other permissions. Okay, this means other users. Now this user is the actual user who is logged into the system. Okay, that particular user. So this is the user permissions, this is the group permissions which the user belongs to, and what the other group can view, and this this is with respect to the other users. Okay, that's what is meant by this others. So if we have uh and the order always goes by rwx and rwx and here also would be r w and X. Okay, so that is the order: read, write, and execute. So if the first three blocks are all r w and X, then it means that the user has all the three permissions, or the owner of the file or the user has the read, write, and the execute permissions. Okay, and in this place if there are three characters, right, RW and X in this order, that means that the owner or the user has the permissions to read, write, and execute that particular file. Okay, and if there is RW and X in the next block, then it means that the group has the read, write, and execute permissions on that particular file. So every file that's created, right, it will have a user, and it will also have a default group that it will be assigned to. So all the users a part of that group will have the read, write, and execute your permissions. Okay, but whereas the last three here, it stands for other users' permission. So there can be multiple users, right? The same system can have multiple users; one, of course, would be the root user, the other would be the owner or you, and besides you, they can be any number of users; you can be your friends, your colleagues, or you know, other people. So this others represents that, and uh if you have a blank in any place. Okay, so in this case there's a blank over here in place of w; there's a blank; it means that this others, they don't have the write access; they only have the read access and the execute access. All right, and similarly if you go back to the terminal, okay, and if you see here uh take the example of this particular file desktop. Okay, desktop folder is where we were executing a lot of commands, right? It is under the editoraker folder. So yeah, this was the folder that we are talking about, the desktop. Right now it's a directory, basically, okay, that you all agree with. Then these three characters represent that the person who's using it, okay, right now the person who's using it uh because I'm logged in right now and I've logged in with this username, right? Sorry for that, guys. Yeah, and I've logged in with this username, right, edureka. So uh me being the owner and me being the user, I have the read, write, and execute permissions. Okay, but the group that I belong to, okay, that group does not have the read, write, and execute permissions, and the group that this file belongs to. Now because uh this file is either owned or used by me, okay, now because I'm the user, I have this access, and then this file will also belong to a group, right? So whenever you create this file, it will be assigned to that particular user creating it, and it will be assigned to a default group. So we are talking about that group here, okay, and that particular group does not have all three rights; it has only the read permission and the execute permission; it doesn't have the write permission. Okay, and the same thing can be said for uh even the other users. So the other users in that system will be using that system; they'll only have the read and execute access on the desktop. Okay, but whereas if you take the example of this file one.txt, right, which I created sometime back uh during this session, this one, if you see the permissions are such that the first one is a hyphen. Okay, uh what hyphen technically means is it's a normal file. Okay, I explained that hyphen is normal; b stands for binary special file and C stands for character special file. So of course we don't have those options here; we don't have the B and C options, but what you've got to understand is that this is a normal file and this is a directory. Okay, wherever there is D. So since this is a file and the access for the user is such that I have the read and write access, okay, but I can't execute it; the user can't execute it; and when it comes to the group, even the group has the read and write access, but you cannot execute it; the other users, however, they have only the read access and they cannot execute this particular file, right? So they cannot execute or they cannot write this particular file. So that's what these group permissions mean, and if you go forward from group permissions, there are more other blocks, right? So let's go back to the slides and see what they stand for.
So in this slide, let's talk about the next three blocks. Okay, so the next block is that of a number. Okay, you have a number over here, and that represents the symbolic links. All right, the block after that is the one that represents the owner name, and the one followed by that represents the group name. Okay, so that is with respect to these three blocks. All right, and then after that that comes the file size of the particular file, and then you have the timestamp, the time when the file was created, the file or the folder was created. This is the actual file size of the block. Okay, now that's what the user permissions here represent. So if I quickly go back to the terminal and show you, this is basically the symbolic link, this is the owner name, this is the group name of the file, this is the block size, okay, and this is all in kilobytes, okay, and this is the timestamp, and this is of course the name of the file, right? So we have the name of the file, and that file will have first be the file type, then user permissions, then symbolic links, then the owner name, then group name, then the file size, then comes the timestamp at the end. So that's what the different file permissions are: the read, write, and execute. And if you want to modify any of these file permissions, then it's also possible. Okay, now let me go to my slides and show you how that's possible. Let me show you some theory first. Okay, so first of all, if you want to change the permissions, then you can use the CH mod command, mind. Okay, you can use a chmod command as shown over here, and you can use it to change the access permission of both the files and the directories. If you want to change the owner of the particular file, okay, change the owner of that particular file or directory, then you can use the CH own command, and then if you want to change the group ownership of that file, then you can use the CH grb. Okay, so when you use the chmod command, you got to specify who am I referring to? Are you referring to the uh the user? Are you referring to the group, or are you referring to the other people? Okay, the other users, you gotta say that, and then you got to use either a plus symbol or a minus symbol. Okay, when you use plus, it means that you're adding these two rights. So in this case, when you're saying G plus W X, so G stands for group, right? So as you can see from this particular slide, G stands for group, U stands for users, and others stands for o. Okay, and all stands for a. Okay, so as per this, if you're using G over here, then it means that you're talking about the group, and you're adding the W, that is a write, and the execute permissions; you know, that means you're giving them the W and the right and the execute permissions. Okay, and after you've got to specify the file name. So this means it will modify the permissions to this for this particular file. And similarly you can use the equal to symbol and also the minus symbol. So when you use the equal to symbol, then whatever writes you have initially that should be overwritten. So when you say chmod U is equal to rwx, and then it doesn't matter what the previous set of permissions were, then the the previous set of formations will be replaced by whatever you specify here. So you'll be setting that particular user to have the read, write, and execute access for that file. Okay, and then you can, in fact, specify if uh, you know, you can set access control for multiple people; you can send it for groups, users, all at the same time. So in this place, this command, we've set it for the users; here we are setting it read, write, and execute for users, and then after that we are setting it for the other people. Okay, for the other users, we are removing the write and the execute access, okay, the execute permissions. So let me just quickly go to my uh terminal and show you that. So currently uh let's take the example of this pictures. Okay, let's take an example of this particular folder; the user that is me, I have the read, write, and execute permissions; the group has read and execute only. Okay, and uh they, of course, the other users, they also have only the read and execute. Now what I'm going to do is I'm going to say chmod uh I don't want to change my permissions. Okay, so I would rather change the permissions that my group has. So I would say G is equal to read and W. Okay, so if you see here, right now the group has read and execute. Okay, I don't want to give them execute. So if I want to remove execute, I have to do G minus r and then I have to give comma G plus W. Okay, but those are two different arguments, right? So instead of using two different arguments, I can just give an equal to which would replace this entire list with the current arguments. So instead of having rnx, I will replace that with R and W, read and write. Okay, I'll give a command, and then we have others here; the other users, they have read and execute again. So what I'll do is I'll uh say o minus execute because I want to give others only the read access. Okay, so in this case, when I do this, the X over here that will uh become hyphen, and uh the hyphen here will become W. Okay, I'll be enabling the W for them and removing the execute, and for these people I'll be removing the execute. And now that I've specified what are the permissions and who are the your recipients, I'm going to give the file name. So let's say pictures. Okay, so I'm going to give the ls minus L command again, and now you can see that if you go to pictures, it's been reset. So the others have only the read access; the others are blank. Okay, and the group have the read and write access, and this execute has been taken away from them. So that is with respect to the read, write, and execute permissions that users can have. All right, so I'm just going to clear the screen and go back to my slides. So similarly you can change even the ownership of are certain files and certain groups. Okay, so if you use a CH own, okay, CH uh change ownership, with that's what it stands for, and when I follow that with the username and the file name, then this particular file will have a new user or will have a new owner, and this will be the username. Okay, and similarly even the group command works in the same fashion. So this is something that you can always work on and you can figure it out. All right, guys. So working with Linux repositories. Okay, and it says that stable versions of most softwares will already be available in Linux repositories, and the command to install them is this. So you would have heard me say earlier that it's very easy to update software and the operating system itself by just running one simple command, right? You can update the software. So uh this is what I'm talking about. So you can just run one command. So this is the only command that you need to run. Okay, if you just give sudo yum install and if you give the package name, then that particular package will get updated. Okay, the sudo is something that you would recognize from what I told you earlier; the sudo is to uh we give it to to execute this command as a root user. Okay, and if you see that there are two other lines and the only difference between these three lines is the letter that the word we are using here. Okay, so in the first case, in case of any Red Hat Enterprise Linux system or even CentOS, right, which falls under a red hat, we use yum. Okay, but if it's a Debian-based system like Ubuntu or add one to X Ubuntu or any any other Debian Linux system, then you would have to use apt hyphen get. Okay, and then if you're using a Fedora-based system, then you got to use a dnf. Okay, so these are the three different commands, and these are the—that's because uh the repository name for RHEL it's called as uh yum repository, and the repository name for Debian is called as the APT repository. Okay, and for Fedora it's called dnf repository. So that's why we say we are first we will have to first give the sudo command which would make sure that we execute this command as a root user, and from the command perspective the first part would be calling or referring to the repository. Okay, so from the CentOS it would refer to the yum repository, or from the Ubuntu if it is—if I give apt-get, it would refer to the apt repository, and then we have something called as install, and when we say install and then follow that by package name, then that particular package will get installed. So for example over here it is Java, right? I'm trying to show how to install Java on your system. So in this case, if you first give a yum update, then it will first of all update your links to your repositories. Okay, it would update the Yum command and the links that you have between the repository and yourself. So it's not something related to installation of Java. Okay, this is just another command that you specify if any of your installation fails. Okay, so this is not a compulsory command that you need to run, but besides that what you have is uh yum install Java 1.8.0 hyphen open jdk. Now the packaging that you see here, right, that is Java, so if I want to install Java, then I
Would just give this particular package name, and I would say install. Okay, because the package name of Java that's present in the Linux repository that is called as Java 1.8.0 open GDK. And similarly, if you want to install any other software, right, if you want to install any other technology like Hadoop, then you can just give one such package name. You just got to find out what is the name of the package that they have in the repository; you can just simply Google it, and it will give you the package name, and you can just say yum install or sudo yum install followed by package name followed by Hadoop-2.0 or 2.3.0, or very soon 3.0 is coming, so you can say Hadoop-3.0, something like that. And yeah, if it's uh, if you want to install Docker, then again you can say sudo yum install Docker, and uh, probably the version name. I don't think Docker needs a version though. And uh, for installing Docker, you can do it also through Ubuntu. Okay, so when I installed Docker in my other Ubuntu VM, right, which I showed you earlier, so that VM has Docker installed, and the command that I ran that time was sudo apt-get install Docker, and that downloaded and installed the latest version of Docker that was available in the repository. Okay, yeah, so that is it. And once you're done with the installation, it would take quite some time to install, and once when everything is done, then you'll have to just, you know, update your environment variables. Okay, you have to set the environment variables over here in your .bashrc file. And once you set the environment path over there, then you can just do source, and then your software is ready; it's installed. Okay.
Now this was another step which I skipped out because this is not really necessary for you to execute this. Okay, I'll tell you why: because uh, this command, which is update-alternatives --config Java, it is only to select a particular version of Java. Now let's say that you're new to Linux, okay, and you're downloading Java for the first time, then you just need to run this command. So after running this command, you can straight away just uh, you know, probably when you're done with this, Java is installed basically. Okay, but it's just that you need to go to your sudo; you should do sudo gedit, go to your .bashrc file and update the path where Java is installed. Okay, you got to specify it; your environment variables to your runtime engine that Java has been installed in this path, so you have to just copy the path of your Java and paste it in the environment variables over here, and then you have to source that particular .bashrc. So when you're done with these things, your Java is installed. Okay, but if you already have a Java package installed, okay, so in my case, when I'll be showing you this now, I already have a Java 1.7 package. Okay, so now if I do a sudo yum install Java 1.8.0 open GDK, then I'll have multiple versions of Java. Okay, and my environment variables would be currently set to Java 1.7 because that's what I already have. But since you have, you know, multiple versions of Java, and since there are different packages, you can have multiple packages of Java installed, but you can only run one of them. Okay, so you set which one you want to run, right? That one you set over here, whether I want to choose to execute seven or whether I want to choose to execute it, that I can choose by updating over here. So I'll show you this command also. Okay, so that is what I want to show you with respect to Linux repositories. So similarly, you can even, you know, you can do a sudo yum install PHP if you want to install a PHP server; you can just say PHP MySQL server. If you want to install any other software like wget, you can do that also. So this is what we are saying; you know, it's very simple to install software. So if you're doing it with the GUI, then you'll have a lot of steps that you need to do; you need to go to the website, download the appropriate package, then extract them, then install them, all those things. So instead, this is just simpler, and it's much faster. Okay.
Now let me go back to my terminal and show you how that is done. Okay, so I'm going to go to my CD, and the command is sudo yum install, and now would come the Java package. So the package I'm going to install is Java 1.8.0. Okay, that's because Java 8 is placed with this name. Okay, so the package name of Java 8 in the Linux repositories is uh Java-1.8.0-openjdk. Now when I hit enter, it asks for the password because uh this particular uh, sorry for that, guys, when I use sudo to execute this particular command, then it asks for a password because I'm executing this as a root user, so that's why if I try executing this as a local user, as my own user, then it wouldn't be possible to execute this command. Okay, I have to execute this as a root user, and uh, root user is the one that has the ultimate privileges, the ultimate access; he has access to everything. So you just enter the password and put enter, and then automatically your packages will get downloaded and it'll get installed. So uh, now it says, you know, total download size is 33 MB, and uh, it asks is it okay to download it? Y stands for yes, and uh, n stands for no. Now if it's uh, you, when you're trying to download Java, when you give this command, you gotta say y and hit enter, because uh, that would download the 33 MB package and insert in your Linux machine. Okay, but however, I have already downloaded Java, and since I've done it already, so I don't need to. Okay, I don't want to waste my time here uh because uh this is a session, right? I don't want to waste your precious time, so what I'm going to do is I'm just gonna click on n and give enter. Is it fine, uh, Siddharth, Hemant, all you guys were in the session, is it fine? Because I want to save some time here by hitting n. Okay, because otherwise it would take some time to set up the installation process. So okay, fine. Yeah, I'm running a yes from you both, all right? So I'm just going to click on no. Okay, so it says uh exiting on the user command. Great uh, yeah, so the the one thing you gotta notice that instead of if you put y and if you hit enter, it will download for you, and it would complete the installation. All right. And there's one more thing that I would actually like to add to this: supposing while uh installing the same package, right, while doing the sudo yum install Java this package, when you're trying to run this command, if you want this y option to be chosen automatically, okay, because right now it entered into the interactive mode. Okay, interactive mode was when the kernel was asking you, should you download this, and do you want to download this and execute it later, and I had to press n and get out of it. Okay, but however, you might not want to. Okay, so there may be times when you might want to by default just click on yes. So what you can do at that time is you can just go back here: sudo yum, you have a flag here, you can just put -y, and if you then install it, then it will not ask you; it will not get into this interactive mode, so it will take this Y flag, y option automatically, and it will uh, you know, install the Java package. So that is what I wanted to show you; that's what I want to tell you. So that's how you install Java. Okay.
So now I've just cleared the screen, guys. Okay, so the when you execute this command in your Linux machine and when you finished downloading and installation of your Java, what you got to do is you got to set your environment variables. Okay, so as it was written in the slide, you got to give the sudo gedit .bashrc to enter into the .bashrc file and set the environment variables here, the path to where your Java is installed. Okay, so what I'm going to do is uh I'm gonna do the same. To end your .bashrc is something that will be present only in your home directory. Okay, so you got to remember to go to Siri, and from CD you got to access that; you got to say sudo gedit .bashrc. When you do this, it'll ask you for the password, but of course, I've entered the password previously, so it didn't ask me, but yeah, when you do that, you will open this uh .bashrc file. Okay, so right now my Java path is set to this. Okay, so this means during runtime, and any application is uh using or requesting for Java, then it will look for Java in this path. So you just need to find out where your Java has been installed in your system, so it would most probably be in your user/lib/jvm folder. Okay, so let me go to the same; so it will be there under your root directory. So uh if you uh go to your My Computer from your file system, under the lib folder, we have various uh packages that will all be installed over here. Okay, so in my system, it's all installed over here, so this is the jvm folder, and inside here I have all the different Java packages which I have downloaded over a period of time. So guys, uh in this case uh supposing see I have Java 1.7.0 open JDK installed. Okay, now in your case, you will have a Java 1.8.0 open JDK installed. So what you got to do is you got to just right click on that folder. Okay, similar to what I'm doing now. Okay, I'm going to right click and just click on copy and go here and paste the path over here. Okay, if anything is existing already, then remove that and paste the new path. So the path is nothing but where your jvm is located from your route, so it's in root/usr/lib folder, and then inside lib it's in jvm, and here it's this is the folder it's present in. Okay, and then you got to also additionally give the path to your bin directory. Okay, so you have this is your bin directory, so what you do is you right click on bin, again copy, go to your .bashrc, okay, you go to uh paste it over here. All right, so this is how uh this is what you do; this is how simple it is. So when you do it, you just gotta save it, and you gotta, you know, close this .bashrc file, and when you are done with uh saving and closing it, just go back to your terminal, and you got to run this command: source .bashrc. Okay, so when you do this, then your terminal will get synced with the updated environment variables; otherwise, even if you don't run it, it's fine; you can just start executing your commands from a new terminal, then it would not be fine, but yeah, the source .bashrc is only to sync your environment variables with this particular terminal that is uh opened. Okay, so that's how you install Java in your system. Okay, guys. So uh I'm just going to clear the screen now. Okay, and I'm going to go back to my slides. Okay, so I'm done with showing you how to work with Linux repositories, and the next topic that I'm going to talk about is that of tar files. So what are tar files? Okay, so all of you Windows users might be aware of this software called WinZip or WinRAR. Okay, what are they? What do they do? They are basically to extract your files, right? So they'll be in compressed form, and you'll have to extract them. So in Linux, we have an equivalent format. So in Linux, it is either the tar file or the gzip and the gunzip files. Okay, tar is the preferred option. So I am going to show you how to compress and decompress a file with .tar format, but however, even gzip and gunzip is something that can be used. If you want to compress a files with the gz format, okay, then you got to use this command, but however, if you have to go on a decompress it, then you got to give gunzip. Okay, and the syntax is here. Okay, but however, with the tar, for both compressing and decompressing, you will use the same tar command itself. So you'll just have . and in the arguments there will be a minor change. So when you're compressing the file, you will have to specify -c, okay, and when you are decompressing the file, you will have to give the flag -x; otherwise, it's all fine. Uh, the v here stands for verbose, and the f here indicates that you want to compress the file that is mentioned followed by uh the command here. Okay, so this f just basically indicates that you got to compress this particular file; otherwise, the uh kernel will be wondering for which file to compress, and it will throw an error to you later. Okay, so that is what uh the xvf here stands for; these are the different flags that are available with the tar command. Okay.
Okay, before I go and show you how to do the tar, let me show you a place where tar files will be your present. So in Linux, right, so no matter what kind of software you're downloading, whether it's a Java package or if it's a Hadoop package, if you're downloading them manually from the internet, okay, then you would get them in the .tar format. Okay, or you might find them in tgz format. Okay, tar is something the most, I mean, I would prefer a few people download tar because that's the easiest; it's easiest to extract and, you know, also comparison. So I can just download the tar file; it's very common, and you can just by just running this one command, you can compress the file. So the Hadoop packages that are available on Apache's website, right, that would almost be around two to three GB, but you, the compress format will only be around 100 or 200 MB. Okay, same thing can be set for uh something like Tomcat, if you're, you know, downloading the Tomcat package or nagios. So anything like that, so those packages would have a lot of MB, and to download them, you will need to compress them, right? So because the lesser you download, the more you save on bandwidth, so it's also easier to transfer them in a compressed format. So for transferring, especially, you use these tar files. Okay, you compress them into tar format, and then later when you're done downloading, you can extract them and bring them to regular file format. So I'll show you how that is done. So uh first of all, let me go to my terminal and uh let's go to the documents folder. Okay, I'm here; I'm doing an ls; we have this. So what I'm going to do now is I'm going to say ls -l. Okay, when I run this, you can see the different files and the size. Okay, you can see that the LMS folder, right, the nms folder here, it has, it's the highest; okay, it's uh it's showing its 44096 MB. So what we can do is I'm gonna show you how to compress this and convert it into a tar file. So to convert it into a tar file, you gotta say tar -cvf. Okay, x is when you're trying to decompress it, but cvf is when you're trying to comprise it. So you're going to say tar -cvf, and then here comes the tar file name. So what you want to be the name of the tar file? Okay, so I just want to have it as lms.tar. Okay, so this is the name of the file I want to keep, so I will put that here, and then you go to specify the file which you want to compress, whether it's LMS or whether it's in the folder. So I want to do it for LMS, so I can just say LMS. Okay, and when I run this command, then this particular document would have been compressed and it's present. Okay, so if I do an ls now, you can see that there's an LMS folder and an LMS.tar file. Okay, so this is the compressed version of this folder. Now when I do an ls -l command, you see that there's a new tar file that's created, okay, lms.tar, and then you have this folder whose file this one is. So that's how simple it is, guys, and uh what you can do now is if you uh you can just transfer this file over FTP or via SSH or, you know, just upload this to your internet and let people download this because this is a smaller file compared to this proper folder. Right now uh in case you want to uh extract a file, so in case you have downloaded this kind of a tar file, okay, from the internet, how will you untar what is the package to uh, you know, decompress it? So to answer that question, I can, we can give the command tar -xvf and the package name. So in my case, it's lms.tar. So when I just do this and when I hit enter, then that package would get extracted. So now if I do an ls command, you can see that this particular tar file has been extracted, but you can't see two different folders because the existing LMS folder has been rewritten. Okay, so it has been uh well, let's just say it has been overwritten, and that's why you can't see two different files, but yeah, as you can see, this was the process uh which was taken to untar the LMS package. Okay, so that's it with respect to the compressing and decompressing of files. So uh let me quickly go to the next topic in my slide. Okay, so the next topic is that of environment variables. So what are environment variables? I told you that we had to set the environment variables in the .bashrc file, right, while installing Java. So what are they? As the definition says here, environment variables control the behavior of the software packages installed in Linux. Okay, the path where the packages have been installed will be specified in the environment variables. So if you are installing Java, okay, and if there is some other application which needs Java, let's take the example of Hadoop. Okay, so Hadoop is basically a Java framework. Okay, so the mapreduce concepts, it's all Java-related, and you need Java to run Hadoop; otherwise, it will not run. Out of so by just downloading uh the Hadoop tar file from the internet and extracting that tar file is not enough. Okay, what you got to do is you got to download Java also and set the environment variables for both Java and for Hadoop. So in our case, when Hadoop is running because it's based on the Java framework, it would need Java to work, right? So at times it allows the runtime engine where is Java installed, so that only needs some commands to be run on Java. So at that time, when the runtime engine is asked that kind of a question, it will go to the environment variables and it will look for the path over there. Okay, so that was the environment variables I was talking about earlier. Okay, you go and set your environment variables in your .bashrc file, and your .bashrc file can be uh accessed by going to your home directory. From your home directory, just run gedit .bashrc. Okay, and here you can set your path. So if you've installed Hadoop recently, then you can just set the path of Hadoop over here, and if you've installed Java, then you can set the path of Java over here. So basically, whenever any other application wants access to uh some program, right, so it can get access by looking at its path from here. So that's what the .bashrc file is all about. Okay, that's what the environment variables are all about. So uh that was about the environment variables, and we have some of the most common environment variables are these. Printenv, so this will basically list or print the list of all the environment variables. Okay, all or almost all the environment variables; that's what this will do. And then when you say echo, you know, $HOME, this will print the path of the home directory of the user. So this uh HOME that you see here, this is a variable. Okay, and the path of your home directory has been specified over here. So whenever you press CD on your terminal, right, so it goes to the home directory, correct? So that is the home directory I'm talking about over here, and the path of that is what is set over here. So when you say echo $HOME, like I told you earlier, I showed you that echo will
Basically, print whatever arguments you give it; it will print it to standard output. Right? So, when you say `echo $HOME`, it will print the path of your home, whatever is stored in this variable. And similarly, when you give `echo $PATH`, then it will print the list of all the directories in which the shell looks for commands. Okay? And all those directories will be separated by your colon. Okay? So, you'll have multiple directories which you will get as a result, and they will all be separated by a colon. Okay? And similarly for hostname, uh, what was the name of your host of your system? Right? That will be printed when you give this because this again is a variable, and this is all set as environment variables. Okay? And then you have username; your username will be printed. So, and when we say `language`, it's basically the uh the language right in which the whole system works and can be either Chinese or can be English. So, in our case, Lobby English, right? Because we're all uh working on English, so it will all print either US English or UK English, something like that. And when you say `echo $BASH_VERSION`, this will print the version of this instance of bash.
Let's just go ahead and execute some of these uh environment variables. Okay? I'm just going to clear the screen and go to `cd ~`; clear the screen. And first of all, let's uh put `$` or let's say `echo`. When you give `echo`, you have nothing. Okay? I showed you earlier that when you just put an `echo` and uh when you say `hi`, you will get `hi` as return; the output will be `hi`. So, similarly, when you say `echo $X`, right? I said the path of x to 200 earlier. So, when when I say this, right? `X`, I will get the value of 100 now. And similarly, the path of home will already be set. So, if I just give `echo` and uh `$PATH`, then all the directories where the shell will look for to execute commands, those paths will be present here. So, scoop is located over here in this bin path and separated by a colon; we have the next thing. So, I have installed Pig in my system; so, Pig is installed here. Uzi is installed here; I was installed here. Okay? And similarly, uh, if you see Java, Java is installed here. Okay? And uh Hadoop 2.2.0, that's installed over here, right? And similarly, there are all the directories where your shell will look for; right? They will all be specified in this path. So, similarly, you have another command that is for uh `HOME`; this will print the home directory, and my home directory is `/home/iteraker`. You can also alternatively print your hostname, right? So, my hostname is `localhost.localdomain`. Okay? So, this is my hostname, right? So, my uh basically my hostname is `localhost`; that's what's being printed here. And when I say `echo` and follow that with `language`, okay, with a `$`, then it would print the language. So, this is uh using `en_US.UTF-8`; so, that's what this means. And in case if you want to print the list of all the environment variables, then you can just run this command: `printenv`. Okay? So, all the element variables uh there are there in your system; they will all be displayed here. Okay? So, that's it with respect to environment variables. Let me get back to my slides now and continue with my session.
So, going on to the next slide now, I'm going to talk about regular expressions. Okay? So, regular expressions or regex; they are used to search through data. It can be piped along with the `grep` command to find patterns of text in the file. Okay? Now, what this means is that you'll have multiple different files or you know multiple a lot of data and probably even one file. Okay? With the help of a regular expression, what you can do is you can search for patterns of that data. So, you can use the `grep` to search through data, and you can use the regular expressions to search through patterns of data; that kind of a pattern. Supposing you have a spelling mistake in the middle. Okay? Supposing the spelling of Apple is A-P-P-L-E, okay? And uh you know you might have made a mistake in one of the files; you have saved it as APLE. Okay? And you're not able to find when you're using Apple, avple, you're not able to find that actual string. Okay? Then it's you'll be wondering why you're not able to find it. Okay? Then you'll realize that okay it may be because the spelling that I've entered in the file, it's uh that might be wrong by mistake; out I've entered APLE. So, in that kind of a situation, you can use regular expressions to find patterns of text in the file. So, you're all aware of the pipe I spoke about earlier, right? You can use the pipe to use one operation's output as the input to another operation, right? So, you can use that, and you can use the regular expressions with the combination of `grep`. Okay? With the combination of `grep` command. So, we have a lot of regular expressions, and the most one of them are these. Okay? So, the dot here, it basically means it can replace any character. Okay? It can mean any character, the dot. So, and then you have the caret symbol here. So, the caret symbol here, it basically uh matches the start of the string. Okay? Now, what that means is, let me give you an example. Supposing you're doing a `cat 51.exe`; you're looking for uh some kind of data inside this `phylon.txt`, and you're using the `grep` command to search this data. `cat` basically lists down all the uh file contents; `grep` will search that data. And how will it search? When you give `a`, it will just display, you know, all the lines or all the words where `a` is present. But when you give a caret `a`, it means that the starting of the string starts with `a`. Supposing I have three different lines or three different strings in my uh document, in my file `one.txt`. Okay? Supposing I have ABC, uh AFG, and uh ADF. Okay? And if I uh give `^a`, then the result that'll be out would be uh given given back to me is those three lines because those three lines are starting with the character `a`. So, that's what this character means; it matches the start of the string. Okay? So, that's about caret. And similarly, if you want to match something with the end of the string, you can use the dollar symbol. And supposing you know that this particular word or string that you're searching for, it ends with `xt`. Okay? In that case, you can put `xt` and then you can suffix that with a dollar; then all the strings in that particular file uh you know which are uh all the all the strings in that file which are ending with `xt`, they will be displayed. Okay? So, that's how you can search for data. And similarly, if you give asterisk, asterisk basically means that the character that is uh you know preceding the preceding character is um it matches zero or more times. So, let's take an example of this. Okay? Now, in this case, we have uh `a` in front of the asterisk. Okay? So, the asterisk basically means preceding character matches zero or more times. Supposing I have two different strings in my file. Okay? One string is ABC, and the second string is DEF. So, then comes the asterisk. Okay? So, when you give asterisk, it basically means that the preceding character it occurs zero or more times. But uh however, if you give a question mark, it means that the character that that comes uh proceeding before the question mark, that appears exactly one or uh it can appear more times. Okay? And then you have uh you know these brackets here which can be used to group these regular expressions. Supposing you have, you know, more than one or two regular expressions, you can use them to group them. And uh again, the backslash, it represents special characters. Okay? So, let me uh just run a couple of examples of this for you. Okay? Let me go to my terminal and go to my home directory. I'm going to clear the screen; I'll go to `Documents`. Okay? So, in here I have my three different text documents: `automobiles`, `file one`, and `file two`. So, if I uh do `cat` and `automobiles.txt`, then I have a list of all these uh strings, right? I have the list of all the cars and bikes and the different automobile companies. So, what I'm going to do is uh I'm going to say `cat automobiles.txt`, and I'm going to use a pipe; I'm going to use a `grep` command to search for strings starting with the letter `a`. Okay? So, if I give `a`, then all the strings where there is `a` present, that will appear. Okay? Now, first let me show you without the regular expression. So, when I give `a`, then these are the strings where `a` is present. Okay? However, if I uh give `grep -v`, then it will list down those strings where `a` is not present. Okay? So, you might see `a` present in these two things, but the truth is it's looking for uh smaller. Okay? If you want a case-insensitive searching, then you can just use the `-i` also, all right? So, uh you can see as you can see from here in these four strings, `a` is not present, right? So, that kind of uh searching is what we need to do. So, I can use a regular expression to search for those strings starting with a particular character. Okay? By using the caret command. So, in if you take this example, so these are the list of strings in which `a` is present, right? So, in here, where is `a` starting? Okay? So, `a` is probably starting only in this one particular string. Okay? But maybe also over here, but because I haven't included the case-insensitive, so what I'm going to do is I'm going to remove this; would be once I'm going to print it. Okay? I'll just do a `ctrl+l` and execute it again. So, now if you see all the strings where `a` is present, whether it's a capital `A` or small `a`, those would be listed here. Okay? And now I can use a regular expression to uh basically filter out those letters or those strings which are starting with `a`. Okay? By specifying this command. Okay? So, I have to ideally get the answer; I should get is Aprilia, Audi, and Amber. Okay? So, when I hit enter. Okay? So, there's a space here; so, that's the problem. And as you can see, it says that there is no string that's matching with this `a`. Okay? Now, that's because I removed the `-i`. Okay? I removed the `-i`, which stands for uh case-insensitive searching. So, it basically returns that uh it's not returning any result here. So, that basically means the there was no search. But however, if I add a `-i`, okay, `-i`, and enter, then I will get these three as is my results because I have added the case-insensitive searching here. So, did your guys get this concept here of using regular expression of uh you know this caret? Okay? This matches the starting of the string. Now, I can do something similar; I can search for the end of the string. Okay? Now, let's see again if I use `a` itself, and if I give dollar, then it will look for all the strings which are ending with `a`. Okay? So, uh that's happening because of this problem; the whole `$a` should come inside brackets. Okay? I should be in uh quotation marks. So, that's the thing. So, when I do this, I'm not getting any result. So, uh similarly, I can execute another command. Okay? So, another one involving regular expressions of asterisk. So, what I'll do is I'll say `grep -n`; let's say I want to search for the character `a` itself. Okay? So, uh when I say `a*`, so it when when I use this asterisk, it basically means zero or more occurrence of `a`, correct? So, I'm going to search for that from here, and then I have to specify the file name over here. So, I'm not using any `cat` command, and I'm not using a pipe to get data in over here. Okay? So, I'm just going to display the number of times that happens by specifying the file name here. I'm going to say `automobiles.txt`. When I hit and enter, I get all the occurrences where 0 or more times `a` is occurring. Okay? So, that is uh one aspect, and uh the other command that I can show you is that of with respect to `echo` itself. So, I can run an `echo` inside flower brackets; I can say `A-Z`. Now, when I print this. Okay? Sorry, there should be just uh two dot symbols. So, when we say two dot symbols, it basically fills the characters, the sequence of uh a, b, c, a, b, c, e, f, g, h, uh you know the entire alphabetical sequence that will happen, as you can see. So, that's because there were just two dots specified, but had there been three, this won't happen. Okay? It would just display this uh whole uh thing again. So, the thing you want to note is that the regular expression that we are using here is uh this one: two dots. Okay? So, similarly, you can replace it with even numbers. So, we can have `89`, and you can say `33`. So, from `33` to `89`, all the numbers will be uh you know the sequence of the numbers would be present here. They can also have combinations like, you know, I can have uh say `p` over here, and I can have a name over here. Yeah. When I do this, the combination of `a` with all of these uh numbers would be visible. So, as you can see, so `a33b`, `a34p`, so things like that, right? So, patterns are also being generated. So, that is the advantage with uh some of these uh regular expressions. Okay? So, I'm just gonna clear the screen now and uh go on to the next topic. Okay? So, we are done with regular expressions now, and uh this takes us to the final part of this uh Linux demonstration. Okay? This next webinar, and here we are going to talk about processes, adding users, and SSH. All right? So, let's get started. Okay? So, uh guys, the processes is something that's really important from the administration perspective of Linux. Okay? Well, it's I mean it's basically something that's necessary, not more than you know an important thing; it's most basically necessary. I mean uh you should know what this is. And when I say processes, I'm pretty sure that you know that we are talking about the programs or instances of programs, right? So, uh anything that you start on your system, so whether you're starting a web browser or whether you're using a media player, so everything, every software there, it will have process involved. Okay? There can be multiple instances of that particular project. Uh, supposing I'm viewing a presentation on my computer. Okay? Supposing I'm seeing five different presentations at the same time; I mean I can see only one at a time, but I can have the remaining open, and I can put them in the background, right? So, uh that's what we mean. So, the different instances of that particular system can also be considered as a process. So, at any point of time, only one application or only one process will be in the foreground. Okay? But many such uh instances of many softwares or also of that particular software or program can be present in the background. Okay? So, the example of that is uh me opening uh two Chrome browsers. So, I can have two different Chrome windows, and uh you know one can be in the background, one can be in the foreground. Okay? So, similarly, PPTs or whether it's a media player, anything like that. So, that's what a process is. Okay? Now, going by definition, an instance of a program is called a process. All right? Any command given to the Linux kernel starts a new process, and there can be multiple processes of the same program. They can be multiple processes. When we say processes, it basically means instances. So, we can have any number of instances of any of your application, right? Of Chrome or of VLC media player, of all those things; you can have multiple such instances at the same time. And all these instances are referred to as processes. Okay? Official term is uh processes, and each of those processes have some process ID. Okay? So, uh yeah, like I told you, they'll be divided into two different processes: one is the foreground processes, and the other one is the background processes. Okay? So, uh how will you determine what are the different processes that are running in your system? In Windows, you can just do `ctrl+alt+delete`, and then you'll get the list of programs, right? And you can even terminate them; you can end the programs from there, right? So, you have different tabs. So, let me show you an example of that. Okay? So, this is my Windows system. Okay? And when I do `ctrl+alt+delete`, it starts my task manager, and it asks me for applications or processes and all these things. So, this is the process that I'm talking about. Okay? You can have any number of processes running in your system. Okay? You might not be aware of all of those things. So, yeah, anyways, some may be started by you, and some may not be started by you, right? Some may be started at system boot, and some of those uh processes might be started by you when you're running some command. So, that's what this is. So, every time you specify uh you know a command in the terminal or the kernel, that will boot a program or a software, and that will also alternatively start a process. Okay? And every time you start it, you will have a new process to find it. And if you want to see the list of all the processes running in your system, then you can use this `top` command. Okay? And what you get followed by that will be be the list of processes and their PID, their user username, their priority, all these things. So, I will talk about all these aspects in some time. So, let me first show you the different things and how they look in the Linux in my VM. Okay? So, I'm going to run; I'm going to run the `top` command, and when you do that, you can see that you have something called as PID; we have user; you have uh PR; you have a whole taskbar; and you have with respect to which software is running, which program is running, what is the application name, and all these things. Okay? So, right here, you can't probably see anything that I have created on my own. Okay? Except for this VirtualBox client and maybe the terminal. Okay? But if you want me to create one, then I can also create one. So, what I'll do is I can just end this here by pressing `ctrl+c`. I can get out of this `top`, and what I'll do is I'll create a Firefox instance. Okay? So, Mozilla Firefox is installed in my system, and through my terminal, I will start Firefox. Okay? When I hit enter, my file Firefox has been initiated. Okay? See? Now, I did not make any change. Okay? I did not touch the Firefox icon, but instead of that, on its own, Mozilla Firefox opened. That is because I hit Firefox, and I put enter in the terminal. So, when I did that, the uh Firefox opened. Okay? Now, I can just minimize this, and if you go back to the terminal, you'll see that I'm still inside the you know the terminal is assuming that I'm still working on Firefox. Okay? I've still not ended Firefox for that. So, when I uh when I close Firefox, that's when I'll come out of the terminal over here. But instead of doing all that, I can simply do `ctrl+z` or `ctrl+w`. Okay? When I do `ctrl+z`, it means that I'm stopping my Firefox instance. Okay? So, whatever Firefox uh browser that was open, that has stopped; the process however would not be stopped; the process would be running in the background. Okay? Now, supposing I want to push it; if I want to bring it to the foreground, I can just say `fg`, and I can give Firefox. Okay? This will again uh initiate Firefox for me. But otherwise, I can just uh you know close it, and I can push it also to the background; I can say `bg`, and I can say Firefox. And if I give enter, then my Firefox has been pushed to the background. So, now what I'll do is let me run that `top` command again, and if you see over here, the Firefox was not visible. Okay? But since I started and pushed my Firefox to the background, and all since I've done all these things, my Firefox would be visible in this list of processes. Okay? Now, seems like I've sent it to the background, right? So, that's why it's not coming. So, let me uh hit Firefox again, and it's opened the ER terminal now, and what I'm going to do is uh of course it's in the background, so I'm
To run the top command again and show you that Firefox is here, so we have the Firefox here right. As you can see, there's a Firefox process that, of course, keeps moving up and down, and it's all sorted by the priority that each process has. Okay, so uh, yeah. So every single uh instant, or every single program or application that you start, right, so they will be started in this way, and they will have a process ID associated with them. They will have the time for how long they have been instantiated; they'll have the CPU memory they're using, the virtual memory they're using, and all these things. Okay.
So let me explain each of these things by going to my slide first. So if I go back to my slides, okay, as you can see here, these are the different blocks that you saw earlier, okay, on the terminal. So the first PID stands for the process ID. So each process that is initiated will have a unique process ID, okay. And the user here is uh the name of the user who started that process. And PR is uh refers to the priority of that process, because uh every process that is running in your Linux, it will have a priority associated with that, okay. And the greatest priority process is what will be executed first, and that will be executed at the top, and then so along with the priority of that process, you have the niceness value. So niceness value is again, you know, the value ranges from minus 20 to plus 20, and even the priority value, it varies from minus 20 to plus 20. Okay.
So basically, the nicest value is uh somewhere it's opposite to Priority, okay. So the lesser the nice value, the greater will be the priority of your uh process. You can also manually set the niceness value of your process to increase the priority. If you want to give a particular program or a particular process more priority, then you can probably decrease the niceness value, and uh that will lead to the increase in priority on its own. So that's what this is. And then after that, you have this VRT block, okay. So VRT stands for virtual memory; res stands for the physical memory; shr stands for the shared memory; s is the status of the process, so that's what s is. So s speaks about the status of that particular process, okay. And then percentage CPU is it is about the percentage of the CPU time, okay, and percentage of the memory of the physical memory that's being used, okay. And then you have the time block, which refers to the total CPU time that this process has been running for, and then finally you have the command, okay, and then fine. And then after the command, you'll have the process that is uh actually running, okay.
So uh let me just quickly go back to my thing here. So the command is basically the uh application that's running, okay. So yeah, that's about the different process. I'm just going to end this top by giving uh Ctrl Z. When I give up control Z, this stops, and I can just clear my screen. So that's about my processes, okay. Now uh I show you how the top command works, okay. Now along with that, if you want to see the list of all the uh processes that are running, okay, then you can see that by running this command: PS uh hyphen space ux, or you can do this, or you can even run PS hyphen PID. So when you do that, you will only get the list of processes that are being started by you, okay. So you are the user; I'm the user, and my name is Ed Reika, right. So all the processes which I have started, right, so all my processes will be visible. Of course, uh uh the other users' process will not be visible to me; it will be only visible for him, okay. So I can also give PID, otherwise ps pid. Okay, the PS ux it basically displays the process that you have started, okay. So you any any program or anything that you've started, that you can uh see it here. You can see, you know, what is the percentage of the memory that's being used because of that process, what is the process ID for that particular process, and all these things, okay. So uh similarly, if you have uh you know anything else, so that's what uh this command does, okay.
The next thing that I want to tell you is that of finding the PID of a particular process. So you know that we've started uh a particular process, okay, we started the Firefox process that time, and what I can do is I can find out the PID of that particular process by giving this command: PID off, and uh what is the name of the process? So in my case it's Firefox, so I'm just going to give PID off and Firefox. That will give me the PID of that particular uh process: 5836, okay. And I'm gonna clear our screen, okay. I'm gonna run the process again, okay. I'm going to start Firefox again, and when I do this, there is a new instance of Firefox that starts, okay. So a new process would have started by now, and uh when I just give Ctrl Z, I'm kind of stopping my process, and now if I give PS hyphen ux, then you can see here that there's a new Firefox process that starts that's running, okay. The ID is six zero six zero, okay. You can verify that by also giving uh by seeing what is the answer that I get if I uh PID off Firefox. When I do this, I get six zero six zero, so that is uh what this is all about, okay. And if you see the status, it's also showing as a TL, okay. This means that I've terminated that process, okay. So process of Firefox has been instantiated; it has a PID of 6060, okay, and uh you know if I want to kill this process, then I can give the command kill six zero six zero. All right, great. So that's about the different process that I want to talk to you about, okay.
So uh what's next is uh let me go back to the slides and talk about the next topic. All right. So I spoke about uh processes here, and uh the next topic is uh Pro—this is the management topic actually, and I'm going to tell you how to create your own users. So you can create users by this command, simply uh saying uh sudo user add and the username, okay. If you want to set password to that person, then you've got to say password and uh the username of that password, then it will prompt you to set a password for that person. And similarly, if you want to delete that particular user, you can say user delete and then uh the name of that username whichever you want to delete, okay. But one thing is that you got to always use sudo before that, because these commands cannot be executed by users like us, okay. We need a root access for that; we need only root users who have super user permissions can do this. So that's why we use the sudo, and we enter the password for it, okay.
Now uh one thing you need to note is that when a user is created, then by default he's also added to a particular group, okay. There'll be sometimes there'll be a default group to which that person will be added. And if you want to add a user to a particular group, then you can just do that by using the user mod command, okay. You can say user mod uh hyphen g—g represents the group—and then you can say the group name and the username. So the group name that you want to set and followed by the username of that particular person. Suppose you want to add your own groups, then you can do that by group add and group name, and then if you want to delete them, it's again the same thing, okay. After this process, then again you can assign them a different group, okay. So let me just show it to you on my terminal, okay. So the first command is adding a user, right. So before anything, let me just go to system, go to Administration, and users in groups. It asks for a password, okay. I'm giving okay. When you go there, you see that there are two users currently, so iteration. So these are the two users, and in groups again there are uh there are two groups here also. Now if I want to add users, I can add it from here, okay. I can just I can click on add user, and I can give the username, I can give the full name, password, and all these things from the GUI, but you know the CLI is a more simpler version where I can just supply a command, okay. So I'm gonna say uh user add space uh I can give the name of the user. So if I want to create a user for myself, okay, I can give this name using user add for them, okay. But of course it's not going to work, because it would say we need a suitable access permission tonight, right. So what I'll do is I'll give sudo access. It asks for the root password, and when you give the password, you don't have any arguments, so that means your user has been created successfully. So if you go back to system and administration, and if you go to user and groups, you'll find that there's a new user that's added, and the user ID is five, not two, okay. Now let me just minimize this for now. Uh similarly, if you want to set a password for this user, because right now it might not have a password, if you want to set a password, then you got to run this command: sudo password and the username. Username is version, so I'm going to do this, hit and enter. It will say changing the new password for the user, okay, and let's say the new password is this, and it will say retype the new password. I can give it here, and then the tokens are updated successfully, okay. Password is updated successfully. So that's what this is all about. So if I go back to this user window and if I click on button, then you will know that there's a password that's been added over here, okay. This is what I added from here, and you'll also notice that there's a new home directory that's created for that person. So all these things, right. Uh so that's about trading a user. Supposing you want to create a new group, then how will you do it? Uh similarly, just say group add. So I'm gonna say uh sudo and then enter this. So the group has been added successfully, and if I go back to turn the system under Administration under users and groups, if I go to groups now, even insd is something that's created. So this is something that got created now because as and when you create a new user, right, when you create a user without uh you know by specifying any group, then automatically is added to a group. So a group is created automatically when a user's created, and it's the same as the username. So that's how this got created, but anyways this is the new group. So I'm just going to do Ctrl L, and uh same way if you want to delete any users, it's again a very simple process. You can just do a sudo and user delete and the name of that user, okay. If I want to delete button, then I can do this. Yeah, so I'm not able to delete it right now because version is currently logged in. So if I just log off from this VM and if I uh login as button and log out from there, and then as a root if I execute this command, then I would be able to delete this user. The command is is very simple; this is the command, and you can all try it at home. All right. And similarly, if you want to delete any group, again the command is simple; it's uh group delete and then the name of the group that is uh insd, okay, which I created. So if you do this, the group I will delete it now, okay. Yeah, as you can see now insc is not visible, okay. So that was uh the previous window; I hadn't refreshed it. So now if you see ins is deleted. So that's how you delete the group, and that's how you delete a user. All right. So that's that brings us to an end to this topic. So I'm just going to clear the screen, and uh what I can do is I can just go back to my slides and get started with this final slide of mine.
So guys, uh this is the last topic for today, that is the the secure shell, okay. It's also called the SSH, and this is for gaining remote access of a system, okay. So you can get access to a system which is remotely located. So without you physically accessing that system, you can get access through this SSH server, okay. So that's what the SSH does, okay. It's called secure shell; the connection is called uh secure shell connection. So uh all the other topics in this session, right, today's session, they were all basic stuff which any user could learn, but this one, this SSH is something a little—it's a little advanced, and this is and this is with respect to networking, okay. You know, it's a thing that people would look forward to, okay. So if it's uh you know if you guys are waiting for a long time and if you're feeling bored in the session, then this is something that's going to be a little more fun. You're going to do something real time, and you're going to see something uh incredible happen here, okay, by pinging and accessing some other machine. So first of all, how does secure shell work? So we have two different uh systems, right, but in my case it'll be two different VMs, and uh in general it'll be two different uh systems which are remotely located, and you can get access to them by the help of this SSH. And how is that possible? By setting the IP address and all those things, right? You set the IP address, and in two different places you set one system as the master and you set the other system as the slave, and uh you basically what you do is you have something called as the ATC hosts, okay. So you go to this file and you set the master and the slave IPs over here, okay. You'll have to set up this IP for the master and this IP for the slave machine, and then you can do the ifconfig or the IP Adder show to list down the IP address of that particular machine. So if it's something other than what you want to set, then you can just do that by deleting the existing IP table, running this command in both the machines, and then to add an IP address to that machine, you can run this command. So to IP Adder add and the IP address you want to add, okay. So remember to set the mask for that, and when you enter this command, this particular IP address will be set for that particular node, okay. So that'll be the Master's node, and set this IP address for the slave node, okay. The command will be the same, but before that you got to delete the IP address, the existing one, by this command, and then add the new IP address at the same end with this command, and then simply just type SSH master or SSH slave, okay. So when you do that, your secure connection would be established, and you you see the username, then you realize that okay you're logged in into the different system, okay. That's what I want to show you now, and that's what I'm going to uh do it, but before that you might have some problems like firewalls and stuff like that, okay. If you have a firewall, you can still set up an SSH connection, okay, but the problem is you'll have to generate RSA key and all, and I don't want to do that because it's a little more complicated, and since you people are beginners, I just want to show you by turning the firewall off, okay. And to turn the firewall off, what you've got to do is you got to drop the ID table, okay. It will just stop your IP table, and this command will permanently disable your IB table. So this is with respect to Linux. So when you do these two things, then you can get started. All right. So uh let me go to my uh VM and show you what are the two different machines that I will be pinging to, okay. As you can see, so this is uh the VM which I was working on, right. So let's say cancel, and I'm just going to minimize this terminal, okay, and let me just close every other file and folder. All right, this is my terminal that's minimized. So if you can see here, you have something called as Master written, right. So this is the Master machine, and if I go back to my virtual box, you can see that this is the machine that's already running, okay. Now this is the slave machine which I will ping. So I need to instantiate this slave machine also, and even when you are bringing two different machines to remote machines or two machines in the same VM, then what you got to do is uh you know you got to turn on both, and you got to set the IP address in both the places, and then you got to ping them from there. So let's just wait until the slave opens. All right. When it's launched, we can start with our commands, but in the meanwhile I can just go to my master terminal and uh I can go to the terminal and start executing my aqui tables, okay. So uh let me check if my connections are all running. Let me click on this, okay. Now that both my uh network connections are on, so what I'm going to do is I'm gonna say ifconfig, okay. So when you do an ifconfig, you'll get this kind of an output, okay. So your at 0 is uh is your NAD address is your network address translation, okay, and your F1 in my case it's Ethan, but uh generally you people will not get a net one, because this comes when you're running a VM, okay. So I have set up a bridged adapter, okay, host only adapter actually between my two VMs. So I have a master VM and a slave VM, right. Yeah, since there are two VMs in the same machine, I need to set different IP addresses for both the VMs, right. So that's when F1 comes into the picture. Otherwise, in your case, if you're learning running Linux, if you run this ifconfig tab, then you will not get at one; you'll only get at 0, or you'll just get one option; you'll get L naught, and we'll get at zero, okay. And this L naught basically represents the entity address, okay. So this 10.0.2.15, this basically is your IP address which you need to use to connect to the Internet. So if you don't get an address over here, then it means you're not connected to the internet, okay. So that's what this means, and right now my uh F1 address is 192.160.56.2, okay. And similarly, if I go to my slave VM, let me just log in here first. As you can see from here, it's a slave VM, and if I launch my terminal, what I'm going to do here is I'm going to run the command ifconfig again, right. So right now it says that my uh okay, I don't have an inet address, okay. My network is not connected, okay. I have F1 connection, and that is 192.168.56.2, okay, but my NAD address is not set, so I think I'm disconnected from the internet. So what I'm going to do is I'm just going to click on system F0, and when I do this, I'll be connected to the internet now, and I'm going to run this command again, and uh now if you see I have the uh net address, okay. So this is my network address 10.0.2.15, and in in case of my master VM, 10.0.2.15 was again the entity address, okay. It's the same, but however the at one would have to be different, okay. I mean whether it's different or not, I need to change my uh F1, but now what matters is I need to ping my slave from my master, right. So I need to drop whatever IP address is there right now. So uh if this is the IP, then I have to drop this IP. So even in your case, by default there will be one random IP address. You can drop that IP address by uh running one of the commands which I showed you in my slides. I'll show you that again. Similarly, you got to do the same thing at even your Master's end; you got to drop the IP with the F1 IP address, and when you when you've done that, you can set your new IP address. So you will be setting two different IP addresses, one for your master and one for your raw slave, okay. This will be setting one over here in this VM.
and you'll be setting one over here, and that address will be over here. Okay, so I'll make my slave as 192.168.56.3. Okay, so I'll drop this one and I'll update it as uh, dot 3. And in fact, Master can be the same 192.168.56.2; it can be the, you know, the IP address of my uh, Master Slave. Okay, so I'll use these two things, and once I add these two IP addresses to the ATC/hosts file, then I can start bringing them. Okay, I can start pinging them, and I can get remote access to them. All right.
So what I'll do is I'll first clear the screen and I'll go to my slave, and again I'll do the same thing. I'll I'm going to clear the screen now, so going back to my uh, VM, the First Command that we got to run is we got to drop this particular IP address. So to delete the IB address, we have this command uh, sudo IP adder delete, and then whatever the IP addresses. Okay, so here this was the IP address, right? I'm going to drop the F1 address, so what I'm going to do is I'm going to put this here; I'm going to say Dev at one. Now when I hit enter, this particular IP address will be dropped. Okay. Okay, this is the password. Okay. Now if I again run ifconfig, you can see that I don't have an iPhone address; that's because I dropped it over here, correct? Let me just show it to you; that's because I dropped this particular address. Okay.
Now similarly, let me run the same command in my slave also. The command is IP Adder delete; the IP address over here is uh, 192.168.56.2. Okay, so this is the same here also, so I'm gonna just paste it here and say Dev that one. When I go enter, okay, I need to give sudo, so that is a problem, so I'm going to give sudo ipadder; it asks for the password, there you go, and uh, yeah, my IP address has been discarded. Okay. Now if I again run the ifconfig, you can see that F1 again does not have any IP address. Now what I need to do is I need to set my own IP address over here, so let me first set the app address over here itself in my uh, this slave VM. So to add the IP address, the command is almost the same, except that instead of delete, you will have to put add, okay, and you'll have to specify the IP address you want to set. So I want to set 192.168.56.1, not two. Okay, I'm going to say that one or two, and then I need to give a mask, so if you remember I told you that we need to give a mask, so it'll be /24, or let me give 103 because it's the slave, right? I can give one or three here, 103 24. When I give enter, the IP address will have been added. So if I do the if config now, you can see that F1 has this address 192.168.56.1, not three; this is what I added sometime back, right? This is what I added here.
Now similarly, I'm going to go back to my master VM, and uh, I've deleted the IP address from here; I need to add the IP address here, the new one. Okay, so the command is ADD 192.168.436.1, 1 not 2 / The Mask that's 24, give enter. Okay. Now let me check the ifconfig; as you can see the IP address for my F1 is there; it's up and running. Now it's 192.168.56.1.2 over here in this case. Okay. Now I've now that I've done this, uh, there's one more important thing that I need to do; I need to add my IP addresses to the ETC hosts file, which indicates to both the VMS where the master is and what is the IP address of the master and what is the IP address of the slave. Okay. Now that I've added this one, so let me just copy this address; I'm going to copy this, and I need to set this address of the master and similarly the address of the slave in the ETC hosts file. Okay, how will you access the ADC/hosts file? You need to first go to your home directory, and from here, okay, let me clear the screen, home directory. So here you got to give a pseudo G edit /Etc/hosts. Okay, when you hit enter, you'll open this file. Okay, this file is called the host/ADC file, so in here, you know, I've already set my IP addresses. Okay, now I can just delete it for namesake, and I can just copy uh, paste what I had copied, so it was 192.168.56.1.2; this is the IP address of the master which I wanted to set, correct? If you see here, this is the app address that I added now, and I'm adding this IP address dot 1.2 to the host; I'm going to add that as master. And similarly, if I go to the slave, the IP address is 192 168 56 and one not three. Okay. Now I need to go to the EDC file, and since that is a slave, I got to set the IP address for the slave, and of course, even the slave IP already set, but I'll just update it and save it anyways. I'm going to save this, and I'm going to close this. Okay.
Now uh, similarly, I need to go to the slave VM and set these two IP addresses. Okay. Now again the command is go to CD and uh, go right pseudo G edit /edc's/hosts. Okay, so here also the RP address is set to one or two and uh, one or three. Okay. Now this is the slave VM, and the IP address of this machine is 103, and the master is one or two. Okay, that's the other VM, so uh, I mean it's the same, so I don't need to make any changes here; I'm just going to close this; yeah, I can just close it without saving. Now uh, now that I've done this, I can straight away start pinging or get SSH connection. Okay, I can just say, since this is the slave, I can say SSH space Master. Now since I've added the IP address of the master in the host table, I don't need to specify the IP address of that particular system; I can just say SSH master, and if I put enter, then it will ask me for the Master's password, and the other vm's password is what I'm going to put here, and when I put enter, as you can see I'm logged in now, so the password has been entered, and you can see the last login here. Okay, so the last time I logged in was on this date, and I logged in from this slave itself, okay, from this particular VM itself. So uh, to prove that this is the actual Master, what I can do is I can just go to CD and I can do an LS command. Okay, I can go into any of these desktop or the downloads or the pictures uh, folders, right? Because I made quite a few changes in my Master Slave, and from the Master Slave is where I showed you the earlier files, right? I created the automobile.exe, the fileone.txt, the file 2.txt. Okay, if you can remember, then my documents has these contents; okay, it has folder one, it has automobiles.txt and all these things, so I can just add the same to my slave, so I can just navigate to desktop, and if I do an LS, I get the list of all these things. Okay, so as you can see there is uh, the automobile.txte and the readme file in my downloads folder. Okay.
Now let me go to my uh, master, so in my master if I go to downloads, I have these two files. Okay, so this is what I mean when I say remote access; so these two VMS are communicating with each other such that the slave is accessing and it's running commands inside the master, and whatever is visible over there I get x2 here. Supposing you want me to uh, you know, open another file. Okay, so the music folder has these three files, right? So I can access these also; I can just say CD and go back one path and say I wanna change the music. So when I go here and network analyze, I have automobiles.txt, file1.txt, and file.txt. So basically these three text files are present in the other VM, in the other machine. Okay, they are present over here; however, they're not present in this machine. If you want me to prove that they are not there in this machine, then I can just minimize this, go to uh, in the file directory, go to music. Okay, it's empty, so this basically means that I'm accessing the master VM from this slave VM. Okay, alternatively you can also check the downloads folder; there's nothing here either. So yeah, that's how we log into the remote machine, and in my case I've logged into slave from my machine, and I've accessed these folders. Okay, I can also view these uh, contents in this folder by going to catautomobiles.txt, and when I hit enter, whatever data set that I created earlier in the session, right, couple of hours back, so those are visible over here. Okay, so that's it. So another thing is that if you want to exit from your Masters machine, right, if you want to exit your SSH shell, then you can just hit exit. Okay, when you hit exit, it says log out. Okay, connection to master is closed. So this shows that now we are back to your own VM, and now if you uh, try going to CD and if you go to music or something, you'll not find any documents or any folders in that particular directory; that's because this is your VM, this is the slave VM. And similarly, I can just uh, you know, from my Master's VM also I can get access to the slay VM by just uh, typing in SSH and slave; the password is this, and this is the last name that was logged in, and uh, I'm here. If I go to CD music and if I do an LS, there's nothing available here. Okay, that's because uh, the slaves VM does not have anything in the music folder or anything in the documents folder, so that is the reason. Okay. And similarly I can exit from here by giving this command exit; it says it's logged out and connection to slave is closed.
Okay, guys, so this is uh, about the SSH, and this is about the secure shell connection. There is something called as the RSA key. Okay, now that is something that will get generated if there is a firewall. So in my case, I have blocked my firewall by dropping the IP tables. Okay, so the command to drop the IP tables are this one; they are service RP tables and stop. Okay, this will drop the applicable temporarily, and if you want to permanently disable the IP table, then you can just run the command sudo check config and IP tables off. So by doing this, your firewall will be turned off, and you can use the SSH Connection in the way I showed you. Okay. Now this is a very simpler way, but in case of a real scenario, okay, where the machine is located remotely, where you cannot actually disable your firewall, okay, because firewall is important to uh, block any unauthorized access, right? So firewall is important to be enabled. So in that case, if you want an SSH connection to be present in spite of a firewall, then there is another procedure where you have to generate an SSH key, right, an RSA key from the master's end and set that key at the slave end, so you have that kind of a process, and uh, that is something that's a little more complicated than this, and of course that I can't show you now, but I promise to show you that in my next Linux webinar. Okay, so if you guys promise to come back and miss me in that webinar, then I can prompt promise you to show to you there.
All right, guys, so uh, I'm uh, hoping that it's all fine; I'm hoping that you people understood the concepts here, and uh, it's been a good session; it's been pretty long, but it's been worth it, right? Uh, basically uh, hemant who's uh, new to computer science, he says that you know he's uh, got a lot of, you know, honestly he's understood illness well, and uh, yeah, he also says that he's gonna install Centos. Okay, that's good because even uh, this was sentos, maybe this is why you want to install Centos, but don't just keep yourself restricted to this Centos, hemant; you can also install Ubuntu and find out which one you like. So see, I like the Centos, and this is my preferred Linux distribution. Okay, so I recommend everything Ubuntu and Center OS to you; you can install them and uh, you work on them, and you will only figure out which is better for you.
So let's talk a little bit about the kernel and the shell. So what is a kernel? Now the computer programs that allocate the system resources and coordinate all the details of the computer's internals is basically known as the kernel. Now the kernel is the heart of any operating system; it interacts with the hardware and most of the tasks like memory management, task scheduling and file management. Now users communicate with the kernel through a program called the shell. The shell is that utility that processes your requests when you type in a command basically at your terminal. The shell interprets the command and calls the program that you want. The shell uses standard Syntax for all commands; it is basically a command line interpreter which translates commands entered by the user and converts them into a language that is understood by the kernel. And obviously the next logical question is what is a shell script? Since I spoke about the shell, it is only obvious that I'm going to mention the shell script. The basic concept of a shell script is a list of commands which are listed in order of execution. With that, let's move on to our next topic, which is evolution of the shell. So let's begin with a short history of the modern shells and then explore some of the useful and exotic shells that are available in Linux today. All right.
So the shell or the command line interpreter have a long history; with this discussion begins with the first ever Unix shell. Ken Thompson of bell Labs discovered the first shell for the Unix called the V6 in 1971. Now similar to its predecessor, this shell was an independent user program that could be executed outside the kernel. Now I'm not going to talk about the Samson shell; we are going to begin our journey with a look at the modern shelf since 1977, when the bone shell was introduced. Now the bombshell created by Stephen Bourne at the atnt Bell Labs remains useful even today. The author developed the bone shell after working on an algol 68 compiler, so you'll find its grammar more similar to the algorithmic language than other shells. Now the source code itself, although developed in C, even made use of macros to give it the algol 68 Flavor. Now the bone shell had two primary goals: to serve as a command line interpreter to interactively execute commands for the operating system and for scripting. In addition to replacing the Thompson shell, the bond shell offered several advantages over its predecessors. Now the bone introduced control flows, loops and variables into scripts, providing a more functional language to interact with the operating system system. Now the shell also permitted you to use shell scripts as filters, providing integrated support for handling signals, but lacked the ability to Define functions. Finally, it Incorporated a number of features that we use today, including command substitution and here documents to embed preserved string literals within a script. Now the bone shell was not only an important step forward but also an anchor for numerous derivatives, many of which are used today in typical Linux systems.
Next we have the seashell, which came in 1978. It was created by Bill Joy while he was still a graduate student. It has been widely distributed beginning with the two BSD release of Berkeley software distribution. The seashell is a command processor typically run in a text window, allowing the user to type commands. Now the seashell can also read commands from a file called a script. Like all Linux shells, it supports file name wildcarding, piping, here documents, command substitution, variables and control structures for condition testing. What differentiated the seashell from others, especially in the 1980s, were its interactive features and overall style. Its new features made it easier and faster to use; the overall style of the language looked more like C programming language and was seen as more readable. Now another Improvement that we saw on the bone shell was the corn shell in 1983. It was developed by David Corn off Bell Labs again as a comprehensive combined version of other major shells that were present at at that time. The initial development was based on the bone shell source code. Now The Conch Shell is Backward Compatible with the bond shell and includes many features of the seashell as well. Now The Conch Shell compiles with posix2 shell and utilities. Major differences between the corn shell and the traditional Bond shell include job control, command aliasing and command history that is designed after the corresponding seashell features. After the cone shell, we have the 10x seashell, which was a derivative of your basic seashell. Now this shell in 1983 was essentially the seashell but with programmable command line completion, command line editing and a few other features. Then we have bash, which Still Remains one of the most popular shelf even in today's time. Now this was written by Brian Fox for the gnu project as a free software replacement for the bond shell. It had been distributed widely as default login shell for most Linux distributions and Apple's Mac OS. Now The Bash can also read and execute commands from a file. Like all Linux and Unix shells, it supports file name globbing, piping, here documents and command substitution. The keyword syntax and other basic features of the language are all from the basic shell. The Shell's name is an acronym for Born Again shell, a pun on the name of the bone shell that it replaces. The Bash command syntax is a superset of the bone shell command syntax; it supports brace expansion, command line completion, basic debugging and exception handling using trap. Now it can execute the vast majority of shell scripts without modification with the exception of the bond shell scripts tumbling into Fringe syntax Behavior. The Bash command syntax includes ideas drawn from The Conch Shell and the seashell as well. After that, the world came across various other shells such as the public domain con shell, which was basically a public domain or a free version of the Corn shell. You had The Alchemist shell, then you had the extensible shell or the Plan 9 shell. Today we have many other shells, namely your Z shell, your dbn armquist shell or the dash shell and the mere BSD cone shell. In this segment I am going to majorly focus on four shells which will give you an idea of all the other derivative shells as well. I'm going to be talking about first the basic shell, the bone shell; I'm going to talk about the bone again shell, the cone shell, the 10x seashell and an exotic shell called the scheme shell.
Moving on, let's talk a little bit about Shell versus bash. Now most people use these two terms synonymously, but they are not the same thing. Now the shell command language is a programming language which is described by the posseck standard; it has many implementations including the bash. Now because shell is a specification and not an implementation, the /bin/sh is a Sim link or a hard link to an actual implementation on most of the posix systems. Now The Bash started as a shell compatible implementation, but as time passed it has acquired many extensions. Now many of these extensions may change the behavior of valid posix shell scripts. So by itself bash is not a posix shell; rather it is a dialect of the posix shell. So summarizing about this, I would say that shell is actually a specification of which bash is an implementation. For a long time, the shebang line of the shell script used to point to The Bash on most Linux systems; as a result it has become more safe to ignore the difference between the two, but both of them are pretty much different things. With that, let's look at Shell versus bash versus a few other Linux shells. First of all, the seashell. Now if you are a network or systems administrator in a Linux or Unix environment, you will most certainly run into the seashell, so it is good to at least have some familiarity with it. Now casual users and even most developers will probably suggest other shells, but if you are comfortable with C programming language, then the seashell is a great shell to begin with. Now The Conch Shell is the one that you can use interactively to execute commands from the command line or programmatically to create scripts that can automate many computer maintenance and system administration tasks. Now bash is far to bigger subject to be covered fully in a single line, but it is one of the most commonly used scripting languages that you will find today; people are comfortable with.
Bash scripting, and most of the content that you will find around shell scripting, will be in bash. But you should probably learn it for its versatility and ease of use more than anything. Most colleges and universities teach their students to script in Bash because it's a great place to begin as well. So now I'm going to run the same script in three different shells, which are derivatives of the three most basic shells: your Bourne shell, your C shell, and your Korn shell, to see how different or similar they are.
So for that, I have opened up my terminal. This is CentOS 7, the Fedora version. So what I'm going to try to do is take a single argument, which is going to be a directory name, and my script is supposed to search recursively for all executable files in that directory along with the number of files that are found. I'm going to reuse the script design in each of the examples to illustrate the differences.
So first, let's see what directories do we have. Okay, so what I'm interested in is this Eclipse directory. So what I'm going to do is, okay, this is one file, Java oxygen. Let's see if it's executable or not. Okay, as we see, the Java oxygen file is executable. So when I pass Eclipse as an argument—this directory as an argument—to any of my scripts, I am supposed to get an answer that this Java oxygen file is executable and the number of executable files found in that particular directory is equal to one.
So first, I'm going to run the 10x shell and see. So I'm gonna go and open up this 10x shell. So basically what I did is open up my 10x script. It's divided into three basic sections. First, note that I use the shebang symbol to declare this file as interpretable by the defined shell. This allows me to execute the file as a regular executable rather than precede it with an interpreter binary. All right, it maintains a count of the executable files found. So I initialize this count with zero here.
So the first section—this section right here—tests the arguments passed by the user. This argv variable represents the number of arguments that are passed, excluding the command name itself. Now you can access these arguments by specifying their index. For example, if I say this #1, it refers to the first argument. The script is expecting one argument; if it doesn't find it, it emits an error image. So using this $0, I'm going to indicate the command name that was typed.
Now let's come to the second section. This basically ensures that the argument passed in was a directory. The -d operator here—the hyphen d operator here—returns true if the argument is a directory. But note that I specify a not directory sign here—this exclamatory symbol—which means negate. Now this way, the expression says that if an argument is not a directory, you emit an error message, which is the one. And for the final section, it iterates the files in the directory to test whether they are executable. I use the convenient for each iterator, which loops through each entry in the parentheses—in this case, which is the directory—and then tests each as a part of the loop. Now this step here uses the -x operator to test whether the file is an executable. If it is, the file is emitted and the count is increased. I end the script by emitting the count of executables here.
Okay, so now that we have understood what the script is, let's go ahead and run this. And then I'm going to try eclipse, and as we had predicted, it says that Java oxygen is your executable file and one executable files found. Now let me clear this out for you.
Next, let's try doing the same thing with our Korn shell. Now this is the code. Now, as you can see, our shebang line immediately—it's different. Now this Korn shell is a derivative of the Bourne shell, and it looks so much more similar to it than the C shell. So let's look at our example again. Now the first thing you'll notice here is its similarity to the first code that I had put up. Let me open it side by side for you.
Okay, so what I'm gonna do is I am going to open another new terminal. Let me just open another tab right here, another new window, so I can basically show you the similarity between both of these. So I'm going to go ahead and okay. Now we have these two on both sides. So the first thing you'll notice on your Korn shell script is its similarity to the 10x shell script. Structurally, the script is almost identical. The first, second, and third parts of the script: you have your test arguments, then you have your ensure argument which is a directory, and then you iterate the directory to emit the executable files. But the key differences are evident in the way conditionals, expressions, and the iteration is performed. For example, instead of operating C-like test operators, the ksh adopts the typical Bourne style operators. So here you can see this not equal to versus here, this not equal to. Now the Korn shell also has some differences related to the iteration. Now in the Korn shell, the for in structure is used with the command substitution to represent the list of files is created from the standard output of the command LS, representing the contents of the name subdirectory. In addition to the other features defined here, the Korn shell supports the Alias feature to replace a word with a user-defined string. Now the Korn shell has many other features that are disabled by default, such as file name completion, but you can enable it if you want to. So let me close this.
So let's try running this file, and let's put in eclipse again, and as you see, the answer is the same.
Finally, we are going to try the same thing using the bash, or the Bourne Again shell. Now the Bash has continued to evolve with new features, support for regular expressions and associative arrays. Now, although some of these features may not be present in other scripting languages, it's possible to write scripts that are compatible with other languages to this point. This script that you see here is identical to the Korn shell script except for the shebang difference. Let me open the Korn shell real quick and give you a side-by-side comparison on this.
Okay, so as you can see, it's pretty much the same except for your shebang line, which obviously has to be different because of where they are pointing. One key difference among these shells is the licenses under which they are released. Now the bash, as you would expect, having been developed by the GNU project, is released under GPL. But the C shell, 10x shell, Z shell, and so on are released under BSD, in BSD-like licenses. The Korn shell is available under the Common Public License. But apart from that, as you can see, the way you write the script in bash and Korn shell is the same except for their shebang line. So let me just run this and show it to you, and as you can see, the answer is the same.
Now my point being why I chose these three specific shells is that it will give you an idea of how all the other derivative shells work, more or less. It's going to be similar to these three basic shells. The logic will always remain the same. Would that let me move back to my presentation?
Now, apart from these, you can go ahead and pick the shell you like. Many of the ideas and much of the interfaces of the shells remain the same, almost 35 years later—a tremendous testament to the original authors of the early shells. Now, in an industry that continuously reinvents itself, the shell has been improved upon, but not substantially changed. Although there have been attempts to create specialized shells, customized shells, the Bourne shell derivatives continue to be the primary shells in use.
For requirements, you should have a system with at least a 2 GHz dual-core processor or better, a system memory of 4 GB or more, and a recommended free disk space of at least 25 GB.
Now let's look at the software requirements. We are going to be doing this on our system with Windows 10 installed. Also, we are going to use a tool called VirtualBox. Alternatives to this also exist, like VMware, but we will be using VirtualBox here. Also, it is important that you enable virtualization in your BIOS settings for the PC; otherwise, VirtualBox won't run. So let's move on to the demo part. Setting up the Linux VM on our system has two major steps. The first thing for you to do is download the VirtualBox utility, and second is to download Linux. We will be using Ubuntu here, which is a very popular Linux distribution.
So let's first go ahead and download VirtualBox. Open the link and go to your download section. As I am having Windows here, I'll click on this, and then my setup should start. Now I'll just cancel this setup because I have already downloaded the file before. Now as you can see, I have my file here. And the other thing for you to do is to download the Linux distribution. So to do that, type in Ubuntu download. Here you can download the latest Ubuntu, and as you can see, it has the recommended system requirements over here, which we talked about before. To download the Ubuntu, you click on this download button, and soon enough, the download should begin. Now the download process starts, but I have already downloaded this as well on my system. So I have my VirtualBox over here with my Linux distribution here. So let's install VirtualBox first. To do this, open the setup and follow these steps.
Now we can start installing the Oracle VirtualBox. So click next and go with the normal location and continue clicking next. And this shows a warning here, but don't be worried about it; this won't have any issues. So click on yes and then install. Now that the installation has finished, let's start our VirtualBox. So now that the VirtualBox is now open, we need to create a new VM. So to do this, we click on this button, new, and we provide it a name and are provided up to 4 GB of RAM. Now I'll create my hard disk, and this will be dynamically allocated. Now that you have this setup, what you need to do is that you need to copy this ISO image and load it into our VM. So to do that, you need to click on settings here and select this. Now provide it with your file. So I select my Ubuntu here; this is my Ubuntu image, and I'll open it. Now hit OK and start the VM. Now let's maximize this, and here I'll select the first option. So because this is your first time doing this, it might take up to like two hours at max for you to set up this environment. Now click on install Ubuntu and follow along the instructions. Now restart your system. Now you should have a working Ubuntu system on your VirtualBox, and with that, the demo is concluded. In this way, you can set up a number of virtual machines on your system and continue your DevOps journey. [Music]
The first thing we talk about is the Linux directory commands. So what we'll do here is we'll take a look at each command and what they work like in Linux. So the first command is the PWD command, right? So the PWD command is basically used to display the location of your current working directory. Now, a directory is basically a file; you have to realize that everything in Linux is a file. So a directory is a file which contains other files as well, right? So the PWD command is used to display the location of the current working file directory that you have. Let's take a look at it. As you can see, PWD is the syntax for it, and it basically shows you whichever directory you have. Let's take a look at it, right then. So let's say you want to check out the directory for one of your files. So let's say we go to files and you open up the terminal, and then you type in PWD. So this is basically your directory; it is in home, and KB is the user, right? So this is basically what PWD does.
Moving on to the next command. So next up, we have the second command, which is the mkdir, which is basically make directory. Now, make directory is used to make different new directories under any directory that's already there. So let's say, for example, we've already seen that we are in the directory home, and if you want to make a new directory under any existing directories that are present in Linux, you use the mkdir command. And for the syntax of the command, you'll have mkdir and then your directory name, right? So let's say, for example, if you want to name your new directory, then you just have to write mkdir and new directory. So let's take a look at it, right? So you're already here in the terminal, and you're inside the directory, right, with PWD. So what we do here is you make a new directory, say mkdir, and let's say new. So now if you basically LS into it—we'll come to LS later—but if you LS into it, you can see there's a new directory that has been formed here. So this is the mkdir command.
So moving on to the next one. So the next one is basically another command called rmdir. Just like you make a directory, you can also remove a directory. So the remove directory command is basically used to delete a directory that you've already created. And to basically make that happen, you'll have to type in rmdir and your directory name. So let's take a look at how it works, right? So as you can see here, you've made a new directory called new dir. So to delete it, all you have to do is rmdir and directory, and this has been removed. If you cross-check it, you'll see that your directory is being removed, right? So this is how the remove directory command works, rmdir.
Moving on to the next command. Next up, we basically have the ls command. Like in previous examples, we used ls, right? So the ls command is used to display a list of the content that is present in the directory. So let's say you have a directory, which is the home directory, and you want to see what's present inside that directory. So if you just type in ls, it'll show you all of the files present in the present directory there. And for the syntax, you just need to type in ls, and you'll get all the files that are there. So let's just check it out. So suppose you want to check out the system files inside your directory. So if you go to your computer directory, you'll just type in ls in the terminal, and these are all the files that is present in this directory, which is the my computer, or Linux. Since there is no my computer for Linux, you'll have all these files, the system files that you have. So this is basically what ls does. So ls basically just displays the contents of the directory that's there. Right now, if you want to see which directory I'm talking about, I'm talking about this directory, which is computer, right? All of these files that you see, bin, boot, dev, etc., all you got to do is just type in ls, and you can see them. So this is the ls command.
So moving on to the next command. So the next command we see is basically the cd command. Now the cd command is used to change the directory that you're currently in, right? So if you go to the computer directory with all the system files that's there, just type in ls, and you can basically see all the files that's there, right? So you want to go into one of those files and check the contents of those files, right? You want to change the directory. Now these are subdirectories that are already present in the computer directory, right? So you just change directory to, let's say, bin, or library, or tab. So you just need to type cd, change directory, and the name of the directory, right? And you will basically get into that directory. So let's just check it out. So basically, guys, if you can go to the terminal, you see, right? Right now you're in the root directory. The root directory is always shown as a slash; it's a forward slash, right? So if you want to change to accessories, let's say, let's check out the directories that are there. Would check out the contents of your root directory? You will just have to type ls, and you can see these are the directories. So to change the directory, what you have to do is simply type in cd and choose any of these directories that you have. Let's say you want to get it to bin, and that's it; you're going to bin. Now your directory has changed from the root directory to the bin directory. Now the bin directory is a part of the root directory, so we have slash and then bin, but now you've changed your directory to bin. So this is the cd command.
So moving on. First we saw the Linux directory commands. Now we move on to the Linux file commands. So there are various Linux file commands. The first one we talked about is the touch command. So basically, the touch command is used to create empty files, and you can create multiple files by executing the touch command only once. For example, if you see here, you can create an empty file called file.txt, and you can also create two files in the same command. See? Now, as you can see, if you type in touch file2 file3, or whatever the name of your file might be, you can create n number of files at one go. So this is basically what touch is used for. And for the syntax, touch, basically, you have to write touch and then the file name. And if you want to make two or more files together, you can write touch and then add the file names one after the other. So let's check it out. So guys, I'll basically make a file in this folder called Linux that I have, right? So all I need to do is just—as you can see, there are other files as well—so let's see how we can create a new file. And all you have to do is open in terminal. So guys, as you can see, I have basically just cd-ed into this, and it's in the Linux folder, like we saw before. And we create a new file. Just to do that, you'll have to type touch and, uh, Eureka2, for example. And after that, you'll just have to check it out. So Eureka2 is basically a file that you've just created. Now if you want to create another file, for example, two files together, let's check that out as well. Let's first clear this out. So to clear your terminal, you'll just start typing clear, and that's it, right? So let's create more than one file together with one command. You have to type in touch and the name of your file, let's say mynameisoneone.txt onetwo.txt. So these have been created. Let's check them out. So as you can see, there are two files that have been created, and you can see that there's only one single touch command that I have used. So this is what touch is used for.
So basically, the next command is the cat command. Now the cat command is one of the most frequently used Linux commands, right? So the cat command is short for concatenate. Now what this helps us to do is it helps us to create a single or multiple files. So if you have created an empty file called touch, you can basically add content to it if you type in cat. So it allows us to create singular, multiple files, view contents of the file, concatenate files, and redirect output in the terminal of files. So what it does is you can copy the content of a file and put it in another, and we'll show that as well. So let's see an example of how cat works. And the syntax for cat is: if you want to create files, you know, files with content in it, you'll basically have the cat command followed with the greater than sign and the file name. And if you want to concatenate, basically copy the content of one file to another, you'll have to write cat and filename. So let's check it out. Through basically the cat command can be used like this. Let's say we want to insert something into the new file you've just created, you create recorder.one. So basically what you can do now is add content to it. So let's say hi, and basically get out of a tutor to do Ctrl+D, right? And that is you adding content to your file. Now if you basically check this and just write see, this is basically showing you the content of the file that's already there. And this command is basically letting you add content to the empty file that you created using touch.
So up next we have the next command, which is the rm command. RM is basically short for remove, and it is a command which is used to remove the file. And the syntax for that is rm followed by filename. So let's check
it out. So if you want to remove hell, you'll have to first go to the directory where the file is present. And then once you enter the directory, you'll just have to type in RM. Post that you'll have to type in the name of the file. For example, since I've recreated a file called correct one one.txt, if you put RM that, and it's just to cross check, correct one file has now been deleted. Now let's try this file as well, right? So if you just type in code, so since one one is not there anymore, you'll have correct one two.txt, and you do this and now check it, you'll see that coracoin2 has also been removed, right? So this is what RM does.
Show up next you'll have this CP command. Now the CP command is used to copy a file or a directory. Now all you need to do to use CP command is type in CP and type in the name of the files that you want to copy, right? So let's say you want copy a text file called into another text file called demo.txt. So all you need to do is type in CP and the name of the two files that you want copied into, right? The first name is the file you want to copy the contents of, and the second name of the file is the file you want to basically copy to. So let's check it out. If you basically go into the Linux directc that you have, that's basically a folder that I've created, and these are the files that are present in there. So you want to copy the contents of file file into another, all you need to do is type in CP and the name of the first file that is already existing, 1.txt and new.txt, right? And all you need to know here is you can go check the contents of the file after this, right? So if you go and check out new.txt, it's basically empty. Why is that? That's because edureka 1 is also empty, right? So if you basically add some contents, let's say hi and save this and shut it down, back again, go back to terminal and now let's check this out. Is it just copy? So you can just do this and check it out again, right? So if you go back to your file now and open up new.txt, this is the same content as your category carbon file. So this is what copy command does.
So moving on to the next command, the next command is the MV command or the move command. So the move command is basically used to move a file or directory from one location to another. So all you need to do to use the move command is basically type in MV, then the name of the file that you want to move, and finally the name of the directory you want to move it to. So let's check it out. So you're basically in the directory where you have your files. Now you want to move your file to another directory. So you have to just type in mv, the name of the file that you want to move, let's say you want to move new.text, right? So new.text and where you want to move it to, let's say documents, or let's say. Now if you basically now check it with ls, your new.text file has gone off to the documents folder.
Next up we have another command, which is the last of the file commands that you have. This is the rename command. Now the rename command, as you can see, is used to rename files. It is useful for renaming a large group of friends, and the basic Syntax for that is rename and then apostrophe s with the name of the old folder and then the name of the new folder, and after that you'll basically have to show which type of file you want it to be. So this is how you basically do renaming. So let's check it out. So you basically just type in rename command with the old text file, and basically you want to convert it to new text file, which is basically you want to convert it from a text file to a PDF file. So this is the command you given and then press enter, right? So you've now changed rename all the text files into PDF. So let's say if you ls into that now, you can see it's demo3.pdf, educator1.pdf, all these text files have been changed into PDF because the rename command. So this is how rename works.
Moving on to the next command, we've all checked out the Linux file commands. Now we move on to the Linux file content commands. So when it comes to file content, the first thing we can see is the head command. Now the head command is used to display the content of a file. Now the content of a file can be displayed with other commands as well, but the head command, how it's different from the other commands, is that it displays the first 10 lines of the file, and basically the syntax for that is you just have to write head and the name of the file you want to show 10 lines in. So let's check it out. So now if you check out the head command, let's say for example you type in head and basically the first 10 lines of a file that you want to check, let's check it out, right? So as you can see, the first 10 lines have been displayed. Now if you want to check the contents of that file, I'm going to show it to you. Yeah, as you can see, the first 10 lines are from 10 to 100, and the rest of the lines have not been printed. Should cross check back here again. So it's 10 to 200 with no other content. Let's see here. So head is basically something that is used to show the first 10 lines of your file, right?
So moving on to the next command. So next up, just like head, we have the tail command. Now the tail command is used to display the last 10 lines of the file content. Just like head is used to display the first 10 lines with file content, tail is used to display the last 10 of it. Now it is useful for reading error messages, right? So tail is basically something which is used, and after tail you just have to specify the file name. So let's check it out with the same file that we saw before, right? Then so just like head, let's just try using tail, right? And so the last 10 lines are these, as you can see. As in head, if you can see here, I'll just show it to you, edureka. So if you put head, you can basically see it's from 10 to 100, that's the first 10 lines of the file, but in Android 2 which has tail, it'll show you the last 10 lines of the file, right? This has no 10 to 60 here; it starts from 70. Now this is the difference between head and tail, right? So move on to the next command.
So up next we have a very important command, which is the tac command, right? So the tac command is the reverse of the cat command that we have used before. So it displays the file content in reverse order. So let's check it out, and basically the Syntax for it is just tac and then file name. So let's check it out. So if you want to see the content of your file, just type in tac and the name file that you want to see. As you can see, tac has basically displayed the content of this file in reverse order. If you want to check it out, you can again check this. So this is 10 to 150, and if you check here, tac educator 2 has made it 150 to 10, right? So this is what tac does.
Now moving on to the next command. So up next we have the more command. The more command is basically a similar command to the cat command, and it is used to display content the same way cat does. So the only difference between more or cat is that in case of larger file sizes, the screen full output is displayed. So for this I'll have to show you an example. Since we do not have many large content file, we can just check some of the files that we have checked them out. And the Syntax for more command is basically more and then file name. So let's check out the more commands, shall we? So let's basically check out the more command, right? So if you type in more and let's say, right? So when you have more, you basically type in more and then the name of the file. So this will basically display the content that you have in the file, and it's just like cat. Now the difference between cat and more is basically more is generally used for larger files, right? Files with large amount content, larger sizes. So this is basically all about more; will help you show the content that is there in the file, it's just like that.
So the next command is the less command. So the less command is similar to the more command but has some added features to it, right? So along with the fact that similar to the more command, the less command will show you content on your file, it automatically also adjusts the size of the terminal window that you are using, right? So the basic command for less is less, and then you'll have to basically have the file name. So let's check it out. So let's just check out what the less command is and definitely name. So this will basically give you the content that you have, the contents of the file that you have, and automatically reshuffled or adjust the length and breadth of the terminal later, right? So this is what less does.
Moving on to the next command. So after that we have the different Linux user commands, right? So when it comes to user commands, the most important is the su and the sudo commands. So the su command provides administrative access to another user, right? So in other words, it allows access to the Linux shell to another user. So let's check it out. And Syntax for it, that's very basic. So you'll just have to write su and specify the username, right, of your Linux system. So let's check it out. So all you need to do here is go to terminal and type it su and then the username. My username is KB, as you can see. So now you have to specify the password. So this is something which allows access to somebody else, right? If you type in su, so you can basically use their Linux system, right? You have been allowed access into KB's Linux system if you have password and if you know the username as well. So this is what su does.
So next up we have the id command. Now the id command is used to display the user ID and the group ID that you have. So you have a user ID for your Linux system, you have group ID for your Linux system, and the command for that is id, right? So let's check it out. All you have to do here is type in the word id, and you'll basically get your user ID and your group ID as well, along with the username. So this is what id does.
So next up we have the sudo command. Now sudo command, let's just show you. Sudo is something which is used extensively in Linux to give you access to files which need permission, right? User permission, administrator permission to access them, right? You need administrator permission to access current files. So how do you do that? Let's say for example if you go into the terminal for your computer, you go into this computer and you go into terminal and let's check it out, you do ls and then your cd into one of the directories, and all you have to do now is see the files that are there, right? So these are all the files that are there. Now if you want to access one of these files, these files are actually administrator protected, so you need to have sudo to basically ask for permission, which has to be granted by the administrator. So just type in sudo, then let's say, so to zip, and you'll have your password. So you, these are restricted, and basically as you can see, these are restricted because this is basically machine understandable language, and you can already see that this is basically what is there in the file, which is the zip file. So this is what sudo does. So this was a very important command that you needed to know.
So moving on to the next command. So next up we have the useradd command. So the useradd command is used to add or remove the user from the Linux server, right? So if you add or removed a user, you'll have to have special permission for which you'll have to use the sudo command as well, right? So you just write sudo and then useradd and then you add the new user. Sudo has to be because you'll have to have special permission from the administrator to do this. And the syntax useradd is useradd and then you basically add username. So let's check it out. So you basically want to use useradd, right? This is basically add user. All you need to do is add sudo and then the useradd command and the name of your user. Let's say I want it to be KB, right? The last few password, your new user has now been created. And let's move on to the next command.
So the next command is the passwd command, which is the password command. So the passwd command is used to create and change the password for user. So let's say for example you have to use sudo here as well. You have a user already present, and if you want to change password, just sudo into that user, type the new bar. So type retype the new password, and then basically it'll show you the password has been successfully updated. And Syntax for this is passwd and then username. So let's check it out once. So just type in passwd then KB, that is basically your user, right now. So we'll basically change the password for KB since it's already an existing user which has the password, right? So current password is already there, put your new password to be is, and you retype it, right? So the password has now been updated successfully, and this is how you basically use the passwd command.
So next up we have the groupadd command. So the groupadd command is basically used to create a user group, right? So when you create user groups, you'll also have to use the sudo command because you want to access restricted files, right? So the Syntax for groupadd is groupadd and then group name. So let's check out the groupadd command. So first of all you have to type in sudo and then groupadd and then group name. Let's say we name our group Edge 2022 and then password for KB which we've just created now. So now this group has been added into this user. So that was basically how you use the groupadd command.
Finally, you come to the Linux filter commands. Now there are various filter commands that Linux has. The first thing you can see is the cat command. Now the cat command is also used as a filter, right? Now filtering here means to filter a file. It is used for inside pipes. Now you basically filter out the content that is there. Now if you want to filter using that, you'll have to write cat and then the file name with cat or tag and then cat or tag again, right? So you'll have pipes in between, and you'll basically have the cat and tag add tag commands back inside pipes. So let's just check it out. So if you want to use the cat command as a filter, let's check it out. Type in cat home and then we'll basically have this which is the pipe and then the command tag then cat. Finally we have tag. So this is basically what the cat command does as a filter.
Next up is the cut command. Now the cut command is used to select a specific column of a file. So the -d option is basically the delimiter option, and the -f option is basically the column. So the -d option is used as delimiter and it can be a space or a slash or a hyphen or anything else, whereas -f is the column number. And Syntax for this is cut and then you put the delimiter, you put the column number and then you put the file name in the end. So let's check it out as well. So with the cut command, you'll just have, you type in cut, then you have the delimiter, after which you will have the -f and the file name in the end, right? So this is basically what the cut command does. It cuts out from a specific column and the specific column number. Since there is only one column here and we specified -f2, there is no cutting out. So if we do the same thing again and change -f2 to -f1, let's see how it's different, right? So this is basically what -f1 -f2 does. It shows you the column name, and it, it'll show you basically a specific part of the file that you want. You will cut out a part of that file and will show it to you, but since we have only column one, we'll show you just the calling one here, right? So this is what cut does.
Moving on to the next command. So next command is the grep command. So the grep command in Linux is the most powerful command, and it is used to filter the Linux system, right? Grep stands for Global regular expression print, right? So it is basically very useful for searching content from a pack, right? So for example, you need the syntax as basically command and then grep and then you search the word, right? So let's see how grep works. So let's check it out. Should basically check out how grep works. Let's check this out. Let's say cat and it will equal to, then you'll basically have this with grep 3. So this is basically every content in the file which is a Rika 2 which has the value 3 in it. So these are the two values which has three in it, and that is what grep is showing. So this is how grep works.
So moving on to the next command is the comm command. Now the comm command is used to compare two files or streams, right? So by default it for displays three columns. The first display is the non-matching Columns of the first file, the second for the second file, and third display is the non-matching columns for the third file. So the Syntax for this is fairly easy; it's just comm and then you specify the file names that you want, right? So let's just check this out. So if you want to check out how the comm command works, let's see this comm and basically add the two folders you want and the contents of it which you want. So these are all the files content that is there in both the files, right? Input is not in sorted order, but the file number one is not in sorted order, and so this is basically showing the content of all of the files that I've given, which is every tattoo and home and the content which it has, right? It displays it in three different columns. So this is what comm does.
Checking out the next command. So the next command is the sed command, right? So the sed command is short for stream editor. Now sed is used to edit files using regular expression. It does not permanently edit files; instead what it does is the edited contains remains only on display, and it doesn't really affect the actual file. So the Syntax for sed is basically the command and then sed with apostrophe s and the old word with the new word, right? So if you want to check it out, let's see. So basically for having sed, you'll basically have to show this stream editor. So this is the command for it. You have to put sed echo, and echo is basically used in Linux, and you basically have this thing printed called edureka 7, right? So as we can see, sed is used to edit files using a regular expression, right? So it doesn't really permanently edit those files, but it's only for view; you can't really change what's there in the content. So as I showed before, if you write class equals 7 with sed and change it in class, so this is just for view a to z7, what you see is for view; it hasn't really changed the content of it, right?
So next up we go to the next command, which is the tee command, right? So tee command, with tee command is similar to the cat command. The only difference between both filters is that it puts standard input or standard output and can also write them into a file. So let's check it out. Also the Syntax for tee command is the cat and then file name then followed with tee and then with new file and then
You have a cat attack, so let's check it out. So, as you can see here, the DE is basically putting in standard input, standard output, and writing the same thing. As you can see, image breaker 2 into the new 98 file as well. So this is what T does, the T command.
Moving forward, we have the TR command. Now, the TR command is used to translate the file content, like from lowercase to uppercase, right? So if you have some sort of content in a file which is in lowercase, you can change it to uppercase. The syntax for that is basically the command for TR and the old word to the new word, right? So let's check it out. So guys, when you're talking about the cat command, you'll basically have to write cat and the name of the file, followed with TR, which is translate, and then just replace the file with the old file, then replace the word from the old word to the new word. So let's say we have "hello" as the old word; I want it to be uppercase "HELLO", right? So it'll show me "Hello World", right? Go back to the file; now it shows you "hello world", right? So "hello world" is like this, and I wanted to basically make it uppercase. So this is what I have to do to make it uppercase: use the TR command.
Next up, we have the unique command. So the unique command is used to form a sorted list in which every word will occur only once, right? So the syntax for this is the command followed by the file name and /unique. So every command has to be there only once; there is absolutely no redundancy done by C. So let's check it out. So all you have to do for the unique command is basically type in sort followed by the name of the file you have and put in unique after that. If you do this, this is basically showing you everything in the content only once. So there is no redundancy; that's there; everything is unique. So this is about this unique command.
Moving on to the next command, we have here our final command, which is the WC command, right? So the WC command is used to count the words, lines, and characters in a file. So let's say if you want to count the number of characters you have in your file, just type in WC followed by the file name. So let's check it out. So finally, we come to WC. So what you have to do here is type in WC and the name of the file you want. Let's say you want home, right? So this is basically showing you the number of characters that the home file has. The home file has certain content in it, and that content has around 48 characters in it. So that is all about the WC command. [Music]
First, we will have a look at the Linux commands that are very basic. Like, even if you are not working in DevOps, if you have someone who's using the Linux-based operating system, you must be knowing these commands. These are the frequently used commands, like while you're working in DevOps. Okay, I'm just showing you the list; then we will practically see how to use this commands on the command prompt. So these are the few commands I've tried to cover; a maximum number of commands so that you're comfortable working with DevOps. So now let us try to execute these commands in a Linux-based system. So in my system, I have installed Ubuntu operating system. So let us start with the basic commands in Linux.
So the first command that you must know is the man command. Man stands for manual. Like if you want to know about any command in Linux, you can just type man space the name of the command. Say, for example, you have to know about LS; say, for example, just type man space LS. So LS is a command; we'll talk about it later. So just press enter. Okay, so here it shows the name of the command, its syntax, and the description, like if you want to know what it is and what it does. So you can use the man command for it.
The next command that you should know is the clear command. If you want to clear your terminal, just type clear and press enter. So this clears your terminal.
The next command that you must know is: say, for example, if you want to know where is your current working directory, for that there is a command called PWD, that is present working directory. Simply type pwd and press enter. Okay, so here it says home edureka. So this is my current working directory. And if you want to change your directory, for that there's a command called CD, that is change directory. Suppose from home edureka you have to switch your working directory to home, so simply type cd home. Okay, so if I now type pwd, it says home. So this was another basic command.
The next command is the echo command. Say, if you want to type anything, like if you want to print anything on the terminal, so you can use the echo command for that. Say, for example, echo hello world. So I have to print these two words on the terminal; for that I'll use the echo command. Okay, so it says hello world, pretty simple.
The next command is the su command. Let's see first who is the current user; for that there's one more command called who am I. Okay, so here it says edureka. So edureka is the current user of this system, the Linux system. So if you want to switch to the root user, who has all the permissions, as of now the edureka is not a super user; he doesn't have any permissions related to file operations or any other operations. So root is a user, the basic user; he has all the permissions on this Linux OS. So if you want to switch to the root user, so simply type su, press enter; it will ask for a password, type the password. So here it says authentication failure. So there's one more command, bash sudo bash. Okay, so before it was edureka here, and now it is root here. So if I type who am I, so here it says root. Okay, in case if this doesn't work, su doesn't work for any reason, so you can use this command called sudo bash. So it switches to the root user. And if you want to switch back to edureka, simply type su and the username. Okay, so you're back to the edureka user. Okay, these are very basic commands, guys, but you must be knowing this.
The next command is the sudo command. So the sudo command is for a user who doesn't have proper permissions or privileges for executing some commands or operations. So in that case, you have to use a sudo command. So say, for example, adding a user, deleting a user, adding a group, and many other commands that we will see in the upcoming commands. So I'll just give you a few examples here of sudo. For example, you have to add a user. So adding a user, deleting a user, that is mostly done by the root user, so he has all the permissions to add a user and all. Say, for example, if you have to add a user, so the command for that is sudo useradd and the name of the user. Say, for example, arvind. Oh, it says arvind already exists. So type arvind11. So it has created a user. And say, for example, if you have to add a password to this user, so the command for that is sudo passwd and the username. So it'll ask for a password that you need to set; you can type whatever you want, retype it. So it has created a user, and it has also added a password for that user. Say, for example, you have to delete this user, so the command for that is sudo userdel and the username, arvind11. Okay, so the user has been deleted. Say, for example, you have to add a group; a group can have multiple users. Okay, so you have to add a group to the system, so the command for that is sudo groupadd and the group name. So you can say the group name as techies. Okay, so the group has been added. Similarly, if you want to remove this group, sudo groupdel and the group name. Okay, pretty simple. So let me just clear my terminal.
The next command that we are going to talk about is the touch command. So the touch command is used to create any file on your system. Say, for example, I have to create a file, a text file; you can give whatever name, abc cba.txt. Oh, it says permission denied. Okay, so here we are going to use the command sudo. So it has created a file called cba.txt. And how can we see that? Simply type ls. Can you see here the file that we have just created, the cba.txt? So this is the use of the touch command to create a file.
The next command that we are going to talk about is the text editor command. Say, for example, vi, nano, vim, gedit, and so on. So the vi editor is the most popular and a classic text editor in a Linux family. So to use it, say, for example, you have to write something into that file, so for that purpose you will use sudo vi and the name of the file, cba.txt. Okay, so press enter; the file has been opened now. And press I to insert anything into this. Say, for example, hi, this is edureka. So to save this file, simply press Escape, colon wq, right, and q to quit. So our file has been saved.
There's one more command called the cat command. So this command can read, modify, or concatenate text files. So this command is also used to display the contents of the file. So say, for example, I've written something into this file called cba.txt; now I have to display the contents of this file. So what I'll do is cat and the file name, cba.txt. So here this was the line that I had written in this file, cba.txt. So the cat command can be used for that. So there are also other flags that can be used with this command. Say, for example, -b. So the command would be cat -b and the file name. So this is used to add line numbers to the non-blank lines. The next flag is -n, that is cat -n. So this command is used to add line numbers to all the lines that are present in the file. cat -s is used to squeeze blank lines into one line, and the cat -E it shows the dollar sign at the end of the line. So these were a few flags that you can use with the cat command. So let me just clear the terminal.
The next command that we are going to talk about is the copy command. This command is used to copy files and directories. A copy of the file/directory still remains in the working directory. So let me just show you how do you use the less command. So it is very simple, copy. So say, for example, cba.txt, I have to copy this file to the location, say, for example, home edureka. Right now we are at the home location; I have to copy this file to this location, home edureka. So the command is very simple, cp, file name, and the destination name. So press enter. So let us now see whether the file has been copied there. So for that we'll have to switch to that location, cd edureka. So let us use the ls command. Okay, so here you can see the cba.txt file has been copied. So this was a very simple command, and there are a few flags that you can use along with this command. So there's a flag called -n, that is cp -n and the file name. So this does not overwrite the file. The next flag is -u, that is cp -u. So this command updates the destination file only when the source file is different from the destination file. There's one more flag called -r, that is cp -r. So this command is a recursive copy for copying directories, and this command even copies the hidden files. So these were a few flags that you can use with the copy command.
The next command is the move command or the mv command. So this command moves the files and the directories from one directory to another. The file or the directory, once moved, is deleted from the working directory. So this was not the case with the copy command. So I hope you get the difference between copy and move. So let's see what is the syntax for this. So the syntax is mv, um, the flag name, like if there are any flags here, the file name and the destination name, okay, the path to the destination. So let us just say first we will have a look at the files that are present here. Okay, so demo.txt, can you see this file here? So we'll try to move this file to the home folder. So the command is very simple, mv, the file name, demo.txt. It says permission denied. So just simply use sudo. Okay, the file has been moved. Let us now verify this, cd. Okay, so we are here at the home folder; simply use the ls command. So as you can see here, demo.txt has been moved. So this was a very simple command and easy to use command. There are three flags that are associated with this command: mv -i. So this command enters into an interactive mode, and the command line asks before overwriting the files. So the command mv -u updates the destination file only when the source file is different from the destination file. And the third flag is the mv -b. So this command enters the verbose mode, and this command prints the source and the destination file. For those who are not aware of what verbose mode is, so verbose mode provides additional details as to what drivers and softwares it is loading during the startup. So this was all about the move command.
The next command that we are going to talk about is the rm command. So this command removes files from a directory. By default, the rm command does not remove directories. Once removed, the contents of the file cannot be recovered. So the syntax for this is very simple: rm, the flag, flag name, and the file name. That's a very simple command and easy to use command. So I'll just show you how to use this. Say, for example, I have to remove this file, demo.txt. So simply I'll type rm and the file name, demo.txt. Oh, it says permission denied. So the file has been removed. And let us just verify this. Okay, so we cannot see anywhere the demo.txt file; so it has been removed. So this was a very simple command, rm. So there are two flags that can be used along with this command. The first flag is the rm -r. So this command removes even the non-empty directories. And the other flag is rm -rf. So this command removes the non-empty directories including the parents and the subdirectories. So this was the rm command.
The next command that we're going to talk about is the mkdir command. So if you want to create a new directory, then this command can be used. It's a very simple command, and the syntax is even more simple. So if you have to create a directory, simply type mkdir and the directory name. So say, for example, in home I have to create a directory called techies. It says permission denied, no issues. So the directory has been created. Let us just verify this. So as you can see here, this directory has been created here at this location, the home folder. So the flag that can be used with this command is -p, that is mkdir -p. So this command creates both a parent directory and a subdirectory. And if you want to create multiple files into a directory, you can use the command mkdir -p and the file names. So this command will create multiple subdirectories inside the new parent directory. So let me just clear the terminal.
The next command is the rmdir command or the remove directory command. So this command is used to remove a specified directory. Although by default it can remove only an empty directory, there are flags which can be deployed to delete the non-empty directories as well. And the syntax for this command is very simple: simply type rmdir, the flag name, and the directory name. Okay, so very simple. Let us just see how do you remove a directory, rmdir. So let us just remove the directory that we created in the previous command, rmdir, and the name was techies. sudo rmdir techies. Okay, so the directory has been removed. Let's just verify this. So there's no directory called techies here, as it has been removed by the rmdir command. So there are a couple of flags that you can use with this command. The first flag is -p, that is rmdir -p. So this command removes both the parent and the child directory. There's one more flag called -pv. So the command is rmdir -pv. So this command removes all the parent and the subdirectories along with the verbose. So I hope you're clear with this command, rmdir.
The next command that we are going to discuss is the grep command. So this command is used to search for a particular string or a word in a text file. So this command is similar to control F, but this is executed via a command line. So let me just show you how do you use this command. So let's say, for example, let me have a text file here. So the syntax for using this command is very simple. So say, for example, we have a file here called grep test, as you can see here this one. So let me just see the contents of this file using the cat command. Okay, test.txt. So this file has these words: dog, apple, ball, cat, cat, mouse. So say, for example, I have to search the word cat in this file. So for that I'll use the command grep, the word cat, and the file name, grep test.txt. Okay, so as you can see here, the word cat has been highlighted just because it is present in this file. So say, for example, we want to search for a word that is not present here. So say, for example, cat1 or any other word. So say, for example, mad. Okay, so it is not showing anything, that means that this word is not present in this file. So this was a very simple command, grep, and there are a few flags that you can use with this command. So say, for example, grep -i and obviously the file name. So this command will return the results for case-insensitive strings. There's one more flag called -n, that is grep -n. So this command returns the matching strings along with their line numbers. The next flag is the grep -v. So this command returns the results of lines not matching the search string. Next flag is grep -c. So this command returns the number of lines in which the results match the search string.
The next command that we are going to talk about is the sort command. So this command sorts the results of a search, either alphabetically or numerically. Files, file contents, and directories can be sorted using this command. The syntax for this command is very simple. Uh, let me just see the files that are present here. So there's a file called sort test. So let me just see the contents of this files, sort test.txt. Okay, these are the words that are present in this file. So I have to just sort these words. Okay, so the command for that is sort, the file name, sort test.txt. So as you can see here, these words have been sorted alphabetically: b, d, f, m, s, and t. So this is the use of the sort command, and there are a few flags that you can use with this command, like the first flag is sort -r and the file name, obviously. So this command returns the results in reverse order. So there's one more flag called -f. So this command does the case-insensitive sorting. So whether you have uppercase words or alphabets or whatever in your file, so irrespective of the case, this command will sort the file. And there's one more flag called sort -n. So this command returns the results as per the numerical order. So say, for example, you have numbers in this file, and if you want to sort them numerically, like ascending order, that can be done using the command -n. So this was pretty much about the sort command. So let me just clear the terminal.
The next command that we are going to talk about is the chown command. So different users in the OS have ownerships and the permissions to ensure that the files are secure and put restrictions on who can modify the contents of the file. In Linux, there are different users who can use the
System so each user has some properties associated with them, such as the user ID and a home directory. We can add users into a group to make the process of managing the users easier. A group can have zero or more users. A specified user can be associated with a default group; it can also be a member of other groups on the systems as well.
So if you talk about the ownerships and the permissions, so to protect and secure the files and directories in Linux, we use permissions to control what a user can do with a file or a directory. So in Linux, there are three types of permission: the read permission, the write permission, and the execute permission.
The read permission allows the user to read files and directories. It lets the user read directories and subdirectories stored in it. The write permission allows the user to modify and delete a file; also, it allows a user to modify its contents for the directories. So unless the execute permission is not given to directories, changes do not affect them. The third permission is the execute permission. The write permission on a file allows it to get executed. For example, if we have a file named php.sh, so unless we don't give it an execute permission, it won't be run. So these were the permissions, types of file permissions in Linux. There are three types: the first one is the user.
This type of file permission affects the owner of the file. The second one is the group; this type of file permission affects the group which owns the file. So instead of the group permissions, the user permissions will apply if the owner user is in this group. The third permission is the other permission; these types of file permissions affect all the users on the systems.
To view these permissions, so let us just say we use a command `ls -l`. So this command will list down all the files and the directories that are present here along with their permissions. So as you can see here, these are the permissions, these are the users, the groups, and the timestamp, and these are the names of the file. To use this command, so say, for example, there's this file called abc.txt whose user is edureka. Okay, so you have to use this command `chown`. The syntax for that is pretty simple: `chown` the owner name, the owner that you want to change, so say, for example, `root`, and the file name, so file name is `abc.txt`. `operation not permitted`. `sudo let me just try sudo`. Okay, so this works when you use `sudo`. So let us now just run the command `ls -l` to see the permissions of this file. So as you can see here, it was first edureka. Now let us see the changed owner. Okay, so previously it was edureka and now it is root. Okay, so this is how you use the `chown` command. So just to summarize, the `chown` command is used to change the owner and the group of the file.
The next command that we are going to talk about is the `chmod` command. So this command is used to change the access permissions of files and directories. The syntax for this command is pretty much simple. So say, for example, if you want to change the permissions and the privileges of a file, so for that let us just see the list of files that is present here and the permissions. So say, for example, this file `bac.txt`, it has these permissions. So we want to give all the permissions to all the users and the groups that I want to use this file. So for that, let me type the command `chmod 777` okay and the file name `bac.txt`. Okay, so let us again have a look at the permissions of this file. Okay, so as you can see here, previously these were the permissions, read write read and read, and now it has changed to read write execute for the user, the group, and the others. Okay, so there are a few numbers that are associated with the permissions: like 0 means no permission at all, 1 means the execute permission, 2 means the write permission, and 4 means the read permission. So here we have used the command `chmod 777`. So 7 here means read write execute, all the three, 4, 2, and 1, so rewrite execute for the user, the second 7 is for the group, and the third 7 is for any other users or the groups. So this was the `chmod` command, and I hope you have understood this command. So let me just clear the terminal.
The next command that we are going to talk about is the `lsof` command. So while working in Linux or Unix-based systems, there might be several files and folders which are being used; some of them are visible and some of them are not visible. So `lsof` stands for list of open files. So this command provides a list of files that are open; basically, it gives the information to find out the files which are open by which process. With one go, this command lists out all the open files in the output console. The syntax for this command is pretty much simple. Let us just type `lsof`. So as you can see here, this is the list of open files, these many files. Okay, if you scroll, so here you observe there are details of which files are open, the process ID, the user associated with the process. `FD` stands for file descriptor, size of the file, altogether gives detailed information about the file opened by the command, the process ID, its user, and so on. `CWD` here stands for current working directory. `.txt` stands for the text file, obviously. So say, for example, if you want to know the list of all files opened by a particular user, so there are several users of a system, and each user can have different requirements and accordingly they use files and devices. So to find a list of files that are opened by a specific user, you can use the command, say, for example, `lsof -u` and the username, say, for example, `edureka`. So these are the lists of files that are opened by the user edureka. Let me just clear the terminal.
Then the next command that we are going to talk about is the `id` command. The `id` command in Linux is used to find out user and the group names and numeric IDs of the current user or any other user in the server. This command is used to find out a few important things such as the username and the real user ID, find out the specific user's UID, show the UID and the groups associated with a user, list out all the groups a user belongs to, and display the security context of the current user. The syntax for this command is pretty much simple: `id`, the flag, and the username. Okay, so there are a few flags that you can use with this command. The first flag is `-g`. So the command would be `id -g` and the username. So this command prints only the effective group IDs, whereas `id -G` prints all the group IDs. `id -n` prints the names instead of numbers, and `id -r` prints real IDs instead of numbers. `id -u` prints only the effective user ID. `id --help` displays the help messages. `id --version` displays the version information. So without any option, it prints every set of identified information, that is the numeric IDs. So what you need to do here is simply type `id` and press enter. So as you can see here, it displays the UID for this user edureka, the group ID, and the group that he belongs to and the respective group IDs as well. So say, for example, if you want to know the user ID for this user called edureka, `id -u edureka`. So 1000, as you can see here, user ID is 1000 and group ID is also 1000. Let me just verify this; the command for that is `id -g`. Okay, 1000, as you can see here. So to find out all the UIDs and the groups associated with the user, so say, for example, there's another user called Arvin, so `id Arvin`. So as you can see here, the output, user ID, group ID, and the groups that it belongs to. So this was about the `id` command.
The next command that we are going to talk about is the `tar` command. The `tar` command is used to zip and unzip files of the `.tar` format. Let me just show you the syntax for this file. So say, for example, if you want to zip a folder, so for that the command is `tar -cvf` space file name and the folder name, source folder name. So this was a very easy syntax for the `tar` command. And say, for example, if you want to unzip a file, so in devops while installing something, you might be getting a file in the `.tar` format. While unzipping that file, you can use this command: `tar -xvf` and the tar file name. So you can use this command to unzip a file. So this was about the `tar` command.
The next command that we are going to talk about is the `cut` command. The `cut` command is used for extracting a portion of a file using columns and delimiters. So say, for example, if you want to list everything in a selected column, then in this case you need to use the `-c` flag with the `cut` command. So say, for example, let me just see here, so there's this file called `foreign`. Let me just show you how do you use this command. So let us first see what are the files present here. So say, for example, this file `demo1.txt`. Okay, okay, so this file has these lines: a11, b22, and c33. So say, for example, if you want to display only two columns like A1, B2, and C3 from this file, so using the `cut` command we can do it. The syntax for doing that is very simple: `cut -c1-2` space the file name. So the file name is `demo1.txt`. So `-c` here stands for the column and which columns, 1 and 2 column. Okay, just press enter. Okay, as you can see here, it will display these two columns. So say, for example, you want only one column and not the two columns, so just remove this two, `-c1`, press enter. So you, you can see here ABC, only the first column is displayed. Okay, so this was about the `cut` command.
The next command that we are going to talk about is the `sed`, that is `sed` command. `sed` is a text editor which can perform editing operations in a non-interactive way. The `sed` command gets its input from a standard input or a file to perform the editing operations on a file. `sed` is a very powerful utility, and you can do a lot of file manipulations using `sed`. So say, for example, if you want to replace a text in a file by searching it in a file, you can use the `sed` command with the substitute `s` flag, small `s`, to search for the specific pattern and change it. So say, for example, let me just show you an example here. There's this file called `demo`. `sed test`. Okay, `cat`, let me just see the content, this file `sedtest.txt`. Okay, so here it says how are you baban. So say, for example, I have to replace this baban by any other name, so I can use the `sed` command here: `sed` space single quote `s` that is the flag that you can use with this command, so the word that you want to replace and the new word, okay, and the name of the file, obviously, `sedtest.txt`. So as you can see here, first it was how are you baban and now it is how are you Channel. So this was the command `sed`. I hope you have understood this command. We just clear the terminal. Okay.
The next command that we are going to talk about is the `uniq` command. The `uniq` command is used for filtering out the duplicate lines in a files. The syntax for this command is pretty much simple. So say, for example, you have to remove all the duplicate lines from a file, so you can use this command `uniq` and the file name. So this was a very easy command. The next command that you are going to talk about is the `watch` command. The `watch` command in Linux is used to execute a program periodically, showing output in full screen. This command will run a specified command in the argument repeatedly by showing its outputs and errors. By default, the specified command will run every two seconds, and `watch` will run until interrupted. The syntax for this command is very simple; you just have to type `watch`, the flag, and the command. Let me just show you an example using this. So there's this flag called `-d` that you can use with `watch`. This parameter `-d` highlights the differences between the successive updates. The options will read the optional arguments which changes the highlight to be permanent, and this allows the user to see what has changed at least once since the first iteration. So let me just write `-d watch -d free -m`. The `free` command we have used, we'll see what the `free` command is in the later part of this session.
The next command that we are going to talk about is the `eval` command. `eval` is a built-in Linux command which is used to execute arguments as a shell command. It combines arguments into a single string and uses it as an input to the shell and execute commands. The syntax for this command is very simple: `eval` and the arguments. Let me just show you an example of the `eval` command here. So say, for example, you have to type `eval --help`. `eval --help`. This command shows the description of the `eval` command itself. So as you can see here. So let me just clear the terminal.
The next command that we are going to talk about is the `history` command. The `history` command is used to view the previously executed commands. This feature was not available in the born shell. `bash` and `csh` support this feature in which every command is executed and is treated as the event and is associated with an event number using which they can be recalled and changed if there's a requirement to do so. So these commands are saved in a history file. So in `bash` shell, the `history` command shows the whole list of commands. So say, for example, just type `history` here, press enter. So this is the list of commands I've used till now, 400, 500 plus commands I guess, yeah, 584 commands I've used. So say, for example, if you want to see only the last five commands that I've used, `history 5`, press enter. So these are the last five commands that you have used. You can see here the pieces clearly. Terminal. Okay.
The next command that we are going to talk about is the `dd` command. `dd` is a command-line utility for Unix and Unix-like OS whose primary purpose is to convert and copy files. The command-line syntax of `dd` differs from many other Unix programs in that it uses the syntax `option=value`. So this syntax `option=value` is used for its command-line operations. I'll show you just a practical example of this command. So say, for example, you have to backup the entire hard disk. So to backup an entire copy of a hard disk to another hard disk connected to the same system, so this command `dd` can be used in this command. The units device name of the source or disk is, say, for example, the source hard disk name is `/dev/hda`, and the target hard disk name is `/dev/hdb`. So how do you use this command? `dd`, `dd if=` stands for input file, space the name of the source or disk, so it is `/dev/` space `hda`, and I just forgot to place equal to sign here as discussed earlier, it has a syntax of `option=value`. So input file is this, the source file, and the output file of is `hdb`. So as of now we are not copying anything, so but I'm just showing you how to use this command. Input file and output file should be mentioned very carefully; just in case you mentioned source device in the target and the vice versa, you might lose all the data. I hope you have understood this command. Okay.
There's one more command that we talked about like the `free` command. Okay, so the `free` command displays the total amount of free space available along with the amount of memory used and swap memory in the system and also the buffers used by the kernel. The syntax for this command is very simple: `free` space or options you can see. So let me just type the `free` command here and press enter. So as you can see here, total installed memory that is present on the system, so used means the used memory, and free means the unused memory. Shared displays the memory used by the temp folders. Buffer displays the memory used by the kernel buffers. Cached displays the memory used by the page cache and the slabs. Buffers/cache displays the sum of the buffers and the cache. And there are a few flags or options that you can use with this command, that is `-b`, the command is `free -b`, so it displays the memory in bytes. If you use `-k`, this displays the amount of memory in kilobytes, which is by default. `-m` displays the amount of memory in megabytes, and `-g` small `g` displays the amount of memory in gigabytes. I hope you have understood this command `free`. So let me just clear the terminal. Okay.
The next command that we are going to talk about is the `ssh` command. While working in devops, you might frequently use this command, the `ssh` command. `ssh` means that secure shell. Okay, so this command refers to a cryptographic network protocol for operating network services securely over an unsecured network. Typical use cases include remote command-line execution, but any network service can be secured with the command `ssh`. So say, for example, if you have a master node and the slave node, so if you are running this command, the command that I am going to type now on the slave node, this will give you access to the master node. So the command for that is very simple: `ssh` and the master's IP address. So if you run this command on the slave machine, you can get access to the master machine and vice versa. If you execute this command on the master machine along with the slave IP, you can get access to the slave machine. So there's one more command called `ssh-keygen`. So this command is used to generate a public-private authentication key pair. Authentication keys allow a user to connect to a remote system without supplying the password. Keys must be generated for each user separately. So if you generate key pairs as the root user, only the root user can use those keys. So the syntax for creating a pair of keys is very simple. So you need to type `ssh-keygen -t rsa`, press enter here. You can press enter. It says it already exists, so I wanted to overwrite, press enter, enter passwords empty for no passphrase, enter passphrase, press enter, press enter. Okay, so the key has been generated, as you can see here. `-t` option here is used to specify the type of key that you have to create. So you have the option of specifying the passphrase to encrypt the private part of the key. So if you encrypt your personal key, you must supply the passphrase each time you use this key. So in this case, we have just pressed enter; we haven't pressed anything in the passphrase. So this prevents an attacker who has cleared the terminal.
The next command that we are going to talk about is the `ip` command. The `ip` command in Linux is present in the `net-tools`, which is used for performing several network administration tasks. `ip` simply stands for Internet Protocol. So this command is used to show, manipulate, routing devices and tunnels. It is similar to the `ifconfig` command. Okay. The next command that we are going to discuss is the `ifconfig` command. So `ifconfig`, that is interface configuration command, is used to configure the kernel resident network interfaces. It is used at the boot time to set up interfaces as necessary. After that, it is usually used when needed during debugging or when you need a system tuning. Also, this command is used to assign IP addresses and netmask to an interface or to enable or disable a given interface. The syntax for this command is very simple: `ifconfig` space options or and space the interface. So there are two options that you can use with this command, that is `ifconfig -a`. So this option is used to display all the interfaces available, even if they are down. So if you use this command `ifconfig -a`, okay, so you can see all the interfaces.
That are available. Okay, yeah. And there's one more command called hyphen s. So if you type ifconfig hyphen s, so this displays a short list instead of all the details. So this was about the ifconfig command. So let me just clear the terminal.
Also, if you want to know the IP address of your machine, you simply need to type ifconfig, press enter. Okay, as you can see here, this is the IP address of your machine. So to know the IP address of your machine, you just need to use this command ifconfig. So let me just clear the terminal.
The next command that we are going to talk about is the IP command. So IP command in Linux is present in the net-tools, which is used for performing several Network Administration tasks. So IP stands for Internet Protocol. This command is used to show or manipulate routing, devices, and tunnels. It is similar to the ifconfig command, but it is much more powerful, and more functions and facilities are attached to it. Ifconfig is one of the deprecated commands in the net-tools of Linux that has not been maintained for many years. IP command is used to perform several tasks like assigning an address to a network interface or configuring network interface parameters and so on. So it can perform several other tasks like configuring and modifying the default and static routing, setting up a tunnel over an IP, listing IP addresses and property information, modifying the status of the interface, assigning, deleting, and setting up IP addresses and routes.
So let me just show you a practical example of IP space address. Okay, so this command is used to show all the IP addresses associated on all network devices. So as you can see here, these are the various network devices and their IP addresses. Yeah. So there's one more command called IP space link. So this command is used to display link layer information. It will fetch characteristics of the link layer devices currently available. Any networking device which has a driver loaded can be classified as an available device. So IP hyphen link, press enter. Okay, so this is the output. These are the available devices and the link layer information, as you can see here. So let me just clear the terminal.
So the next command that we are going to talk about is the netstat command. So netstat command displays various Network related information such as network connections, routing tables, interface statistics, multicast memberships, and so on. So the syntax for this is very simple. For example, netstat let's start and hyphen a. So as you can see here, if you use this command netstat hyphen a, so it is used to show both the listening and the non-listening ports that are available. So this command is used to show both the listing as well as the non-listening sockets. And there's one more command called netstat hyphen AP. So this command will list all the TCP ports that are available. So as you can see here, these are the TCP ports. So this was about the netstat commands.
The next command is the nslookup command. So nslookup stands for name server lookup. This is a useful command for getting information from the DNS server. It is a network Administration tool for querying the domain name system to obtain domain name or IP addresses mapping or any other specific DNS record. It is also used to troubleshoot DNS related problems. So the syntax for this is very simple. Simply type NS lookup and the option. Let me just type NS lookup, say for example google.com. So it is giving you the details of this domain google.com, the server, the address. So if we type this command like NS and the domain name, so this will display a record that is IP address of the domain, as you can see here. So this command queries the domain name servers to get all these details. So this was about the NS lookup command. Let me just clear the terminal.
The next command that we are going to talk about is the cURL or curl command, as you can see. So curl is a command line tool to transfer data to or from a server using any of the supported protocols such as HTTP, FTP, SCP, SMTP, and so on. So curl is powered by a libcurl. So this tool is preferred for automation since it is designed to work without any user interaction. So curl can be used to transform multiple files at once. So the syntax for this command is very simple: curl space, I repeat curl space options and the URL. So there's one parameter or the option that you can use with this is hypheno. This parameter saves the downloaded file on the local machine with the name provided in the parameters. So this was about the curl of the corl command.
The next command that we are going to talk about is the awk command. So awk is a scripting language used for manipulating data and generating reports. The awk command programming language requires no compiling and allows the user to use variables, numeric functions, string functions, and logical operators. So awk is abbreviated from the names of the developers, that is Aho, Weinberger, and Kernigan. So the syntax is pretty much simple. I'll show you how do you use it. So say for example, let me see the list of files that we have. Okay, so abc.txt. So let us just see the contents of this file abc.txt. Uh, let's just see another file demo.demo1.txt. Okay, nm01.txt. Foreign. Okay. So I'll just show you how do you use this command. So say for example, you want to print every line from a specified file. So we can use this command awk single code curly braces, okay, and the name of the file. So say for example awk test.txt. Okay, so this was the file. This has only two lines. Okay. So if you want to print every line from a file, so you can use this command awk. So say for example, I'm looking for a specific pattern in a file. So say for example awk, I'm looking for the word okay. So let's consider this file itself in single quotes. I'm looking for Ram and I want to print it and the file name awk test.txt. So it will print any of the lines that has this word Ram. Press enter. Okay, so these two lines have this word Ram, so it has printed both these lines. So this was another use of awk.
The next command that we are going to talk about is the tr command. So tr stands for translate. So this command in Unix is a command line utility for translating and deleting characters. It supports a range of transformations including uppercase to lowercase, squeezing repeating characters, deleting specific characters, and basic find and replace. It can be used with Unix pipes to support more complex translations. Okay. So I'll just show you an example of the pr command. So say for example this file called awk test. Okay. So let us just see the contents of this file. Now we will try some other file CBA.txt. Okay. So let us just say we want to convert this into uppercase, everything into uppercase here. We want to display this hi this is edureka in uppercase. So for that we will use the command can the file name CBA.txt and the pipe symbol TR space double quotes A to Z space and the capital A to Z. Okay. So this is the syntax for doing this. Press enter. As you can see here, everything has been converted to uppercase. So this is one of the usage of the pr command. So let me just hear the terminal.
The next command that we are going to talk about is the env command. Env command is used to print environment variables. It is also used to run a utility or a command in a custom environment. In practice, env command has another common use. It is often used by shell scripts to launch a correct interpreter. In this usage, the environment is typically not changed. So say for example, I have to see a list of all the environment variables that are present on my system. So I'll simply type env and press enter. Okay, so these are the list of environment variables that are present. Say for example, if you want to run a command with an empty environment, so for that the syntax is env hyphen hyphen I and the command. Okay. And say for example, if you want to remove a variable from the environment, so for that the syntax is env hyphen U and the variable name. Okay. So I hope you have understood this command env. Let me just clear the terminal.
The next command that we are going to talk about is the iptables command. Iptables is a command line interface used to set up and maintain tables for the netfilter firewall for the ipv4 including the Linux kernel. The firewall matches packets with rules defined in these tables and then takes the specified action on a possible match. So I'm gonna tell you the usage of the IP tables commands. So say for example, while working in devops, for some reason you need to disable the firewalls. So for that this command iptables can be used. Say for example, service iptables stop. So this command can be used to disable the fireballs. Okay. So this was uh one use of the command called iptables. Okay. So as of now we are not running this command on our system.
The next command that we're going to talk about is the apt-get command. So apt-get is a command line tool which helps in handling packages in Linux. Its main task is to retrieve the information and packages from the authenticated sources for installation, upgrade, and removal of packages along with their dependencies. So apt stands for advanced packaging tool. So if you are using Ubuntu based systems, so here the command apt-get can be used. While if you're someone who's using the red hat based system such as the CentOS, so in that case you need to use the command yum. Okay. So the syntax for this command is very simple like apt-get the options on the flags and the command. Okay. So say for example, I have to install something on my machine. So I'll use the command sudo apt-get install. Say for example, I want to install this image editor called Pinda. Okay. So I'll just type Pinter sudo apt-get install and Pinter. Okay. So this was about the apt-get command.
The next command is the df command and the disk usage command. The df or the disk free command reports the amount of available disk space being used by the file systems. The du of the disk usage command reports the size of directory trees inclusive of all their contents and the size of individual files. The aim is to make sure you are not overshooting the 80 threshold. If you exceed the threshold, it is time to scale or clean up the mess because you are running out of the resources. So the syntax to use this command like if you want to see the disk free space in a human readable format, you can use the command df sudo df hyphen h. Okay. So this is the disk free command that we are using, and we can see here the output size, available size, used, available memory percentages, and the mounted location. So but in most cases you want to check which part of your system is consuming lots of disk space. For the command for doing that is sudo du hyphen h hyphen d 1 and the bar. So as you can see here, this location it is consuming a lot of disk space. So this was about the df and the du command.
So now let us talk a bit about shell scripting. So first and foremost question: what is a shell? So an operating system is made up of many components, out of which two are very prime components, and these components are the kernel and the shell. So a kernel is at the nucleus of a computer. It makes the communication between the hardware and the software possible. While the kernel is the innermost part of an operating system, a shell is the outermost one. A shell in a Linux OS takes input from you in the form of commands, processes it, and then gives an output. It is the interface through which a user works on the program's commands and scripts. A shell is accessed by a terminal which runs it. So whenever you run the terminal, the shell issues a command prompt where you can type your input which is then executed when you hit the enter key. So the output or the result is thereafter displayed on the terminal. The shell wraps around the delicate interior of an operating system thereby protecting it from accidental damage. Hence it is named as shell.
So there are two types of shell basically: the Bourne shell and the C shell. So the prompt for the Bourne shell is shown by the dollar symbol and its derivatives are posix con and Bash. Posix shell is also known as sh. Con shell is also known as sh. And the Bourne again shell is now known as bash. And the bash is the most popular shell. The second type of shell is the C shell, and the problem for this shell is shown by the percentage sign, and there are two subcategories for this, that is the C shell which is also known as csh and the tcsh shell which is also known as tcsh.
So now the question is what is shell scripting? So shell scripting is writing a series of commands for the shell to execute. It can combine lengthy and repetitive sequences of commands into a single and a simple script which can be stored and executed anytime. So this reduces the effort required by the end user. So let us understand the various steps in creating a shell script. So what you do is first you create a file using the vi editor or any other editor, and you name the script with an extension dot sh. So we will also have a look at it like we will execute a shell script, but I'll just tell you a few steps of how to do it. Then we have to start the script with the symbol such as hash exclamation mark and the slash bin slash sh. So hash exclamation is an operator called the shebang, which directs the script to the interpreter location. So if we use the command hash exclamation mark slash bin slash sh, the script gets directed to the Bourne shell. Then once we open this file, we have to write some code. We have to save it, and for executing we have to just type the command bash and the file name dot sh. I'll just show you how do you do it. Here I have the git terminal or the git bash opened here. So we have to type say for example abc.sh. We have to write something here. So what we'll do is I have a simple program which calculates the sum of the digits of a number. It accepts a number from a user and it calculates the sum of its digits and it displays the result. So this is a very simple program. I'll just write it here. I'll just save it WQ. Okay, so it is saved, and now we have to just run this script using the command bash. Well let me just check whether I have inserted. Okay, so we are missing out on a very important thing here. We have to type shebang operator. Okay, so hash exclamation slash bin slash sh. We have written whatever we wanted. Okay, so we have saved it, and now bash abc.sh. So it says enter a number 88. So the sum of digits of 88 is 16. So this is how you write a shell script and you run a shell script. So this was a very simple program, but you can write any program that you want and you can run it using the bash.
We have come to the final part of this session, that is the git commands. And before knowing the git commands, we will quickly brush up a few things about git. What is git? So git is a free open source distributed Version Control System tool designed to handle everything from small to very large projects with speed and efficiency. So git has the functionality, performance, security, and flexibility that most teams and individual developers need. It also serves as an important distributed Version Control tool that is used in devops tools. Like git, enable the communication between the development and the operations team. So whenever you're developing a large project with a huge number of collaborators, it is very important to have communication between the collaborators while making changes in the project. Commit messages and git play a very important role in communicating among the team. The bits and pieces that we all deploy lies in the version control system like git. So to succeed in devops, you need to have all the communication in the Version Control, and hence git plays a very vital role in succeeding at devops. So this was the definition of git, and this is the diagram that you must remember, like the working directory, the staging area, the local repository, and the remote repository. You just need to remember these things. So if you remember these things, then you will get a clear understanding of what command is used to do what things.
So now we will have a look at few of the git commands like as you can see here, we will cover a few commands: git config, git init and so on, and few of these commands as well. Now let us go to the git bash. So the first command that we will see here is git config command. Okay, so this command sets the author name and the email address respectively to be used with your comments. So how do you do it? The syntax is pretty simple like git git config hyphen hyphen global user.name and the name, say for example edureka in my case, let's just say Arvin. Okay, this is the syntax that is used hyphen hyphen Global. Previously I just typed a single hyphen. There are two hyphens here. We have registered the username, and now you have to register the email, so that is git config hyphen hyphen global user.email and the email address that is arvind@eureka.com. Okay, so this works fine. So the next command is the git init command. So this command is used to start a new repository. So this is a very simple command. Simply type git init. Like you can type the name of the repository if you want, else it will initialize an empty repository without any name. Okay, so here as you can see here on desktop it has created a repository. Don't get a repository has been created on the desktop with our command.
So the next command is the git clone command. So this command is used to obtain a repository from an existing URL. Say for example, let me just show you a clone a repository from my GitHub account. Okay. So say for example this is the repository Game of Life which is available on my GitHub account. To clone that URL, I'll have to first go to this tab, clone or download, click here, and then you will get link. Okay, copy that link, clone with https. Okay, copy that link and paste it here: git clone and the repository, paste, press enter. Okay, so the repository is being cloned here, and that is still working, and it is done. Okay, so as you can see here, The Game of Life repository has been cloned. So this was a very easy command. Let me just clear the terminal.
So the next command is the git add command. So this command adds a file to the staging area, and the command for that is very simple: git add and the file name. So this is a syntax for the add command. And suppose if you have more than one file to add to the staging area, you can simply use the star option. Okay, so it will add everything like more than one file or multiple files. So this was about the git add command. The next command is the git commit command. So this command records or snapshots the file permanently in the version history. So the syntax for this command is git commit hyphen M and any of the message that you want to type. Okay, so with each commit you can type a message to notify. So this is the syntax for this command. Let's just say there's one more command called git commit hyphen a. So there's one more flag with this command hyphen a. So this command commits any files you have added with the git add command and also commits any files you have changed since then. So this is the syntax for this command: git commit hyphen a. Similarly, there's one more command like as you have seen earlier in the Linux command the rm command: git rm the file name. Okay, so this command deletes the file from your working directory and stages the deletion. This was very easy command: git rm. Similarly, there's one command called git show, and here you have to specify the commit ID. Okay, so this command shows the metadata and the content changes of the specified comment. So this was about the git show. The next command is the git remote command. So this command is used to connect your local repository to the remote server. So for that the syntax is very simple. Say for example, git remote
Add the variable name and the remote server link. This is the syntax to use the `get remote`.
If you want to delete a branch on your remote repository, how will you do it? So there's one command called `git push --delete <remote server> <branch name>`. Say, for example, B2 is the branch name.
So the next command is the `git pull` command. So this command fetches and merges changes on the remote server to your working directory. So the syntax is pretty simple: `git pull <repository link>`. So this is a very simple command.
The next command that we are going to talk about is the `git branch` command. This command lists all the local branches in your current repository, and its syntax is very simple: just `git branch`. This is a very simple command.
And if you want to create a new branch, so for that the command is `git branch <branch name>`. Say, for example, the new branch that you want to create.
And if you want to delete the feature branch, so for that the command is `git branch -D <branch name>`. Say, for example, B1. So this was the usage of the `git branch` command.
The next command is the `git checkout`. So this command is used to switch from one branch to another branch, and the syntax also is very simple: `git checkout <branch name>` where you want to switch. Okay, say for example, B1 or B2 or even master. So this is one use of checkout.
So if you want to create a new branch and you want to switch to that branch, so for that the syntax is `git checkout -b <branch name>`. B4. So this command creates a branch and also switches to that branch.
There's one more command called `git merge`. So what this command does is this command merges the specified branch history into the current branch, and the syntax for that is `git merge <branch_name>`. So this is a very simple command like `git merge <branch name>`.
There's one last command that we will have a look at, that is `git rebase`. So what this command does is this command will move all your work from your current branch to the master branch. They look like as if they are developed sequentially, but they are developed parallelly. So the syntax for rebase is `git rebase <branch name>`. So this was the syntax for git rebase. [Music]
What a Linux file system is. Now when we talk about Linux file system, the first thing we need to know is what it is, right? So a Linux file system is a set of processes that controls how, where, when data that is stored and retrieved from a storage device. How you store it, where do you store it, when you store it—all of those are basically taken care of by the file system, right? So a good file system is extremely essential for everyday assistive processes, right? A Linux file system is basically a structured collection of different files on a disk drive, right, or a partition. So what you can see is that the file system helps in basically making all the files present in the Linux system into much more structured, collected thread of files. And as you know, in Linux, everything is a file: your devices, your applications—everything in Linux is a file, right? So file systems on Linux basically control how and where the data is stored, along with the fact that every partition consists of a file system of their own. Just like in Windows, you have C drive, D drive, and all of that based on namespaces, right? In Python, there is no C drive type, although you can have partitions, but these partitions will basically have their own set of file systems, right? And the main thing is that file systems help us store data systematically. So this is what a Linux file system is.
Next up, we talk about the different types of Linux file systems. Now when we talk about the different types of Linux file systems, there are approximately six types. The first is the EXT. So EXT is basically ext2, 3, 4, which basically stands for extended file system. Now ext2 was the first Linux file system that allows managing 2 TB of data, but at the current moment, ext4 is the fastest file system that you can have on Linux.
Next up, we have the JFS. JFS basically stands for the journal file system. Journal file system is basically developed by IBM along with Unix, right? So JFS is an alternative to the EXT file system. EXT is pretty useful, but JFS comes handy when you have a CPU whose power is very limited.
The third kind of file system that you have is the ReiserFS file system. So earlier, ReiserFS was used as a default file system for Linux, as you may see, but now they shifted to ext3. But what ReiserFS does is that it dynamically supports the file extension but has certain performance drawbacks, which is why now people have again moved back to ext3 from ReiserFS.
So next up, we have the XFS. So when it comes to XFS, you can see that XFS was considered a high-speed JFS, which is the journaled file system, in high speed, which is developed for parallel I/O processing. Now one example where XFS is used is basically by NASA.
The next one is the Btrfs. Now btrfs basically stands for B-tree file system. It is basically a file system which is used for fault tolerance, repairs of the system, etc.
Next up, we have the swap file system, which is the last kind of file system. So when it comes to swap file system, swap file systems are used for memory paging in Linux OS's, right? So memory paging only comes into play when there is system hibernation going on. So a system that never goes into hibernation is required to have swap space equal to RAM space, right? So swap space is always equal to RAM space for systems that never go into hibernation.
Up next, we have the file system architecture. Now when we talk about architecture, there are a lot of things we need to know. Let's let's get going. The first thing you need to know about the file system architecture is that it is a hierarchical file structure, and it can manage and provide for normal non-volatile storage data, along with the fact that the same space describes the logical structure of the file. I'll tell you all about what all of these means. And finally, we see that advanced information about the partitions is always stored. So let's say, for example, this is your architecture where you have the kernel, you have the virtual file system, and you also have the different file systems that you want, right, along with the hardware in the end. So let's go through what I just explained to you.
So when I talk about hierarchical structure, what I mean is that this system basically has a root directory, and that root directory has certain subdirectories, right? So all other subdirectories can be accessed from the root directory. So this is what hierarchical structure means, right? So when I talk about the fact that it can provide for non-volatile storage data, when I talk about non-volatile storage data, I talk about RAM, I talk about ROM, right? So basically, this file system is designed in such a way that it can manage and provide space for non-volatile data, right? All systems require a namespace. So namespace is something that defines the naming process, the length of the file name, or a subset of characters that you have. So this namespace is also used for logically defining the structure of the file that you have, right? And finally, we see that the data structure needs to support a hierarchical directory structure, right? So the structure is used to describe the available and used disk space, right, for a particular block. So finally, we see that the advanced data that the structure stores or represents contains information about the file system stored on the drive, right? So this information that is contained about the partitions is completely distinct and independent from other file system metadata.
Now let's look at this architecture we have. So the file system requires an API to access the function calls or to interact with file systems, right? API facilities starts such as creating, deleting, and copying the files. When I talk about API, I mean application programming interface. So the first two parts of the given system file system together make up the Linux virtual file system, and it provides a single set of commands that you have.
Next up, we talk about the different file system directories that are there. So let's get going. As you can see, the topmost file directory that you have is the root directory, and you can basically access any of these other directories that are there from the root directory itself. You can see there's bin, dev, etc, usr, home, lib, and tmp, where all of these files have certain functions, right? All of these directories have certain functions; they store some sort of information about the system, right? So let's take a look at some of the file directories that are there.
So starting off, we talk about bin. Now when we talk about bin, the bin directory contains mostly binaries. Now when I talk about binaries, binaries is basically some of the applications and programs that you can run. So the `ls` command, which is basically the list of the files that you have, so the `ls` command that you have on Linux and other basic tools are also present in this directory, which is the bin directory, actually, right?
Then we talk about the dev directory. Now when we talk about the dev directory, we see that the dev directory contains device files, right? So many of these are generated at boot time or even on the fly, right? So you don't really have existing device files already present. So some of them are generated on the fly or when you boot the system, right?
Next up, we have the etc. Now this is fairly important because, unlike the fact that etc stands for etc here, etc stands for everything to configure. So everything to configure because it contains most, if not all, the system-wide configuration calls, right? So all of the users, the passwords, the machines that are there on your network, the user, the password—all of these are present in the etc directory.
Uh, then we have the home directory. So when we talk about the home directory, you can see that you find your users' personal directories here. For example, if let's say home/work contains my directories, home/guest will contain another guest's directory on the same system.
Then we come to lib. Now lib is basically short for libraries. All the libraries are found in this directory. Libraries are basically files containing code that your application may or may not need during runtime, right? So the library under root contains all the important kernel modules. As you can see, there are two different lib directories: one is under root and one is again under usr, right? Now before we get to that, we can see another directory, which is the media directory. Now as you can understand, the media directory is the directory where external storage will automatically be mounted when you try and plug it in or try to access it, right? So the media directory is the directory where, if you connect a storage device or an SSD, it'll automatically get mounted in your system, right? So these are the basic directories that are there.
Let's move on to features of the Linux file system. Now when I talk about features, the basic three features that I can think about is the fact that Linux is case-sensitive. Now case sensitivity is because of the fact that it distinguishes between lowercase and uppercase characters, right? So there can be a file which is named test.txt with T capital, and there can be another file which is got the same name but none of the capital letters. So these are two different files in Linux, right? You don't need to rename them; you can have case-sensitive files.
Next up, we can see that Linux has various hidden files that are there. Now Linux distinguishes between standard files and hidden files. Most configuration files are hidden in Linux OS, right? So usually we don't need to access or read these hidden files. The hidden files are represented by a dot before their file name, right? So I'll show you how you basically access the files or you basically check out where the hidden files are.
Next up, we see the different partitions, directories, and drives that are present in Linux, right? So Linux does not use drive letters to organize the drive as Windows does, right? Like local disk C, local disk D—Linux does not have that. In Linux, we cannot tell whether we are addressing a partition, a network, or an ordinary directory because all of the files, all of the directories that are there, every application, every device—all of everything that you have is a file, right? Even the file which has different commands is a different file; even a command like `ls` is a different file which is present in bin, and we'll check that out in a way, right?
So next up, let's come to the demo for the Linux file system. So basically, when you go into Linux, this is your interface that you have, so where can you find your files? Your go-to files. You can also check out your directories from the terminal, and that is basically what we're going to do now. Here, here you can see that there are no such partitions as such, right? You don't have a C drive; you don't have a D drive. So where do you find your system files like in C? You can just go to other locations, go to computer, and as soon as you go to computer, you can see that these are the files that are there: the bin file, dev file, etc, home, lib, and you can basically go into these files. So basically, some of these files have restricted access, so let's just go and see how you can access them through the terminal. So you basically go to your terminal, and let's just take a check out a few Linux commands now. So to basically see the files that you have in your system, just type in `ls`, right? And if you want to move into the directory, you have to put `cd`, right? Change directory, and let's say desktop, right? And then let's say `ls` again. So this is basically how you `cd` into the desktop directory. Now if you want to move into another directory, all you need to do is `cd ..`, and you move back here. And if you see `ls` now, you are back to square one where you can choose anything else, right? So if you want to clear this, you can just type `clear`, and you'll basically have your terminal good as new, right? So basically, you want to know what is the user that you are in called, right? So all you need to do is type in `id`, right? So this is the name of the user that I have created, and it's called kb, and all you need to do to find out which user system you are currently on is just type in `whoami`, right? The moment you do that, your system user will be shown to you. So let's go back and check out something else. So now you basically see, if you type `ls`, this is all the directories that you have in your system, like we talked about: bin with your bin files, with your library files, the dev file, the etc, home—all of these are there. Now what we can do is check out some of these directories that we have ready. So let's get going. So let's check out what is there in the bin file that we have, right? So let's do, let's choose to actually bin and choose it. We can do `cd bin`. Now we are inside bin. Let's check out the files that are there. So as you can see, these are the various files that are present in the bin, right? If you can check properly, you will also see that the `ls` command that we have is also a file that is present in the bin file, repeat in the bin directory. So a command itself is also a file. Now this basically shows us that everything in Linux is basically a file, right? Now apart from `ls`, I can show you some other files which we talked about which are directories as well, like bin itself is another file which is present in usr and is a directory in itself as well. So as you can see, `ls` is a file. So let's go back to our term, right? So let's now check out, clear this out, right? So let's check out this command called `cat`, right? So `cat` stands for concatenate. Now what concatenate does is basically takes any file and it shows you the binary and whatever is there. So this is basically the binary encoded file for your `ls` file which is present in the bin directory, right? So even for a command like this, you will basically have a binary encoded file which is there, right? So this is what `cat` does; it takes a file and shows you the contents of it, so the machine understandable language that is this, right, is shown to you, right? So let let's go back and clear this up, right? So let's now check out another command which is the `cp` command. Let's say you won't copy, repeat, let's say you want to copy the contents of a file into another file that you make, right? So let's check out what you do for that, and you need the copy command which is written by `cp`. So first you write `sudo`. So `sudo` is basically a command which gives you permission to access administrator files, files that you do not get access to generally, right? So `sudo cp ls correct`, and `ls` is the file I want to copy into my name file which is correct, and that's it; it's been copied. Now basically, since I copied the contents of `ls` into this new file which is called correct, let's see what happens when you `sudo cat correct`, right? So as you can see, different files in `ls` are basically now here copied into the file which is called correct, right? So this is how you copy files. Let's go back. So next up, let's just talk about another command that we have called `rm`, right? So let's say `sudo rm ls`, right? Now let's go, let's say `ls`. So as you can see, we've just removed the file `ls`, right? First what we did is we copied the contents of `ls` into correct, and now you can see we've removed file `ls`, and this is basically not there in the directory anymore. Now basically, as you can see, there is no `ls`. So let's check out correct because that's the file we copied it into. As you can see, correct has all the files that were present in the `ls` file, right? So to change that back to `ls`, all you need to do is `sudo cp correct ls`, right? And clear it out, and let's just check it now. Now if you go check `ls` now, the copy of contents of correct are now in `ls`, and that is how you can basically copy and paste any of the contents in your folder into any other folder, right? So let's check out something else now. So let's just try something out. So since we know that every single thing in Linux is basically a file, so the command just like `ls`, the command `cat` is also a file. So can you really concatenate a cat folder? You could write `cat cat`, right? So this is exactly what happens; you go on and on and on, and this is basically your cat folder, and it keeps on going until you do this. So we'll just clear this out. So you can basically concatenate the concatenate file with the same command, right? So this is pretty interesting. So let's not go check out some other directories that are there, right? Let's check out let's say your library, right, or the `sbin` that you have. So these are the `sbin` files that you have. So let's check them out. Let's see if we can really do something, you know, right? So there is this command called `adduser`, which is also a file which is present in the `sbin` directory, right? So let's see what happens when you have `adduser`. So let's basically say we want to create a new user that is basically the command for adding a new user. So let's do `sudo` because you need administrator permissions, `sudo`, and then `adduser`, and let's say a new user's name, right? So this is going to be, right? So basically what you need is a full name. Let's say you can just write. So now you basically have created a new user called edureka which has a full name of code P, and you can basically skip these. You want to add all of the room number, work phone, and home number; if you want to, you can do that, but the entire point of this is to show you how you create a new user from an existing user, right? So basically, let's go back and check something else out, right? Then let's go back into the directory `ls`. Let's check out some other directories now. Let's `cd` into, let's say usr directory. So as you can see here, there's a separate bin that is there here inside the usr directory as well. So if we `cd` into the bin directory...
That it has; see what's there. So, as you can see, the bin directory is kind of similar to your root bin directory that is there. Now, if you can check, there are most of the files that you see here are already there in the root bin directory, right? So, what is basically different, and which directory are you using when you basically store files? Where is the file getting stored, right? So, to do that, you will basically have to type in this command. Let's say, which ls are you using? So you use the ls command which is stored in the user directory, right? Same, let's go for which cat, right? Which concatenate; same here with the user directory; which cp. So all of these are there, present inside the user directory, right, and not in the root bin directory that you have. All those files in the root bin directory and your user bin directory are kind of similar, except there are certain more files that are present in the user directory, right?
So let's now go check out some of the other directories that are there. So let's just—right—so let's check out some of the other directories that you have. So the boot directory will consist of files that you have to boot, right, that you need to boot. Now, the temp directory is the directory which has temporary files that are present there, right? The media directory is basically the directory which lets you connect or mount any external storage device uh automatically. So if you cd into media and check out what's in there, there is no other external storage device that is in there right now. So there's nothing in the media file also. So let's check out some other directories that are there, right?
So let's check out the home directory. So home, as we talked about, is the directory which contains the user's personal directories, right? So if you ls into this, you will see that there is another new user that's been created, which is it Eureka, right, along with the KB user that was there. Now this has only been created because we've used the add user command, right? So this is basically showing you all the users that are present. Now, if you want, let's say, anything to them: cd KB and ls into this, you can see that your personal directory and files are given, right?
So next up, let's just check out some other folders; let's see, right, right. So let's check out dev, which is the devices, right? If you check out the devices—so if you go into devices, what you can see is SDA and sda1. So these—these four that you see here are the various virtual drives that you have; virtual disks that you have on Linux, right? So these are the various devices you have. So if you go back, let's say, clear it out, right? So and finally, let's go check out what proc is, right? So this is basically a file which is not really there right now. Proc is basically something which is created every time your system starts up; it's not there when your system shuts down. Every time it starts up, it has a file called proc. Now this proc file will basically have information related to the ongoing processes that you have, the memory management, hardware management, hardware configurations. So every Linux system has a proc file, no matter which version it is, right? Whenever you start up a Linux system, you will have a proc file.
So let's go back; let's check out our network directory now. So the network directory, we have to cd into etc, right? If you will ls into this, you can see the networks right here. Now you can cd into networks, right? So this is basically what you have; this is your network. Now what you need to find from here is the different files that you have. So these are different files; let's say you cd into this, right, and you will ls into this; you will have these files, right, and you can just check the VPN connection using, let's say, cd open, right?
So finally, what we'll do is check out where the hidden files are there. So you can just—so as you can see, this is basically the computer where you have all your directories, and you have—all of these are visible, and you have hidden files, because Linux allows you to have hidden files. So to check out the hidden files that you have, all you have to do is Ctrl+H, right? All these are basically—right. So as you can see, these are all authenticated files, and so if you just go into this and do Ctrl+H, you can see the number of files that are there have increased, right? These are other files that are there, right? So just to see the files which are hidden in Linux, all you need to do is Ctrl+H. [Music]
Now let's talk about RPM. So the full form of the RPM is Red Hat Package Manager. The files used by this program have an extension of .RPM. RPM was originally created in 1997. It is free and released under GPL license. It is default packaging for distributions which come under RHEL, CentOS, Fedora, etc. So to maintain packages—by maintaining I mean adding, updating, deleting packages—in RHEL, CentOS, or Fedora, we use RPM. So if you want to install any package in CentOS, there are commands like rpm -ibh then the name of the RPM. For example, if you have got MySQL RPM with version 5.7, so let us suppose the name of the MySQL argument is mysql.5.7.RPM. So this is just a pseudonym which I'm creating right now. So what you have to do is rpm -ibh, and then it will install your package.
So let's check all the features first. First feature is crypto: the packages in RPM can be verified cryptographically by MD5 checksum and GPG key. So to check the integrity of any file, we have got md5sum. So to verify that package has not been changed from the source to a machine, we use md5, and then to authenticate that whether it is from the correct source and there is no one behind the source and is proofing it and getting into your system, you need a GPG key. So you take a GPG key from that machine, then install it. Authentication source archives is also available which helps in authentication. So RPM helps in patches also; patches can be applied which helps in updating the process faster and easier. So if you have patches, you don't have to reinstall your system; you just have to change particular some few files and just rebuild it; restart it. It's not that you're again going to compile your whole program and then going to restart; that is automated. And installation time verification; it is done for the dependencies; like if I have a package and it is dependent on 15 or 20 different other packages, so it asks you to download them to carry on with the installation of your current package. Tasks for any package manager: installation, updation, and installation query and authentication. So we need to check how to install a particular package, how to update an existing package, how to remove the currently installed package, get information about the package—for what is the version which it is using, things which it depends on—and then authentication to verify the package for the security reasons that the package is from an authenticated source.
Red Hat developed RPM packages can be found at Red Hat Enterprise Linux CD-ROMS, Red Hat Network, or Red Hat Errata page having a list of packages. So if you go to any of this link on the internet—I'm just going over there—and with—I'm going to search MySQL, so it gives me all the versions of the MySQL. So it suggests that, transform 95 RPMs, very old ones, 5.0 since 2009. So we can see till the packages: MySQL client programs and shared libraries for 64-bit machines; this one is for 32-bit machine, i386/i686, x86_64 is for 64-bit architectured machines. So there are different RPMs for different machines. Now how to install? So to install, -i is the option, but we probably go for -v also because it is the verbose mode, and it suggests that okay, something is going on; because if you just install any RPM package with rpm -i, it will be installing it, but there will be no status bar in it that okay, 10%, this is now 10, 20, 50, 100. So to get that feel that okay, your software is being updated or software is being installed, use verbose also, and then print hash marks of the package archive just as it is unpacked; we use -h. Usually we use rpm -ivh. Now check the RPM signature; to check this signature, we have this command --checksig. So it checks the PGP signature before installing any package if its integrity and origin is okay, because at the background it checks for your MD5 sum as well as your GPG key. So if integrity and origin is okay, then one can go ahead and install that package. If you have any query on that package, -q is the option. So it is pretty straightforward till now. If you want to have a query on a package, it's -q; if you want to install, that's a little bit different. When you want to uninstall a package, it is like eradicate -v. So we will come up to that. It checks the dependencies of the package; if a package is dependent on some other packages, to ignore these dependencies use --nodeps. rpm -q --nodeps and the package name; one can check if a particular package is already installed or not. To do that, just add -l. So -l is for list all the installed packages. So if it is installed, rpm -ql. Now to install all the packages which are there, to view all the installed packages, use -qa. So rpm -qa. So one can list all the recently installed RPM packages. One can shorten the list to check for recently installed by adding --last, which will return the last package installed on the machine. To upgrade a package, you need to do it -u: rpm -uvh; -v is again for verbose and -h for hash. So rpm -uvh, and then your package will be upgraded. Now to remove a package, as we have discussed, it is -e rather than -r or -uninstall; so it is like eradicate. To remove a package, choose -e option. In case you don't want to remove the dependent packages, you just want to remove your package, then apply --nodeps in it. To find the package to which a particular file belongs to, use -f in your query. So -f will give you the file name. To find the details about a particular installed package, again rpm -qi and the package name. To verify an RPM package, use -V option, because small -v is for verbose; so used by this hyphen capital V option: rpm -Vp and package name will give you the verification of the package. So to verify all the packages, use -a rather than -p; just remove -p, because -p is for specific package name. If you go for -a, it will verify all the packages and resistor. So this RPM demo can be done on CentOS or Fedora machine. Right now in our setup, you are using Ubuntu, so let's check it out how it is being done. So if I'm going to install rpm -ivh, you can see those hashtags coming. So if you're not using -v -h in there, or -h is been there, these will not be coming. To verify whether a package is there in the files or not, just use rpm --verify. To query your a particular package that what are the things which are there in the package: rpm -ql httpd. So we know that httpd is there for hosting web servers. So this is—if you go to etc folder—this is how it looks when it is being installed. So it gives you all the files which is packaged in the RPM folder inside any RPM.
Now let's talk about yum. So RPM was the package manager; yum is again another which is being used in the free versions of the CentOS. So if you don't have that .RPM files and you want to install from the source repository which you are not off—because in RPM files you need to have that .RPM downloaded; if you don't want to download .RPM, you don't want to take that headache of downloading .RPM from the internet—what you can use is you can use yum. So yum was created in 2003 and is the primary choice for RPM-based distros. So wherever we are using RPM-based distros like CentOS, Fedora, yum is the repository for it. We tend to do in yum; we just write the package name which we understand. So I don't know the version of MySQL; I just go for yum install MySQL. It will search whether MySQL is there in the repository; it will come up with a specific version number; it will suggest okay, it is there; install it via this command. When you do that, you don't know where that RPM package is kept or whether even an RPM package is kept or not; it automatically downloads that package, installs it. So installing and updating the packages are simpler; software dependencies are taken care of and installed along with it. Because if you are using an RPM package, we have to install all those dependencies by ourselves, but in yum it is just like apt-get; it will install all those dependencies. So we have two things: RPM and yum. The same thing which RPM and yum is, is almost synonymous to dpkg and apt-get. So if you want any package to be installed manually in Ubuntu or any Debian Linux distro, what we tend to do is we use the dpkg command to install it, and the extension of the file is .deb; similar to what we have in CentOS, we use the same mechanism; we use rpm -iph and the extension of the file is .RPM. And in the same way, yum has replaced RPM to some extent; apt-get has replaced dpkg to some extent.
So let's talk about yum first. Software dependencies are taken care of and installed along with it. Yum is primarily a command-line interface, but GUI-based wrappers also exist, but it is pretty simple in command-line interface; it's easy to use in the command interface. It is the official package manager of Red Hat and CentOS; is there—but this is the official package manager; this is the package manager. So RPM, and RPM is the package manager which installs the package; yum is the repository management tool which will fetch the package. So to get MySQL installed, you need to find it on the internet where you can get .RPM files, but if you want to install it via yum, you don't need the file; go yourself, take the pain by yourself and search it on the internet, downloaded, and then install it. So you don't need to do that in the—in here; you just need to list the files, okay, whether it is listed or not; if it is there in the source repository, you can install it, and you don't need to know what was the source of it, where it has installed; that headache is of yum. Repository yum fetches appropriate packages as required by our—our Linux, which is compatible with our Linux. In RPM, it can be that I have, like, been sent to us 7; the default Python version is 2.7, but by mistake I go and I don't use yum; I install it by RPM and install Python version 2.4, which is a very old version, so it is not compatible. So to not—to not take the headache of what is the compatible version of the software with this Linux distro, it is advisable to use the repository manager. RPM can alert you to dependencies but is unable to source additional packages. So in RPM, it will check these are the dependencies which need to be taken care of; it will invoke an alert to you that you need to install these packages first, but it will not give you the source directory or source from where to get these services because these packages, but yum finds out all the dependencies and also the additional packages. Install step: if you are installing any package via yum, by default it has multiple repository locations in its configuration file, and it fetches packages for installation.
So how to install using yum? Use command install to install a package using yum. So if I need to install anything, just do yum install python; I don't need to give the version of it. If I'm going to use 2.4, 2.6, like, by default in CentOS 5, 2.4 was there by default; 2.6 was there in CentOS 6. Now in CentOS 7, it is 2.7, but if you want to go for 3.5, 3.6, or 3.7 version of Python, you need RPM for that, but via yum repository, or you need to tweak the yum repository a bit; you need to go to the yum source repository.d and then tweak over there. So the first syntax is yum install python; it will ask you if you are interested to install this package or not; just a question on it. If you don't want—if you are writing a shell script and you want it to be installed by itself—just insert -y command. The same thing happens with apt-get; same thing happens with yum: yum -y install package name python; it will be installed and it will suppress the confirmation question and it will take the input as yes that okay, it just has been already been provided; installed automatically. To remove: yum remove package name; and again to provide confirmation and suppress the confirmation and automatically do is hit -y. Then list package names. So if you want to check whether a specific package is there in the source repository or not: yum list any specific package name. So it is checking for openssh-server, which is my SSH server which listens on port 22, and if you want to connect from one machine to another, there is a service called /usr/bin/ssh, so that enables you to SSH from one machine to another machine, which we just had an example of ssh username@your machine IP. So that's the package we are searching for: yum list openssh. To list all the available packages installed, use install keyword: yum list installed. And if you want to check all the packages which are there in the yum repository, just write down yum list. Use command if you want to search any package; use command search to find all available packages to match the name of package specified. If I don't know the exact version of it or exact name of it: yum search ssh or openssh anything. So it provides its exact package name which needs to be installed. To find which package provides a particular file—because if you are seeing some file in a system which you haven't created and it is there by some package—you can search the originative package for the file name using command yum provides filename. Again for updating any specific package—for right now I am using Python 2.6; I want to update to Python 2.7—yum update package name. If that update is available there, it will update it automatically. And to check for which packages updates are available, you can write command yum check-update. If you want to update the whole system, just like Ubuntu upgrade: update and upgrade was the job; update is there in CentOS. To list all the enabled repositories in yum, we use command repolist. So to check what are the repositories which are there in my yum, yum source directory: yum repolist. To view both enabled and disabled ones, because few repositories are commented. So to check all those: yum list all. To install a specific repository: yum --enable repo the repository name which was disabled, so enable that repo in the package name. To view all those commands, the other few commands in yum are: yum history—check what are the things which you have executed in yum previously; yum clean all—so it removes all the cassette packages and header created to resolve the dependencies; yum grouplist—which lists yum groups; group info, group installed, and then group remove. Demo about the yum commands which we have just gone through. So we have searched; we have checked that to list a package, it was the command yum list. So we are just listing the package with yum list openssh. Now it is going for all the packages; all the repository; it has probably—it is going to the FTP server of IIT Madras, so ftp.iitm.ac.in, and from there it is checking for the openssh update a package. So again yum update openssh was there. So if there is any update available as per the source repository, it will update it. Install a package. This is a pretty cool package in Linux; it enables you to run all those executables of C of Windows machine, so Wine; so xvrp5fan or nfsfan. So you won't be able to get those things on Linux distributions because Fifa or NFS doesn't support Linux distributions. So if you want to run Linux distribution too, you just need to install Wine, so one application enables you to run exe's—auto source. Actually these windows files are executable formats; exe format. So yum enables you—
To run your .exe files, so what it has done is you have installed one, and then it will be installed. So right now, `yum history` tells you about what are the things which have been done in the last two times. So it says that `yum history` has got 34 commands in it; last one was install libex11 development package, and before that it was update. Accents is also defined; date and time is also defined. Now, how to search for a package? So it is `yum search open SSH`, which it has been done; it is now searching for the package. What are the packages available with the name open SSH? You can see there are many different packages which are available for open SSH. Choose any one of the open server, open SSH client, ldap, GSI base, Pearl based, anything which you want. If you just want to open a server on your machine, install using `open SSH server x86_64`.
Now let's get back to dpkg, Debian packages. Dpkg is the main package management system in Debian and similar OSS. It is used to install, build, remove, and manage packages. Package for it has an extension of .deb at the end. Dpkg is a low-level tool; apt is commonly used as a high-level tool, as it can deal with complex tasks involved in package management. The dpkg database is located under `/var/lib/dpkg`. Dpkg is almost similar to what RPM is there in CentOS, and yum is similar to what apt-get is there in Ubuntu. So how to install? Again, just like RPM, we used to install via `rpm -i`, so similarly `dpkg -i` package name. So if I have that Debian package with me, like if I need to do an installation by RPM, I need to have that RPM package. So similarly, I need to have the .deb package to be installed by dpkg. So I'm installing Python 2.7.deb, so `dpkg -i python2.7.deb`.
To check whether your dpkg premium package has been installed or not, you can use command `dpkg -s python`. It will show if the package is installed, and if it's installed, it will return. Again, to list packages: `dpkg -l` package name. If you want to list all the packages, don't add the package name. If you just want the content which is being used in Python 2.7 Debian file, like the last time which we saw for httpd, we list all the file names of HTTP. Similarly, over here we did that with `rpm -qf`. Now, in this scenario, we can do it with `dpkg -c`. To remove a package, just like in RPM we did via `rpm -e`, we have got `dpkg -r` the package name, and now it is not required to give the .deb extension of it.
Now installing the packages from the directory itself. So we need to install all the packages which are there in the directory `-r` because it will install all the packages recursively. So use command `-R` and then `--install` and the directory name. So it will install all the packages which are there in the directory. So if you've got 15 packages which you need to install, you can do this; you can put all those 15 packages in the directory and then install recursively using directory; you don't need to give the name of each and every package at the time of the installation. Now to update a package, like we have to update python, you need to do `dpkg -u` a specific package name.
Now let's check that demo. So `dpkg -s python`. Now let's check the `dpkg -s python`. So it suggests python is not installed and has got no information on it because this file has not been installed using Debian package. If I ask apt to install python for me, it will check and install the python version 2.7. Now I have installed Python 2.7; it is unpacking and linking all those libraries and processing things up for me. Now let's do `python dpkg`. The thing which I have done is `dpkg -s python`. Now it suggests package name is python; status installed; okay, installed; priority is optional; it gives all the information about the package. I have done pretty good because I don't have the .deb package right now with me. So now `dpkg -l python`. Let's run this command and check what does it give. So it gives me the python version of 2.7.15.
Now let's get to apt because you would be using apt package manager very frequently rather than using dpkg. Apt is the command-line interface to handle packages using apt library, just like the yum library it we used to have in CentOS; we have got apt library in Debian-based Linux distros. It is the default package management system for Debian-like distro like Ubuntu. It is an efficient way of handling packages in your system rather than using dpkg. It is advisable to use apt because dependencies are managed automatically; upgrades and removals are handled carefully to maintain the stability of the system, and it has an external UI support with tools like synaptic, aptitude. But right now we are not using any tool like synaptic or aptitude; going via command-line interface.
Now let's understand few commands first. `apt-cache`. `apt-cache` is a command-line interface to search for apt software packages. This tool is used to search software packages and get information about them. One can search for a package without having the exact name of the package; if you even have some pattern of it, you can get it from the `apt-cache`. The data is fetched from different sources listed in `sources.list` file. So as we saw in yum, `yum repolist` was there; similarly, we have `upgrade sources.list` over here. So it has got a number of links from where it searches for its packages and installs it. Where cache `apt archives` contains already downloaded packages to avoid downloading them again if one needs to reinstall a package after removing it. So now uses of some of the `apt-cache`: How to install such a package using `apt-get`, use command `package names`. To list packages in certainly particular string, so example, if you just want to search all the packages which are starting with open, might it be openSSL, might it be openSSH, anything what you need to do is `apt-cache package names` and open; openSSL or python, anything. So that will fetch all the package names. You search for a package with particular name: `apt-cache search python`. Use command `show` to get details about the package. If I want to get all the details about a specific package, I will use `apt-cache show python`. Check the dependency of a package, like if I install python, what are the other packages which will be installed, which are required in support of python to enable python to run; whatever the other packages which are required to run, we can get that via `apt-cache show package python`. Now to update a package, use `apt-get update` specific package name. So if you are to update python, we would be using `apt-get update python`. If we have to update the whole system, `apt-get update`, simple. And then if we want to install a package but prevent from upgrading if already installed, use `--no-upgrade` options. Now to install a package, `apt-get install` package name. It was for updation. Now let's go how to install a package rather than using update, just choose `apt-get install` package name. If you want to install multiple packages, `apt-get installed` multiple packages; python, MySQL, open SSH, anything, and again you might need to provide `-y` method. And some of the previous version like in 16.04, it used to ask for the confirmation to install multiple packages. Having a particular string, use wildcard. So all the packages in the `sources.list` which is having star named as regular expression in it, it will install all those packages. Now `apt-get upgrade`. If you want to upgrade the system, you can use command `apt-get upgrade`. It may remove or update some of your installed packages. If you want to upgrade only some specific package of your system, you can use `apt-get install python --only-upgrade`. It will only update python; it will not upgrade its dependent packages. Now if you want to remove, `apt-get remove` specific package name. If you want to remove all the configuration files associated with it, what apt does is apt stores the configuration file because in future if you reinstall the package you don't have to take care of the configuration again. But if you want to remove the configuration file along with package, `apt-get remove --purge` package. Removing the package doesn't remove its configuration file. To remove the configuration file along with it, append with purge option, use command `download` to download a package without installing it. So if you are downloading the package, just get `apt-get download python`. So if you want to get into the source code of any package, because we are using Linux distribution, everything is open source over here, we can view source code packages of any package. So in that scenario, we can use `apt-get source python`. So it will unpack the source code of the Python. To check for the dependencies, we can use command `apt-get check`. So if we have to check the dependencies of python packages, we have to check python. To install build dependencies, use build-dep options, such as there that whenever you are building your product or any software where there are many built dependencies of it, to get that, `apt-get build-dep python`.
So let's get into the demo of Apt. So the first thing is `apt-cache`. So `package SSH`. So let's run it on our own system: `apt-cache`. So package, let us go for openSSH. So it says there is no open access. Now we have installed python; now it is showing all the packages into python, a long list. So what are the packages which it has installed? It has installed any JSON that might be used for the JSON conversion from dictionary to JSON in Python. Mod_python, mod_wsgi. Mod_wsgi is usually utilized for web servers if you are hosting your python packages online. Mod_python, mod_wsgi are being used. So it lists all the packages which are installed along with the python package. So rather than showing `show package`, it is showing package names, and these are default commands. If I'm writing package and using tab, it will be giving package names by default. So these are the package names which are installed along with python. So python-RPM is there, crypto-dock is there, HTTP library is there, feed parser is there. So there are many packages like that. We have already seen how to install package. Now check how to `apt-get remove --purge python`. So it is asking me for yes or no. Let's do no, and now what I will do is I'm just appending `-y`. Now it will not ask me for yes or no. By default, it has taken that okay, I have given a confirmation for deletion of this package as I have supplied `-y` command. If you can see the last line, it says purging configuration files, so all the configuration files have been deleted. Now let's try the previous command: `apt-cache package names`. So you can see even if I have not installed these packages, these are getting from the cache. It says that if you install python, these are the packages which will be installed along with it. So you don't need to install any package to check what are the dependencies, what are the files which will be installed. If I install python, I'm going to install `apt-get install python3`. So you can see that I already have python 3.6.5 in my machine, so it is not installing Python 3, and it also suggests that few of the packages are no more required: this Python 2.7. And if I return command `apt autoremove`, it will clean my disk space. It is suggesting that these packages are no more required by I think to Python 2.7, minimal python, minimal pip, python standard library, because I already have python 3.6.5. It's 18.04; 2.7 is the older version of it, so don't need these packages. Now I'm cleaning this off. Let's try `apt-get update`. So you can see it has gone to security.ubuntu.com, type.ubuntu.com; these are the source list repositories which it has, and it is installing packages from there. Now it is updating itself; it is taken if any new version is there, it will be updating itself. Now it is reading the package list; everything is still similarly. If I want to upgrade, it suggests these many packages will be upgraded if I run this command. So you can see how the Linux community is working; there's a lot of huge community and is working all day, and there are many updates coming every day. Now it has started upgrading it. So there are commands like `apt-get check`, `apt-get install python` with `--no-upgrade`.
What is DNS? Well, DNS stands for Domain Name System, and its main responsibility is to translate internet domain and the host names to IP addresses and vice versa. Well, most of you might know that every physical machine connected to the internet is identified by an IP address, but most of you might not know that these IPs are unique only inside that same domain, right? And another fact that you might not be aware of is that when you type in a URL in your web browser, then it, uh, you know, automatically gets converted to the equivalent IP address of that server which you're trying to access. Supposing you try to access google.com, then when you type in google.com in your browser, then it would be automatically converted to Google's IP address, right? And only based on the IP address is the system able to fetch Google's server and display, uh, you know, give you the results on your screen.
Can anybody tell me why that happens? Why do we do that? Why does their why is there an internal conversion into an IP address that happens? Can anybody guess why that happens? Well, that is because, uh, the URL or the fully qualified domain names like google.com, facebook.com, yahoo.com, all these .coms, right? These are the addresses of any server or machine on the internet, okay? And they are, however, only easy to remember by the humans, only for us. For computers, however, it's easier to remember; for them, it's easier to remember in the form of IP addresses. So whatever we have, google.com has an equivalent IP address; facebook.com has another equivalent IP address. So every single, uh, site and every single URL has an equivalent IP address, right? They would be hosted on a server, and to access that server, you have to access, uh, that server's IP address. So that's how things work in the background, and yeah, so this task of translating between the IP addresses and the domain names is what is done by this, uh, by this tool called DNS. Okay, so the Domain Name System does that, and, uh, well, it's a big benefit, and the people nowadays might not realize the thing. Okay, any newcomers might not know because without the invention of DNS, our lives would have been very difficult because back in the 80s, 90s, at that time when we didn't have the DNS, and if we had to, uh, access each and every website with the help of just by giving the, uh, host name. So for example, if I wanted to access google.com back in the 80s or 90s, right? Instead of giving the IP address, if I had to give the Google, say google.com, then I have to specify this in the hosts file. Okay, I have to map the IP address and the host name in the in the host file, and doing that today seems a very tedious task because we have so many websites and we have so many which we have to manually feed, and, uh, this is a manual task, right? So to to eliminate this overhead, we came up with a DNS, and, uh, boy, now it's a very big help, and a lot of our effort is saved. So that's the thing. And talking of how DNS works, it works on a concept which is very similar to a client or a server or network communication architecture. Okay, so here are systems will be the, uh, DNS client. Okay, now supposing I am accessing internet, then I would be a DNS client first of all, and then I'll be sending these requests to the server. Okay, I'll be sending the requests to the DNS server by specifying the hostname, uh, if I type in google.com in my URL in my, uh, in my web browser, then that you are then that hostname would go to DNS server; it would the DNA server would resolve google.com to a particular IP address. Similarly, if I type any other website like facebook.com or yahoo.com, DNS server would do the task of converting that that host name into its equivalent IP address and then give back that IP address to us. Okay, and, uh, the very act of sending a request is called a lookup request. Okay, and what you get back from the DNS server in the form of an IP address, that's what a lookup response. So these are the two things that are involved, and wherever you you configure the DNS server in whichever environment or whichever machine, that's generally called a DNS server. Okay, you can even it can even be a running environment, and similarly, every system that tries to access that particular server, that they are called DNS clients. So we don't have much of a configuration to do from the DNS client side, but of course, being a server side, we have a lot of configuration to do. Excuse me, guys. Yeah, so that's about, uh, this example, and another thing that I want to show you is that, um, this concept of DNS lookup request. Okay, now if you see this image over here, you can see that, uh, over here I've specified lookup request and look up response. Okay, but over here this DNS client is making a request in the form of an IP address, right? And then the server is giving back the during this response in the form of a fully qualified domain name. So in my case, dns.vardhan.com is a fully qualified domain name that I have set for my demonstration on this system of mine, okay, on this virtual machine. Now, now you might ask the question why am I specifying IP address? Now that's because, uh, the fact that of course you people know, right? You can either enter the IP address or the host name. So to represent that I've entered this, and when you enter the hostname into your web browser and when you and when the server gets back to you with the IP address, and that's called a forward lookup. Okay, so it resolves the hostname or the domain name to the IP address, whereas the reverse lookup, this one resolves, resolves the IP address to the host name. So in this case, when I send an IP address, supposing I know the IPs of a machine but I don't know the host name or the domain name, then in that case what I get back, the lookup response I get back from the server, that would be a reverse lookup, right? So there are there can be two kinds of ways in which you can access and look up. So these are the two things with respect to DNS. Now the question that can arise in your mind is that, uh, where does the DNS server get the IP addresses of the hostname, right? You can ask that from where, how? If there are so many websites, if there are so many domain names, if there are so many IP addresses for those systems inside a particular domain, how with our DNS server access that particular IP address or that particular server? You can ask me that question, and to explain that question is what I'm going to explain in this next slide, right? So here first of all we have a local system. Now let's assume it's me. Okay, I'm prano, accessing a new, uh, website. Okay, which has not been which is a very new website. So or let's ignore the fact that it's a new website. The for, uh, let's just consider that we are going to try to access google.com. Okay, so when we try to access google.com, then that request would first of all go to a resolver. Okay, now the resolver is nothing but your ISP server, and it's basically built into your network operating system, and the IP address of google.com would be built inside resolver. Okay, it would be present as a cache memory, and, uh, since the IP address will be present, the hosting would be resolved on it; the response would be it would come back to you. But in case if there's a new website which has been newly new newly published, and if that website if that IP address is not a new resolver, what happens? Google.com is famous, right? But google.com is, uh, you know, there's no guarantee that the website that you're talking about is has been accessed by someone in your ISP and it's on there in your DNS cache. What would happen at that time? So at that time, the entire, uh, we have the we have a different root hierarchy of DNS, right? So those would be accessed. Now that's where the whole concept of DNS comes into the picture, and that's where we have first of all something called as a root server. Okay, now the root server sits at the top of the DNS
Hierarchy okay, and there are about 13 sets of these root servers placed strategically around the world, and about 12 organizations access these. You know, they control these root servers, and the thing with these root servers is that they will not tell you which exactly which IP address your hostname is resolved to. Okay, if you specify apartment.com, it's not going to return back with the IP address of that particular domain. What the root server will do is it will point you to another server, okay, and that is called the top-level domain servers, also called TLD servers. Okay.
Now, when they point back to the TLD servers, the TLD servers will have further information so they can point you to a direction where you will get the IP address. So the root server will point you back to the TLD server in which your domain may be hosted. Okay, the domain that you're trying to access that may be hosted in one of the domains over here, and these one of these domains are what make up these 13 sets of root servers. So from the 13, you shortlist one of them, and those come to the resolver; it tries to access the top-level domain servers, and these top-level domain servers, they store information of these top-level domains such as .com, or the .net, or the .org domains, all these domains, right? So whether it's facebook.com or google.com, those kinds of those kind of information or details will be present in the top-level domain servers.
Now, even now you cannot totally resolve to a particular domain's IP address. Supposing I want to access a particular IP address inside a domain, that I cannot get it here, I just by this time the top-level domain only uh it only knows this particular domain is hosted under these uh servers. Okay, so what the TLD will do is it would again return back the particular domain, or let's say, let's call it authoritative name server. Okay, the TLD would return this name server back to the resolver. So based on that information, the resolver would again query the authoritative name server. Okay.
Now, the name server is what knows everything about the domain, including the IP address. So there is roots of our return back the top-level domain servers such as .com, or the .net, or the .org, and these top-level domain servers, they will return back the domains where your IP address is part of, right, and that is through the authoritative name servers, and uh yeah, that's how things happen, and then the resolver would finally get uh short uh you know, get to the IP address inside your authoritative name server, and uh finally it would it would store the IP address in its cache locally for later use. So the next time somebody else is trying to access this website in your uh you know, through your ISP, then they can instead straight away access that website with the IP addresses since it would all be present in the cache, and yeah, finally once it's present in the resolver, the resolver would send the response back to the local system. So this is how a DNS server works. Okay.
Now, uh if you guys have understood this part, then you're all set; you can understand exactly how how to set up your DNS server, which uh which which server to use, right? So speaking of which server, we have a lot of DNS servers available in the market, and Dobby what I'm going to use in my session is that of a bind DNS server. So bind is one of the most popular and one of the earliest DNS servers which was in use, and it's basically a name server, and it also be configured for mail service, and uh I'm gonna use bind; however, you can try out Unbound, or you can try out PowerDNS. We have a number of names uh DNS servers. So moving on to uh how to configure a bind DNS server, I can show you that in 10 simple steps. Okay.
Now let's see how we do that. Now that's the next topic, and uh the 10 star the 10 steps that are involved are mentioned here, right, and first of all, the most obvious of the steps is this one: you have to install bind because uh bind is a DNS service, and we'll have to install bind with the help of yum command in CentOS machines. Uh, if you are however doing this on Ubuntu machine, it would be apt-get install bind, right? So this is the first step. The second step would be to add a static IP address. Uh, now can anybody uh guess why we add a static IP address to your machine, to the to the system where you're configuring the DNS server? Anybody? Well uh see, the reason for that is uh because when we reboot our machine, so sometimes if your server crashes and then it reboots, then at that time you don't want your IP address to change, right? So for that purpose, you say boot protocol is static. Okay.
So initially by default when you're trying to configure it for the first time, you would find DHCP over here, that's stands for dynamic host control protocol, which would assign a dynamic IP address every time you reboot your server, but uh when you change it to static, then what IP address you set here, this is going to be constant; it's not going to change. Okay, so that's the uh uh need to assign a static IP address, and that makes up the second step, and along with these you need to also add these two lines of net mask and say which uh subnet it belongs to, okay, and the Gateway. So uh in my case, my IP address is 192.168.436.2, and this is what I've entered in my eth0 file, which is present under uh this directory, /etc/sysconfig/network-scripts/, right, and you also add the Gateway. Okay, and you add these three lines, and the rest remains the same, and you of course change the eth0 file, and uh moving on, the next step is to assign a fully qualified domain name for your server. Well, what's the point in hosting a domain if you don't want to give a domain name, right? So that's the whole point of assigning it, and uh you can simply assign a domain name, a fully qualified domain name by entering this file, the /etc/sysconfig/network file, and you'll have two lines; you'll have NETWORKING=yes, this will be a line which would be initially there, and even the HOSTNAME= followed by the current machine name, that would be the entry initially in your system. Okay, so when you configure it, you can change it with the domain name that you want to give. So in my case, I'm giving dns1.1.com. Okay, so you can change it appropriate accordingly; you can do that.
So once you've set the fully qualified domain name, the next step is to go to the /etc/hosts file and add the entry. Okay, this entry you've uh in your uh in this file, right, in your networks file, you've added the domain name; you've said this is your hostname; now you're defining an IP address for that hostname over here in the hosts file, right? That's the step here. These lines would uh be there by default; you don't need to worry about that. And the fifth step would be to go to your resolv.conf file. Okay, this will again be present under the /etc/ directory, and you need to add these two lines. So you need to say search and your domain name. Uh, you can ignore the DNS1 part, but you got to put your domain name over your uh in your case it can be anything, but in my case it's version.com; otherwise it can be google.com or yahoo.com. Excuse me, it can be anything like that, and of course you should say nameserver and point the IP address which you want to act as the DNS server. Okay, and this is one important step which has to be configured even in the clients, even in your DNS uh client. Okay, so supposing uh if I want to check later what is the uh uh what if my domain name is working, right, that time I will have to go to the resolv.conf file in my client and add this particular line. I will show you that later, right? I will show you that in my demonstration. So just remember that it's a very important step which you need to do even in your clients; in fact, this is the only step that you have to do in your clients, in your DNS client side, right? So then this next step would be to go and edit the named.conf.options file. So from here onwards is where the actual configuration of bind starts. So tell you you are just configuring your own network; the first five steps; from the sixth step onwards till the uh eighth, and in fact even then until the eighth step, it's all about bind DNS. Okay.
So this named.conf.options file is a file that comes when you install bind. Okay, and uh what you have to do is you have to enter the named.conf file, and you'll have a number of lines there, which of course I can't uh I couldn't print all the lines in my slide, so I have just the three lines which we have to uh change. So we have to edit these three lines, and the thing is initially when you open this file, you will have this line okay, where in curly brackets you would have localhost, like it says here. What you have to do is you have to replace this localhost with your IP address. So in my case I would be doing it with uh .52 uh sorry .256.2; that's my IP address, right, and you'll have one more line for pointing to the IPv6 port number, and this you need to comment; you don't need this line anymore. Okay, and the third line which you have to edit is that of allow-query, and you will have none initially; you should replace this with any. So that is the sixth step which you have to uh configure. When you're done with this, you can then go to the other file in the /etc/, which again uh the file name is rfc1912.zones, and this of course comes from uh comes when you install bind, and here is where you define your zones. Okay.
Now there are two concepts of forward lookup and reverse lookup, right? So I told you that when you enter the hostname and then uh you hit enter in your browser, then that's called a forward lookup, but however if you enter the IP address, that's the reverse lookup. So if you want people to query your server either uh in the forward or the reverse fashion using one of these uh uh lookup fashions, so at that time, for that purpose, you have to set up two different zones. So your first zone would have the rules and settings for what should be returned to them when they access you from the forward lookup, and when they access your server through the lookup through the reverse lookup, then the settings for those would be present under this zone. Okay, so I've just defined that it's uh the I've just defined the forward lookup as my domain name here, as you can see it's in the form of version.com, which is uh like a domain name, and for the reverse lookup of course it would be from the IP address. So for this reverse lookup I've said it would be in the form of an IP address, and I've named it as reverse.zone. Okay, and similarly, file would be forward.zone. Okay.
Now uh this file RFC, your file, this is going to be again a very long file, and you'll have a lot of lines there, and uh these should be this would be placed in that, so you would understand this bottom and I open the demonstration, so stick around till then till you understand this completely because it's a little tricky at uh this step. Okay, and then moving on to the next uh point, the next step is the configuring of the forward and the reverse zone. So whatever we have configured over here in steps, and we have created the forward zones here, we've created a new file forward.zone and created a new file reverse.zone; we have to add the uh we have to add the rules over here, so that's what you're doing here; you create one and then you open them, and you will have a basic template, and you'll have to edit that template and replace that template with your hostname and your IP address. In the forward.zone you would replace the template, the template with your domain name, and in the reverse or zone you would replace your template with your IP address. So these are the two things that you have to do, and when you do this your DNS server is uh well and good. Okay, but however you might also want to change your group ownership of those two files. Okay, this is a minor step that's needed; you're just setting it root access, full permissions, and uh yeah, that is the final step. When you do that, you can just restart your named service, and uh your service would be up and running, right? So these are the 10 different steps which are needed, so I can now get started with my hands-on, right? So let's see how to configure this bind DNS server in 10 simple steps through my demonstration. And for my demonstration, what I'm going to do is I'm going to open my virtual machine. Okay.
So uh this is my virtual machine, as you can see I've already set my domain name here; it says dnsborn.berton.com; this is my machine name. So let me just open this up. So first and foremost, let me just check what's my IP address; that's 192.168.56.2. The IP address did not change because I followed my step and lab assigned a static IP address for this, right? So okay guys, so I hope you can see the uh VM clearly now, right? Now uh the first thing of course that you would have to do is to install bind, right? So the command for that is uh sudo yum, well what I'll do is I would uh enter as a sudo user. Okay, yeah, the first command is to do a yum install bind, and uh I'm gonna give asterisk because there are multiple packages that come with bind, so I would want to install all those uh utilities, especially the one that's a chroot and util's package. So when you give asterisk, all the associated uh packages would be there, and since I have already the latest one installed, I have nothing to do. So the next step would be, let's go back to step number two, would be to assign a static IP address, so I've done that, and let me just verify that and show it to you once. Okay, so let me open this and show it to you. So I'm going to do a cat command here, or let's do a VM itself; let's see this says /etc/sysconfig/network-scripts/, and I want to edit my eth0 file. Okay. Okay, so one minute. Oh yeah, eth0 file. All right, so here we go. These are the settings that uh I had told you that I had already done; I've assigned my IP address here; I've um mentioned it's going to be static. Okay, I've also added these two lines, a net mask and Gateway along with my IP address. So this is something that you also have to do. So let me just uh close this now. Going to the step two is all about ascending of of uh you know, assigning a FQDN for my server, right, fully qualified domain name, so that we can do by going to my /etc/sysconfig/network file. You can again change the domain name as per your wish, right? So this is the important thing, and uh the next step would be to configure the /etc/hosts file. Okay, you have to add your uh whatever domain name that you've created, you have to add the IP address along with that. Okay, so let me just uh open that file and show you that I've done the same thing here. I have my IP address, and I've also specified my domain name for this particular IP address. Okay, that's done with step number four. Now going to step number five, we have to then go to our resolv.conf file. Okay, so our resolv.conf file is again present over here, and as you can see uh I've said search warden.com. Okay, now uh I've mentioned my I mentioned my uh domain name, but however there's one problem over here; the nameserver is wrong, so it's pointing to 8.8.8.8. So let me just change this to my IP address which I want to set for my uh nameserver, and uh let me also okay, so I can also comment these two lines; I don't really need these two lines. Okay, so I'm going to comment them; I'm gonna just uh save and quit. All right.
So going back to my step number six now is where the uh who will bind task starts. So bind, like I told you, it's one of the most popular uh DNS servers, right? So let's edit the named.conf.options file, which is given by bind. So here we go, and uh this is the file here, and this was the line that I was talking about. Okay, you would have uh localhost specified over here, and you'll have to change this with the IP address of the server on which you are of change it with the appearance of the machine that you want to make your server, okay, DNS server. In my case it's my IP address, and uh you have to comment this line of yours, and then you'll have the allow-query, right? So here you have to specify any. So these are the three uh settings that you have to do in your named.conf.options file. Okay, when you've done this, you can just quit, and then you can to go to the next step, that is configuring the rfc1912.zones. Okay, you define the zones over here now. Okay, so this is the file, the RFC file, and as you can see this is my uh this is the this is the thing which is pointing to my forward zone. Okay, I've said warden.com is my domain, and uh I've said type master; it's going to be the master; it's not going to be the slave; it's going to be the master over here, and I've said the file name is forward.zone. Okay, uh when when we say file forward.zone, it basically means the settings for uh the rules that you need to follow that you need to return would be present in the file called forward.zone, and uh this forward.zone would be present in the directory that is uh /var/named/. Okay, uh that is a directory that you can set in your named.conf.options. So the file that I opened previously, in that we have to set the path. So let me just uh quickly open back that file and show you what I'm talking about. So over here, along with uh specifying these three lines, I have something called as directory, right? So whatever uh files that my DNS bind is going to create, so that it would place it in the /var/named/. So even the forward zone and the reverse zones which I'm going to configure in my RFC, those would be present outside inside this directory. Okay, so that's why we have written forward.zone, which would be the name of my file, and uh similarly explaining the other lines, dump-file again over here is where your uh cache and your logs will be dumped. Okay, and then you have a statistics file where you'll have other details; these are not uh we don't need to really worry about these details for now. Okay, we just need to verify that it includes the rfc1912.zones because you are defining your forward and the reverse zones inside this location. Okay.
Now now going back to the rfc1912.zones, I explained uh this part. Okay. Now what you have to do is one minute guys, yeah, sorry for the delay guys, one minute. Okay, yeah, so what I was uh what I was talking about is uh setting the forward zone; we've done that here. Now we need to go down, and you would see the reverse zone right here. Okay, as you can see, when someone queries me with the IP address of my system, that time uh we are specifying the rules for that in this file called reverse.zone. Okay, and the second would be present in the same directory, and one thing which you would find strange is we've uh we have the subnet in the reverse order. Okay, now that's because uh that's how rules are defined, so you don't uh this is the only thing that's going to be different; instead of giving 192.168.56, you would have to give it the other way; you have to first specify the class C, then comes class B, and then class A. Okay, the subnetting order is a little different over here when you specify the reverse.zone; the reason for that is in the reverse.zone you specify the number of your IP address; so in my case it's 2, so I've specified the 2, and I've followed that up with the rules. So for that purpose we specified in this order. Okay, you
Would understand this better later. Okay, so right now you might get a little confused, so just hang around. So let me just uh, quit and exit this now. Going back to my slides, the next step is to actually create the forward zones and the reverse zones. Okay, and then open them and use the template to basically create a rough forward zones and then edit them. So now those would be present. Okay, let me first clear the screen, guys.
Okay, so let me do uh /VR/name d and uh I can do an LS first. Okay, so as you can see right now we have something called as namely.localhost. Okay, now this is the uh file that provides the default template. Okay, now the forward.zone and the reverse.zone is what I created based out of this. So using this I created these two files and uh let me now show you what I have made changes in these two files. Okay, so this is my forward.zone which I am first editing and as you can see uh we have in the first line it says TTL. So TTL stands for time to live and uh we say that as one day. Okay, and when we say add the rate it basically means uh rules for all. Okay, and uh in specify stands for internet and SOA stands for state of authority. Now these are a couple of terms which you might not understand when you get started with DNS right away. Okay, so the state of authority we are going complete when we say add rate in SOA we are giving complete authority to this particular domain. Okay, that's what's happening and uh right after specifying SOA with the tab space I have set dns1.1.com. This is my fully qualified domain name. Today I'm giving complete uh Authority. Okay, along with that I'm giving root. the fully qualified domain name. Now the one rule which you have to notice after I give the fully qualified domain name I finish it with uh append that with a DOT. That the same thing goes over here and over here. Okay, uh this is basically to indicate that your domain is ending. Okay, this is a syntax so you cannot play around over here. So just make sure that you have a DOT and if there's any time if there's an error make sure that you check this because most of the time errors would be because of giving of failing to give a DOT somewhere here. Okay, and these are again set of rules which you don't need to really worry about. These are the rules when something goes down it it's it's about the backup. Okay, so what you need to uh just edit is these two lines in your forward.zone but I've said again with transfer internet I've said that the forward.Zone over here would act as a name server. Okay, so I'm sending up my bind as a name server which would basically resolve IP addresses and host names. Okay, so NS stands for names. However, if you want to configure a mail service over here then you can replace NS with MX and similarly other options. Okay, with bind of course you have these two options and I've added name servers name server and I've said my server is dnsbond.barton.com. Okay, and the domain the DNS one have given the IP address of 192.160.56.2. Okay, so whenever this domain is uh queried then the address for that query over here is the server. Okay, the server address would be 192.160.56.2. So that's what the forward Zone does. Now let me just start quickly exist and Open my reverse Zone and here the only difference that you would see is the last line over here. Okay, so we the other rules are the same you are saying complete state of authority to your uh to your domain name here and then these rules are the same and uh you're also defining the name server for dns1.1.com which is my domain name but instead of a we have PDR. So a over there stands for address right uh that's pointing to your address but when you say PDR it's basically pointing to your IP address so because it's a reverse lookup right so from your iPads it's looking up to your domain name so that's why we replace this with PDR and this all this is the syntax so you uh say PDR and then you give the uh if it's a 56.2 in my case so I've given two over here. Okay, now some of you might have had a doubt why I gave that in Reverse uh 192.168.56. So that's because the Rules start from here so it's 2.56.168.192 so uh it would look up in that fashion right. So now I hope now you would have understood why I did that and uh yeah that is pretty much it and this is all that's needed to set up your DNS server. Okay, so let me just quit this again and uh you want to clear the screen. So the ninth step that's uh that needs to be done is that of changing the group ownership of these two files. Okay, you give them complete uh root access uh this is something that I've already done so I don't need to uh brush upon this. And finally the 10th step is to restart your namely service. Okay, now let me just Supply the command for that. Okay.
foreign service namely restart. There's a command to restart my service and it says it's stopping my service. Okay, and it started my name service. Great. Now uh to check if our connection is up and running we can do a dig command which basically uh digs for our name service and as you can see it says that uh the status there's no error and it's uh giving you all these details but to understand better you need to just look at this particular server if this is coming perfectly right. So the server that you set your DNS service for is uh this one 192.168.56.2 so that is coming up here it's uh perfect and it also says it's it's under Port 43. uh as we suggested. Now you can verify this in another way by supplying this command NS lookup command and specify the domain name uh in my case it's dns1.warden.com. So when I hit enter you can see that it says the server is my IP address uh the address where it's hosted is port number 53 inside the same IP address and the domain name is this and my IP address. Now similarly when I do a reverse lookup.
Foreign I can do a 192.168.56.2. When I do this it returns me my domain name again right. So this is the server this is the port number and where it's running and the uh lookup done in Reverse fashion right and uh it's pointing to my correct domain name. So this is what a DNS server does. So this is how you set up a DNS server guys. Now some of you might you know have a doubt as to okay we've done we are doing the lookup from the server that's why we are getting to see the details uh the correct details here now right. So you're not uh you know having a verification you don't have a verification as to if you can actually see this domain name from other systems also. Now to answer that question I can show it to you from a different VM. So this is one VM I can go to my second VM here right and let me open up my terminal first of all uh okay I'm going to do a ifconfig and yeah this is my IP address of this VM. Okay, now let's see if this from this VM if I do a reverse lookup sorry if I do a lookup to my uh domain name let's see if it's pointing to the correct address right. You guys notice that this has a different IP address right. Now let me Supply the same command and let's look up and say my uh my domain name here warden.com. Okay, and when I hit enter uh okay so it's giving an invalid address. Now that's because we have not set the name server right. So there was one point number six which I told you that we had to do even on your client side. Now it is this point this one right where you you configure the resolve.confile you have to set the name server which you want your system to look up to so that is what you have to do over here. So at every client if you want to resolve the domain name you have to do that and uh the command for that is uh resolve.conf. Okay, and there goes the password. As you can see we have the default ones over here. Now let me replace let me first comment these two lines and change the IP address over here and point it to my name server. So my name server my DNS name server is 56.2 same and exit. Now if I Supply the same command NS lookup command now you can see that it's pointing to my IP address and it says the port number where it's hosted is 53 and it's resolving my domain name and this is the address from your let's check even the reverse lookup. Okay, and when you do that the reversal cup also works exactly the way we want it correct. So it's pointing to my domain name and uh yeah that's how this works guys. So that's how you set up a DNS server and this is a simple 10-step process.
[Music] Now let's move on to our command line Essentials for that I'm going to take you to the terminal now. Because this is a scripting video we're going to spend a lot of time on the command line interface. Now this is important because it saves you a ton of time. You can't just keep switching from CLI to GUI in any real life given scenario. So I am using Centos 7 the Fedora version and I'm running it on a virtual machine. So first of all what I'm going to do is I'm going to increase the size of the text a little bit. I think this should be fine and then let's start with making a list of all the commands that we shall be acquainting ourselves with. For that I'm going to open the Nano editor and I'm going to name this CLI Essentials. All right. Now Nano editor is basically a text editor like any other. I could have used whim instead of it but I like the Nano editor because it gives you a bunch of options in the bottom and it's just easier to use. So let's start with our list. So we have our Basics which are CD which means change directory. PWD which will show you the directory. Then we have LS or list. Then we have the next segment which is the copy the move and the remove. They pretty much do what the name suggests they copy move and remove respectively. Then you have echo which is like linux's version of print. You have cat or concatenate. Then you have less which by definition both of them should sound pretty similar but in a bit I'll tell you why they are different. Then we have grep. We have mkdir which basically helps you make a directory and then we have touch which basically helps you make files pretty quickly. Then we have change mode which is also pretty significant. I'll tell you in a bit why and then finally we have man plus help which is basically like a manual. Then if I had to save this I just have to write out so Ctrl O then it'll ask you whether this is the name you want to save this with and hit enter and then it tells us that we've written 14 lines. Now all I want to do is exit this so Ctrl X and here we are back on our basic terminal. So let's start change directory. Right now as you can see we are at edureka our current working directory. So CD /home it's as simple as that. Now we are at home then we can do a CD and back to edureka. There you go. Then we have PWD which will show you your current working directory. As you can see it shows home/edureka it's the path of our current working directory. Then we have LS it shows all these files that are there in our current working directory. Not just that you can also write LS and specify a path name so then it will give you the list of objects that is there in that particular file. So at home you have these two files called edureka and background. Now what else can we do with ls? We can go ahead and look at the flags that are available for that. All you have to do is --help. Now that works universally through all distributions of Linux. Now this may look like a lot of text now but if you go up you will realize that there are flags and their descriptions given on the left and right respectively. You have your -a which means do not ignore entries starting with your dot. Then you have capital A which means almost all and then it has its description right here. What I'm more interested in comes all the way down here which is your L flag or the long listing format. Let's use that and see. Now I had done LS before. Now if I go on and do LS -L it's basically going to show me all my objects the same as LS but it is going to give me more information about these objects like the date and time at which this object was created who is the user the user group and on the extreme left if you see it basically shows you the permissions which I'm going to talk a little more about later in this segment. Right now all I want to tell you is r here stands for read W for write and X for execute. So when you see rwx written on the left it means your user can read write and execute that particular file. Okay, with that let's clear this. All right, let's move on to our next set of command line essential commands. So what else did we have? We had copy. So for copying all you have to do is type CP type the name of your file and then put in a destination path. In this case I've put in pictures which is there in the edureka directory and with that it is copied. Now let's see if it is actually present in pictures. So again let me just use the list command and you can see CLI Essentials is right here. Now let's see how to use the move command. For this I am going to be moving to this pictures directory. Oh first up let's just see what other file can we make the move to. All right, we have downloads. We have project public. All right, so first let's move into pictures. So now I'm at pictures what I'm going to do is I'm going to move CLI Essentials to let's say I'm going to move it to public. Okay, now once the move is done if we see public let's list our public. You see there is just one file which is CLI Essentials but then if I go back and check pictures there is no CLI Essentials file which basically means what moving did was it removed the file from the pictures directory and put it in public. Now let's remove that file from public with which we can also cover the RM command. So let's move into public. Now as you can see we are at public. Let me clear this. I'll keep clearing the screen for which you can just type clear or use Ctrl L and let me remove CLI Essentials. Now if I do an LS you see there is nothing there in the public directory. So with that let me move back to edureka the original working directory I was in. Let's see what are the commands that we were using. Okay, we've done CD PWD lscp MV and RM. Next we have Echo. Now as I had mentioned Echo is like the print command in here. So if I'm going to say Echo hello world like we haven't used this phrase a million times already but I'm going to stick to the cliche and I'm going to still type that it prints out hello world surprise surprise and as you might have seen what I previously did which was using the cat command I'm going to do it again. Basically what the cat command does is it concatenates your text file to this terminal of yours. So what is there in that particular text file CLI Essentials I can see it printed right here. Now how is that different from the less command? Now if I did the same thing with less it will also show you the contents of your text file but it will open it on a brand new separate window and just override the previous window you were working on. Now this is a much neater way and it helps you from not cluttering the window that you're currently working on. So that was all about cat and less. For grep let's move back into our original window. For that all you can do is press q and then you're back here. So the next command we're going to do is grab. Basically what it's going to do is it's going to grab the data from a certain file or a command that you are trying to pursue. So you guys might remember I just used the MV or the move command. So what I'm going to do is MV and go to help because if you remember your --help would basically bring out this entire Manual of the flags that are there for MV then we're going to pipe and we're going to do this thing called grab and we're going to type out verbose. So basically what I'm trying to find out is is the verbose flag available for your move command or not. So as you can see your -V or the verbose flag basically what it does is it explains what is being done while you move it. So if you use the -V flag with your move command it's going to show you basically where you're moving your file and if suppose you're using a big file suppose a 12 or 20 GB file it's going to show you when it starts and when it is finished with that. Let's move on and let's see what else. So we finished cat less grep. Next we have touch and mkdir. Now touch will be easy to show it is basically going to help you create a few files quickly in the current working directory that you're working on. So file1.txt then we have file2.txt and let's take file3.txt. Not very original but just have to show you how it works and if I do an LS you can see you have file1.txt file2.txt and file3.txt right here. Next we have mkdir which basically helps you make a directory in your current working directory. If I just type files and then I'll do this LS again you see we have created a directory which will show you in blue and we have created files. Then we have chmod or change mode. Now this basically helps you play with or alter the permissions that are associated with a file. Now let me give you an example by running a script. So what I'm going to do is I'll open script. So basically what I'm going to do is that I'm going to write a little script. Now this is a no meals me rushing into the next segment that one is separate this is just for me so I can demonstrate how you use chmod. So I'm going to go with shebang line and I'm going to just go with hello world or hello learner because we have used hello world a lot. So I'm going to write out of this controller and then we're going to move out of here. Now let me clear this out and let's try to run that particular script. So this is how you run it you go ./ and then test.sh and as you see it basically shows you permission denied. Now one thing you should remember is any script that you've just written isn't executable from the get go. Mostly you only have permissions to read it. Now to change that condition we have something called chmod. So when you go ahead and type chmod and then your +r or +W or +X it means you're basically adding to whatever permission that there is a permission to execute that particular file. So with that +X now let's try running this and as you can see Hello learner. So what I could have done instead of the +X is I could have done this 777 and then test which would have meant the same thing but there is a difference from just adding a permission to the user and using the chmod this way. For that let me open another Nano editor called permissions so I can explain it to you further. Now remember how I had said when we were using long lists or the extension -L to LS that on the left most column what you could see were the permissions associated with a certain file. Now chmod basically helps you alter that. Now if you might have noticed the permissions were displayed in the following fashion suppose ABC and then ABC and then one more ABC and then
The file name and then the date and then whatever. Basically, there are three aspects to it: the first one being the user, or you; second one being the user group; and finally, there's a thing for everybody else. So when you basically type chmod and followed by three numbers, you're basically specifying the user, the group, and others, and then the file name, which is the basic syntax of chmod. Now, how does this work? Now, these numbers can be anything from 0 to 7, and all those numbers mean something. Now let's start with zero. We have 0, which is equal to zero, which basically means nobody gets any permission. Then we have one, which basically means only execute. Then we have two, which means you can only write. Then you have three, which is basically the sum of two plus one, which means you can write and execute. Then we have 4, which is read. Then we have 5, which is essentially four plus one, which, as you all might have guessed, means read and execute. Then we have six, which is read and write, and finally, you have seven, which is four plus two plus one, which means all three permissions: read, write, and execute.
Not going to be saving this. So when you type something such as chmod 777 and a certain file name, your first seven basically means your user has the permission to read, write, and execute. Your second seven means your user group also has the permission to read, write, and execute the file, and so does everybody else, which you can see through the third seven. With that, I am closing this, so Ctrl X, and then I'm not saving it. And then finally, I have man plus help, which is basically your general commands manual. You can see the names of all your general commands; you can see your bash bulletin commands. It's basically like your guidebook before scripting. You can press h and it'll open to a summary of commands, and then you can press Q when you are done—again, Q.
Now let me head back to my presentation for a little more on CLI. Now, basically, before closing the segment, I'm going to talk a little bit about CLI and how it compares to GUI. So firstly, the first point must be pretty clear: CLI actually stands for command line interface. So it basically means it's a text-based interface. Now, the GUI, or the graphical user interface, is a visual-based interface. Pretty clearly, it features the use of graphic images, including Windows, icons, and menus. Even if it does that, it does require a mouse, which is the most common way to navigate through a GUI, which brings me to my next point: icons are easy to use because of the visual representation. Most people can learn and use GUI much faster and much easier. But once you get used to the command line, I don't personally think it is that off as well. But for a beginner, yes, GUI can prove to be pretty optimum. But there is also a downside: a GUI's OS is slower because everything you remove does not get permanently removed from the system; it is going to stay there as a copy of the file and going to clutter your space and reduce the speed of your whole system, which is where CLI wins, as it has a faster OS, which also brings me to my final point: command line interface gives you way more control than your GUI. With the CLI, users have all the control over a file system and their operating systems, and the tasks become really simple. You can create a script that contains a few lines of command, and it will do the work for you. Although your graphical user interface can create shortcuts, they do not readily support scripting or automation. So for common tasks, a user must repeat each action within the GUI manually. Now, nothing is better than the other; it's a personal choice for everybody. But for scripting, obviously a command line interface is more—most optimum. It helps you do things at scale; it helps you when you need to script or automate something; you need greater control over systems or functions; and it helps you with less memory usage. With that, let's move on to the shell script basics.
The most logical question obviously is: what is a shell? As I had mentioned earlier, users communicate with the kernel through a program known as a shell. A shell is basically a command-line interpreter, and basically what it does is that it processes your requests. When you type in a command at your terminal, the shell interprets the command and calls the program that you want. The shell uses standard syntax for all commands. So basically what it does is that it translates commands entered by the user and converts them into a language that is understood by the kernel. From the shell, the direct derivative is the shell script. Now, the basic concept of the shell script is that there will be a list of commands which are listed in the order of execution. A good shell script will have comments preceded by the hash sign. Now, it is not important for you to have hash-signed certain comments for your script to be executed; it is all only a good practice to have your steps hashed out so somebody else reading your script can understand what you want to do with it. Now, there are several different types of shells, which can be broadly classified into two types. First, you have the Classic Shell, which is the Bourne shell; a derivative which came later was the C shell. Now, each of these types have their own subtypes. A few examples of the Bourne shell are the basic Bourne shell, the Korn shell, the Bourne-again shell, or Bash, and the POSIX shell. In C shell, certain examples are your basic C shell, your TCSH shell, and the Z shell, which has been picking up popularity in the past few years.
Now, to understand how this works, let me move on to our terminal. Now what I'll be doing is I'll be dividing the screen into two parts: on my left I'll have my Nano editor, and on my right I shall be having your basic terminal where you can see your commands being executed. So to kindly be patient. Okay, so let's start with some basic shell scripting. Now, shell scripts have several required constructs that tell the shell environment what to do and when to do it. Of course, most shell scripts are more complex than the one I'm going to show you. The shell is, after all, a real programming language, complete with variables, control structures, so on and so forth. No matter how complicated a script gets, it still is just a list of commands executed sequentially. So here I'm going to open up my Nano editor, and I'm going to put up, let's say, example1.sh. Now notice the extension sh; this is my extension because I'm using the basic Bourne shell, or the sh shell. So I'll start with the shebang line, and it is nothing but the absolute path to the interpreter of your shell. So it has this hash and this bang, or the exclamatory, followed by the full path to your interpreter. Now, all scripts under Linux execute using the interpreter specified on this first line. So this could be sh, or Bourne shell, bash, or your ksh, your zsh, so on and so forth. Now, like we had given the advice of hashing out comments, let me just put on a few comments, make this look good. Okay, and then I'm going to put up, try and print this very simple print, such as "What is your name?" And then I am going to read whatever you enter, and then I am going to print that out. You're going to allocate whatever we read into this variable called person, and then we are going to call that variable using the dollar sign. So "Hello, whatever person". As I mentioned before, your control or write out, and then we're going to exit this. Now, this is to remind you one more time that every file which has just been made is not executable. So if I try to execute it now, it would tell me that permission is denied. This is just a recap of what I had done say two minutes ago. So we are going to change the mode, and I'm going to do this when I'm executing any script at all. Try and execute it now; it's going to ask me "What is your name?" I enter "At Eureka employee", and then it's going to greet me saying "Hello, At Eureka employee," and that is the most basic of the shell scripting that you can do. As we move further, I'm going to keep bringing you back here. I'm a firm believer in practicing what we're learning in theory. With that, let's go on and see what we have next in this module.
So the next segment is about using variables. So what is a variable? Most people might be aware of this term, but for those who are not, I'm going to explain it down to the scratch for all of you. Now, a variable is nothing more than a pointer to the actual data; it's nothing more, nothing less. The shell enables you to create, assign, and delete variables. So basically what it is is that a variable is a character string to which we assign a value. The value assigned could be a number, text, file name, device, or any other type of data. The shell enables you to create, assign, and delete variables which may contain numbers, texts, file names, devices, or any other kind of data. Now, variables are of three kinds in the shell: you have your local variables, which, as the name suggests, is the variable that is present within the current instance of the shell; it is not available to programs that are started by the shell, and they are set at the command prompt. Then you have your environmental variable; an environmental variable is available to any child process of the shell. Now, some programs need the environmental variables in order to function correctly. Usually a shell script defines only those environmental variables that are needed by the programs that it runs. And finally, we have the shell variables, which can be compared to the global variable if you're into any other kind of programming. A shell variable is a special variable that is set by the shell and is required by the shell in order to function correctly. Now, some of these variables are environment variables, while others are local variables; it can be any of these.
To see how we can implement these variables, we are going to move on to the shell. But before that, let's see specifically what we are going to look at. So first of all, we are going to learn how to define variables, how to access the values; then we're going to see a little bit on read-only variables and unsetting variables. Then we have special variables; we're going to see how you can work with them. We have command line arguments; we have special parameters; and the exit status. Now, to see how all of these things work, let's move on to our terminal. So again, I am going to create another Nano file called variable.sh. Now, defining variables. Now, any variable that you are going to define should be along the lines of this: you have your variable name, and then you have your equal sign and your variable value. Now, if you have done any sort of coding or programming before, you would know this is basically how you allot a value to a variable throughout all different platforms. Now, the thing you have to notice is that in shell scripting it's very particular about the syntax: so no spaces on either side of your equal-to sign; in that case it is not going to execute and it's going to throw an error at you. So let's take something simple: it's your name equals this. Now, this example defines the variable name and assigns the value "At Eureka employed" to it. Variables of this type are called scalar variables. Now, a scalar variable basically means that it can only hold one value at a time. So let's turn this into a shell script first. So I'm going to go up and put in my shebang line, and then I have my name, and then we're just going to call that particular variable; pretty simple, and we've done it before. So then Ctrl o. Here again we have to give it permissions, and then when we executed it, prints out what we had asked for it to print out. Okay, let's see what happens when I use the read-only command and then I try to change the value of the variable. Suppose I put in my own name into it. I'm going to go Ctrl o and okay. Basically, it's going to throw an error at me saying that the variable name is a read-only variable, so I cannot change the value of the variable once I put read-only in front of it. Now that was all about read-only variables. Now let's move on to see what else can we do with this. Now there is also something called unsetting variables. Now, unsetting or deleting a variable directs the shell to remove the variable from the list of variables that it tracks. You'll see in a moment what I mean. So I did this, and then instead of read-only I'm going to put unset, and then I'm gonna call my variable; same old, same old. And now we are going to try and call this. As you can see, nothing. So basically what it did was it took the variable out of the list of other variables; that is what unset does. Now let's clean this out, and we can look at special variables.
Okay, so now let's discuss a little bit about special variables. So in the previous segment you understood how to define a variable, how to read-only and unset a variable. Now these variables are reserved for specific functions, and hence they are called special variables. Now they're usually preceded by a dollar sign, and these are the special variables that we are going to see: you have your $0, which is the file name of the script; then you have your $, any number 1 to 9. Now these variables correspond to the arguments with which a script was invoked. Here you can pick any n number, which will be a positive decimal number corresponding to the position of the argument; you shall understand when I demonstrate this further in the segment. Then you have your $#; now this will basically return the number of arguments applied to a script. Then you have your $* and $@. So this will return you all the arguments that are double quoted, which again you shall see when I demonstrate this. This will give you all the arguments that are individually double quoted; that is the only difference between the $* and the $@. Then you have this, which is the exit status of the last command that you have executed. And finally, you have the $$ which will give you the process number of the current shell for the shell script. Now this is also the process ID under which it is being executed. Now let me try to script something with which I can depict not all, but at least most of these special variables. So let's just on echo big $0; let me go ahead select it and then copy it a bunch of times. Okay, so let's go ahead and execute this. So now that we have learned about all of these special variables, let's implement them using command line arguments. Now, command line arguments, as you can see on your left, are these $1, $2, $3 to $9. They're actually positional parameters, with $0 pointing to the actual command, following which your $1 and your $2 are the arguments to that particular command. If you see the script on your left, this is how it will run. So first we are going to change the mode, then we are going to run it and pass a parameter here. So if I pass "At Eureka employee" or after that too many times, so "At Eureka learner" and enter, it shows you the file name, $0, your parameter number one, which is "At Eureka", your second parameter, the quoted values, and the number of parameters, all of which are returned to us by our special variables. Now, as you might have noticed, your $@ and your $* returned pretty much the same thing. These are the special parameters that allow accessing all the command line arguments at once, which in our case is "At Eureka learner"—both of these arguments. So both of them actually act pretty much the same unless they are enclosed in double quotes. Now let me show you how. If I run the same thing but I put them in double quotes, you can see both of them again give the same value. But if I put them in individual quotes, it will treat them as two separate parameters and will give you two separate values, whereas in the first one it will quote your number of parameters as one; it will consider it one single string. Now let me try and demonstrate it using another shell script. How is it different? This does not make a lot of sense to most of you right now, so let's just hope the next thing makes it better. So I'll run a little for loop here, which again we are going to touch up on later, but for now let me just do this to demonstrate how this works. Now let me put this in perspective. So what I'm going to do is I'm going to run this entire sentence: "At Eureka wishes you happy learning," and you see what just happened, right? What your special parameter did here is that it took this entire list and separated it into separate arguments, and that is what these two special parameters do. Now, once you're done with it, you can always use the exit status. So what I'm gonna do now finally is I am going to go and implement the exit status, and it is going to return a value of zero. Now this is basically the exit status of the previous command; it would have given you a one if your previous command was unsuccessful. Since your command was successful, it gave you a zero. So the exit status is basically a numerical value returned by every command upon its completion. As a rule, most commands return an exit status of 0 if successful and 1 if unsuccessful. Now, some commands also return additional exit statuses for particular reasons. For example, a few commands will differentiate between kinds of errors and will return various exit statuses depending on the specific type of failure. With that, we've come to the end of this segment. Let me go back to my presentation.
Next, let's take a look at our basic operators. Now there are various operators supported by each shell. I'm not going to take a lot of time with this segment. We will discuss about the default shell in this segment, and we are going to discuss the following operators: we have the arithmetic operators, relational operators, Boolean, string, and file test operators. So this is the first table, and these are your arithmetic operators: you have addition, subtraction, multiplication, division, modulus, assignment, equality, and not equality. It's very important to understand that all these conditional expressions should be inside of squared braces with spaces around them. Now, all the arithmetic calculations are done using long integers. Next, we have relational operators. Now, the Bourne shell supports these relational operators that are specific to the numeric values. Now, these operators do not work for string values unless their value is numeric. We have again the equal operand, not equal to, greater than, less than, greater than equal to, or less than equal to. Then we have the Boolean operators, which are just three: there's the logical negation, logical or, and logical and. And finally, we have the string operators, which are equals, not equals, check if operand is 0, not 0, and check if string is empty. And finally, we have the file test operators. Now we have a few operators that can be used to test various properties associated to a Unix file. Now assume a variable file holds an existing name of the size 100 bytes and has to read, write, and execute permission on. So you have your -b, which checks if the file is a block special file; then you have -c, which checks if a file is a character special file; if the file is a directory, which is -d; -f is if a file is an ordinary file as opposed to a directory or a special file; then you have -g, which checks if the file file has its set group ID; -k, which has its sticky bit set; -p, which is a named pipe; -t, which checks if it's associated with the terminal; -u, it has a set user ID; r is readable; w is writable; and x is executable, which we had discussed before; then you have -s, with a size greater than 0; and -e, if the file exists. Now these are specific to the Bourne shell; there are other operators that are available in the C shell types, but you shall find a lot of content surrounding that; it's not really crucial to discuss that in this module. So let's move on.
Next we have shell loops. In this segment we are going to discuss shell loops in Linux. A loop is basically a very powerful programming tool that enables you to execute a set of commands repeatedly. Here we shall discuss the...
While loop, the for loop, until loop, the next loops, and loop control which will include the infinite loop and how to get out of it with break and continue commands. So that again, as most of you might have correctly guessed, let me head back to the terminal. So first, let's discuss the for loop.
So the for loop operates on lists of items; it repeats a set of commands for every item in the list. So let me open the Nano editor. Let's see, let's call it edit, all right. So basically, this is how the syntax of your four loop goes: for your certain variable in say your word one, word two, so on and so forth till your word n, then you have a do statement, whatever you want your for loop to do, and then done. And this is basically how your for loop works. So here I'll give you a simple example of how the for loop works. It's basically going to span through a given set of numbers, set 0 to 9, and upon execution it should print all those numbers. It's basically printing out this variable for all the variables that are there in this set. It's pretty simple. So again, CH mode and then, and there we go.
Now what if you had to do the same thing using another way? We have for you the while loop. Let's get out of here. Let's open this and see how the while loop is different from the for loop. Now the while loop, what it does is that it enables you to execute a set of commands repeatedly until some condition occurs. So it is usually used when you need to manipulate the value of a variable repeatedly. The syntax of a while command looks something like this: so you have a while, and then you have a command, a condition if you will, then you do, and then there's this statement, what you want to be done, and then done. I'm going to demonstrate the same example using the while loop. Now this is basically going to do what we did with the for loop, but using the while loop. We start with assigning a value to a, which is our variable. Now we say while a is less than 10, it's going to print a and then increase the value of a to a plus 1. That's all that is there inside the loop. Now let's try executing this. Again, I'm going to change the permissions, and it prints the same exact thing. Here the shadow command is evaluated; if the resulting value is true, so as long as a is less than 10, it will keep printing a and adding 1 to it. Once it reaches 10, your while loop breaks and you come out of the loop. Each time the loop executes, the variable a is checked.
Let's try doing this one more time using the until loop. Let me clear this out. Now the while loop is perfect for a situation where you need to execute a set of commands while some condition is true. Sometimes you need to execute a set of commands until a condition is true, and that is where you use the until command. I'm gonna go back here, and you'll notice that the structure of until command is pretty similar to that of your while. Again, you have your until statement, then the command or the condition, then you have your loop beginning, whatever you want to happen in the loop, and then done. Here, once the shell command is evaluated, if the resulting value is false, the given statement is then executed. If the command is true, then no statement will be executed, and the program jumps to the next line after the done statement. So again, because I'm lazy, I am going to do the exact same thing as I did twice before, but this time using the until command. Same thing here, instead of while it's until, so until your a is not less than zero, it's going to keep printing a and then incrementing the value of a. So even if what gets printed is the same, you know for a fact that how the procedure was gone about was different. When you use the Y command, your statement is executed while your condition is true, but when you use the until command, your statement keeps executing until your condition is true. With that, let me clean this out, and then we shall move to nested loops. Let me get out of here. Okay.
Now next, let's talk a little bit about the nesting of loops. Now all the loops support nesting concept in Linux, which means you can basically put one loop inside another, similar or different loop. This nesting can go on up to an unlimited number of times based on what you require. Now let me give you an example of nesting using the while loop. So remember the simple while loop that you ran which went from 0 to 9? What we're going to do is basically we're just going to add another while inside the previous one. So Nano. Okay, remember till here it's pretty much the same as the previous one, that is your first loop. Inside we are going to assign the value of a to B, and while your B remains greater than zero, it's now going to go to a new line, which is this n flag, print B, and then increment B. Once it comes out of the loop, it's going to increment a, and so on and so forth. Let me show you what this looks like. Now the result here is not very important, but what you need to understand is how the basic structure of the loop is and how it works. So again, like you can see, a starts with zero. Now while a is less than 10, 0 being less than 10, a is assigned to B. Now while B is greater than equal to 0, which now B is, it is 0, it's going to go to a new line and print B; it printed 0, then it's going to increment the value of B and turn it to 1, and now once B is incremented it gets out of that loop, followed by the increment of a, which now a becomes a plus 1, that is 1, and it keeps going on and on and on and on till finally your a is no longer less than 10. So with that, let's move on to our next topic, which is of loop control.
Here we are going to discuss some very important concepts, but before I introduce the concept of loop control, first we need to understand what an infinite loop is. So let me create an infinite loop. So let's start with a equals, suppose 10, and let's go saying as long as a is greater than 0, start your loop, and you're going to print a, and then we are going to increment the value of a, and then done. Ctrl o. And now what this is going to do is it's just going to go on and on and on and on and on because it will go on until a is greater than 0, and it's always going to be greater than zero. So let me just put a stop to it this by using Ctrl C. I can put a force stop to it. Now you can also do that using something known as the break statement. Now the break statement is used to terminate the execution of an entire loop after completing the execution of all the lines of code up to the break statement. Now let's see how that works. So I am going to exit this, and now this is a simple example which shows that the loop will terminate as soon as a becomes equal to 5. So let's go ahead and you go and one, two, three, four, five. Now another statement associated to it is the continue statement, which is similar to the break statement except that it causes the current iteration of the loop to exit rather than the entire loop. So this statement is useful when an error has occurred, but you want to try to execute the next iteration of the loop. Let's look at one of those. So basically what you see in the script is that this loop makes use of the continuous statement to return from this particular statement to the next one, which is the found odd number statement. So if we try to run it, you will receive this result: found an odd number, even, odd, even, odd, even, odd. It's basically very similar to the break command except for the fact that your break command will exit the entire loop while the continue statement will only exit the current iteration. On your left you see this little script where we're trying to see these numbers that we have put in, one to seven, which of them are even and which of them are odd. Now what you'll see here is that the script uses the continue command to exit from this particular statement to this particular statement. So if I tried to run this, it keeps exiting this to produce this even number statement. With that, we come to the end of shell loops. Let's go back to the presentation to see what we have next.
So in this segment we will discuss in detail about functions in the Shell. Now basically what functions enable you to do is to break down the overall functionality of a script into smaller, more logical subsections which can be then called upon to perform their individual tasks whenever needed. So in this segment we are going to talk about creating functions, passing parameters, returning values, nested functions, and calling from prompt. So here we are at our terminal. Let's again open our Nano editor. So to declare a function is a very simple; what you will have to do is type your function name and then go ahead with your list of commands and then close the bracket. This is all that you have to do. Now let's start with this very basic function. Dot with the shebang, again not to be confused with the shebang in the pop culture that we use. So what we're going to do first is that we're going to define function. So again, this is my function name; it's going to be hello, and then I am going to just print hello learner, nothing very complicated, and then all I have to do is just invoke my function or call my function, whatever it is. So hello, then I'm going to save it, and here it basically calls that function, and that's how simple that is.
Now using functions to perform repetitive tasks is an excellent way to create code reuse. This is an important part of modern object-oriented programming principles. Now shell functions are similar to subroutines, procedures, and functions that are present in your other software and hardware coding languages. The idea here is to break down a big program into smaller, more logical subsections which can then be called whenever they need it. Now you can define a function that will accept parameters while calling the function. Now these parameters can be represented by dollar one and dollar two, as we had past parameters early on if you remember. Now here if I make some minor changes to my function, I think I can make it accept parameters. So hello, and I can put two different parameters, and then what I can do is I, I can put those parameters right here. Let's say I'll put two names; let's say I'll put Priyanka Chopra, because you're not pretty international, let's just keep it that way. And that is what it called. Basically, these two parameters were captured and printed in this function. What you can also do is return values from functions. If you execute the exit command from inside a function, its effect is not only to terminate execution of the function but also the shell program that called the function. If you instead want to just terminate the execution of the function, there is a way to come out of the defined function. Now based on the situation, you can return any value of the function using the return command. So again what we can do is make some changes here. Let me return this. Another thing I'm gonna do is capture this 10 value that has been returned from my previous command, all right. So what I'm going to do is I'm going to print this out by Echo, and then return value is, so I'm going to with this hill. So here, as you can see, the parameters that we had passed and the value that has been returned.
Now one of the more interesting features of functions is that they can call themselves and also other functions. A function that calls itself is known as the recursive function, as most of you might know. Now I'll also give you an example demonstrating the nesting of two functions. So let me just clear this out. I could open a new Nano editor, but let's just say I am very lazy. So okay. Now let's execute this. Basically, we have a function number two inside the function number one. Function is saying Alpha online over and then calling number two, and number two here is printing beta online, and then we are calling the function number one, which is our superset if you may in the function. So if we execute this, we get the first one, alpha online over and beta online. I clearly watch a lot of movies as well. And now you can put on definitions for more commonly used functions inside your profile, and these functions will be available whenever you log in, and you can use them at the command prompt. Alternatively, you can also group the definitions in a file and then execute the file in the current shell. With that, I come to the end of the segment as well. Now we are going to move on to some used cases, on a small scale of course, to see how shell scripting is used on a broader scale on a day-to-day basis. So I am going to clear this, and I am going to clear this as well.
So let's run a few simple scripts to scan and monitor network using the combination of your shell script and your ping command. Obviously, these scripts are no match to a full monitoring dedicated software like Nagios, but they could be useful for a small home brand networks where implementing sophisticated monitoring systems can become an overhead. Let's look at something simple first. Okay, let's look at a scan. So your dot slash. Okay, so let me just show you the code for this. So right now we are going to run a few simple scripts to scan and monitor the network using a combination of bash and ping. Now this is a disclaimer here: these scripts are no match for a full monitoring dedicated software, something like your Nagios, but they could be very useful for small home brand networks where implementing sophisticated monitoring systems can become an overhead. So let's start with something simple like scanning a network. So this is the code in the script. What we are going to do is we are going to scan the network for hosts that are attached to and IP address, and the script will print the message nodes with IP. So if your IP address is up, then your ping command was successful. Feel free to modify the script to scan your host's range whenever you try it. So as you can see, it starts with your basic shebang line, then we are using our ping, and we are basically checking for the exit status for being 0. Now if your exit status is equal to 0, then it will print that your IP address is up. Pretty simple. If we go deeper into it, now we're going to run this loop for IP addresses from 1 to 255 in the subnet 192.168.2. Basically, what's going to do is it's going to ping these many systems and check if they are up and then disown them. All right, let's try running the script. Now as you can see, these many systems are up in this particular subnet. We have a bunch of different ones; one of them should be mine, this one seems like it's mine, and so on and so forth. All right, let's move on to our next script. Basically, what I did just now is I force stopped this script. All right. Okay.
Now what we're gonna do is we will try to send the email to my email address when the ping cannot reach its destination, which probably means the host is down. System admins can execute this in a script regularly with the use of a cron scheduler. Now this script uses ping command to ping the host or IP that is supplied to an argument, and in case that destination is unreachable, a mail command will be used to notify the system administration about this event. So let's look at this. So cat. All right. Now this is what the script looks like, also a pretty small code. Again, it starts with the shebang line and it runs a for loop. Now here you can see there is a special variable used which is your dollar act, which basically means that all the arguments are individually double quoted. So inside this for loop, basically we are trying to ping all the parameters that are passed, and if the set parameter is not equal to 0, then we are going to get email to this particular email address that the host is down. All right. Previously we had checked for an entire subnet; that is why we didn't have to pass on any arguments, but here since we are not running it for an entire subnet, we are going to try it on on some trusty websites. So before I call in this code, I would like to show you that this is what my Gmail tab looks like; there's nothing in my inbox currently. So what I'm expecting is that when I pass on an argument which is not supposed to be up, I'm supposed to be getting a mail in my Gmail, right? So let's run this. Let's put in google.com, because we know it's always running. Now let's put yahoo.com. Let's put in an imaginary IP which I'm sure, let's hope this does not exist. Let's put on one more for safety. Okay. Now we've put in four; we know for a fact that google.com is always up, so has yahoo.com. Now we'll have to check which of these two IP addresses it's not up. Now let me open my Gmail and check, and as you can see, I have two new messages, and if you open the mail, you can see the message that we had put in as input. All right.
Now that we've done these two things, let us try an extended version of the same thing. Now I force stopped this particular script from running because it will go on and on and on and on. Now what we're going to do is that we're going to create a monitoring log. The last example I'm going to show you here is a modified version of the previous two examples. Now this example that I'm going to show you is a modified version of what I just showed you. When the mail is not configured on the system, the script will create a log file. Now the core of the script is wrapped into this endless while loop which is set to execute ping and check every minute. Feel free to modify the script according to your own needs, and you can also go ahead and remove the endless while loop when you intend to use the script with the cron scheduler. All right, so let's see what our script looks like. So this is our script; let me break it down for you a little bit. So first of all, I've created this log file which is going to save if your host is up or down in a temporary log file; it basically is a directory. Then I have created another variable called seconds. So this script is going to run every 60 seconds to check which host is up. The email is my email, which I had shown you previously. Then the for loop begins. Now this is very similar to the previous code that we had just run; this is the same part, and here we have an infinite loop, which is basically what we're going to run to check if a host is up. So we are going to ping the various arguments that we're going to pass, and if the said argument is not equal to 0, then the status gets logged into our monitor log, and if the status is down, then again like our previous code, we get a mail that our host is down; else if the host is up, you just ping okay the host is up, and there is no mail. Now the reason why I'm not sending a mail when the host is up, if suppose somebody uses this code to check a subnet of a lot of systems, you do not want to spam yourself with a bunch of different mails saying the host is up; that is not important; we want to know when a host is down. And then this if condition closes with an F5, and your argument being up is also sent to the log, and then we have sleep for the seconds variable which we have put up as 60 seconds. So as I had mentioned, the script is going to run every 60 seconds. So let's run this. I'm going to check for google.com and this imaginary IP address which, as we had previously seen, is not up, and then let's put in yahoo.com and yahoo123.com, which I'm hoping is not an actual website. Let's put in this 2.2.2. Now let's run the script. This might take some time, so kindly be patient. Let the
script run so while it runs let me explain this to you. As you can see, the core of the script is wrapped into an endless loop which is set to execute a ping check every 60 seconds. Whenever you try the script, feel free to modify it according to your needs. And if you intend to use the script with a cron scheduler, feel free to remove this endless loop, because that's what a cron scheduler will do on its own. Okay, so I think that's enough time; let me just stop this.
And as you can see, I've already gotten the new messages here again. As you can see, this does not exist; this does not exist. The hosts are down, so our ping has failed, and so we've gotten these mails. Now, what else can we do with it? Let's try to understand a script to create a network backup, sort of a file. So let's see what that code looks like.
So for this code, I'll have to go back to root. Let's check if our file is here, and it is. So let me show you the code for creating a backup of a file in your network to your local system. All right, now this is what your code should look like. So first of all, you're going to mount the shared directory, which basically means you're not creating a copy of the directory, but if you make any changes in your local file, it will be reflected in your shared file and vice versa. So CIFS is basically used for sharing your Windows file. This is the path of your shared file, and this is the path to the local directory where you're going to create your backup. We've had a username at edureka, and we've set the password at edureka; that is what hyphen-o does. So again, we've mentioned what are we going to backup; this is the file that we're going to backup, and this is our destination.
Now, basically, we're going to create a backup and save it in the name of the day. So, for example, today is Thursday; so if I create this backup today, then it's going to be saved in a folder called Thursday. Our host name is localhost, and so our archive file is going to be localhost-the name of the day, which is Thursday.tgz. .tgz is basically your tarball file extension. And then we've put in a print of the start status message, which is basically supposed to inform us that we have started creating the backup. What ccf does here is it basically creates a zip file, because we're obviously going to import files into the local system, and in the end it is going to show us a message called "backup finished." And finally, we are going to unmount our shared directory.
So first, let me show you the file that I am trying to backup over here. So now that we know what the code looks like, let's give it a run. So ./ So as of now, it's creating a backup, and remember I had told you this is how it's going to name it: localhost_Thursday.tgz, localhost being our hostname and Thursday being today's date. And it's also showing us that these are the folders that are present in our backup directory. So how are we going to see it? Let's first head on home, change directory to edureka. So let me clear the screen and let me head on home. So here I am, home at edureka, and this is the list of everything that is there. So as you can see, there is a file created here called backup, and now we're going to extract the files and see if the code that we've run has actually worked or not. So let me go to that file, and so now I'm going to unzip the file and see if actually… Now let's go in here and check if we actually have our files in or not. Let's go and unzip this file, and here are all the files that are present in that particular folder. We have a bunch of PNG images, as you can see. Now if the same thing I had to show you in GUI, so I'll go to home, and this is my backup file, this is, and these are the PNG images that have been imported into this folder. [Music]
Let's straight up move ahead to the questions. So first of all, the most basic: what is a shell? Now, the shell is a command-line interpreter. Basically, what it does is it translates the commands entered by the user and then converts them into a language that is understood by the kernel. The typical operations that it performs include file manipulation, program execution, and printing texts. So basically, the shell is the utility that processes your requests when you type in a command at your terminal. The shell interprets that command and calls the program that you want. The shell uses standard syntax for all the commands.
So obviously, the next logical question is: what is a shell script, and can you name some of its advantages? So a shell script is basically a computer program designed to be run by a Linux or a Unix shell, which is in the form of a command-containing text file which has one or more commands that are written in an order of execution. It has two main advantages: one is it facilitates you to develop your own OS with relevant features best suited for you, and secondly, you can design software applications according to your desired platform.
Next: what are the different types of variables that are used in the shell script? Now, there are basically two types of variables: there are system variables and user-defined variables. So the system variables are defined or created by the operating system or Linux itself, whereas the user-defined variables are created or defined by the system users. Now, the system-defined variables are generally defined in capital letters and can be viewed by the `set` command, whereas the user-defined variables can be viewed using the command `echo`.
Question number four: what are the different kinds of commonly used shells on a typical Linux system? Now, firstly, there are two main kinds of shells: you have your Bourne shell and your C shell. Some common derivatives of Bourne shell that we use—some very popular ones—are the Bourne shell or the regular shell; you have the Korn shell; you have the Bourne Again shell, or bash; and the POSIX shell. Some common C shell types are the C shell, the Tcsh, and the Z shell.
Next: how do you create a shortcut in Linux? Now, you can create a shortcut in Linux with the help of links. There are two kinds of links: you have the soft link and you have the hard link. So before you understand what a soft link is and what a hard link is, I'd also like to explain what an inode is. Now there's something called an inode for every file of the file system which has information along with all the file attributes except for its name. Now a soft link is an actual link to the original file. These links will have different inodes with different values. The soft link points to the original file, so if the original file is deleted, then the soft link fails. If you delete the soft link, nothing will happen to the file. The reason for this is that the actual file or directory's inode is different from the soft link created with the file's inodes. A hard link acts like a mirror copy of the original file. These links share the same inodes. Changes made to the original or the hard-linked file will reflect on another; that is why when you delete a hard link, nothing will happen to the other file. Hard links cannot cross file systems, whereas soft links can. Hence, deleting the original file does not affect the hard-linked one, whereas deleting the original file makes the soft link inactive.
Next, okay, now this is a question which is very common: can you tell me something about the superblock in shell scripting? Now, the superblock is basically a program that contains all the information regarding a specific file system. It contains information such as the size of the file, the block size used by its number of free data blocks, and the list of free inodes and data blocks.
Question seven: what is GUI scripting? Now, when we talk about Linux, mostly what we talk about is the CLI, or command-line interface scripting, but there's also something known as graphical user interface, which is used for controlling a computer and its applications. Now the GUI scripting supports different applications which mostly depend on the OS.
What are the various stages of a Linux process that it passes through? Now, basically, there are four stages, namely: they're waiting, running, stopped, and the zombie mode. Now, waiting is basically when the Linux process waits for a resource; then it starts running, which means the process is being executed; then after a successful execution, the Linux process is said to have stopped. Now the fourth one is an interesting one, which is called a zombie stage. Now it is known as a zombie because the process has already stopped, but in the process table it is still active.
Question 9: what is the difference between the `break` and the `continue` statements? Now, a lot of the times when you do basic scripting, you might use `break` and `continue` statements for pretty much similar things, but they are actually a little different. The `break` command is a way to escape out of the entire loop in progress, whereas the `continue` command causes you to escape only the current iteration; you do not skip the whole entire loop. So when you want to test whether each iteration of your loop is executable, you use the `continue` statement, in which case it just jumps out of every iteration that has an error and goes on executing those which don't.
Next question: what is the significance of the shebang line in shell scripting? Now you might have seen the shebang line at the top of each script. Basically, what it does is that it determines the location of the engine which is to be used to execute the script. It simply provides information regarding the location where the engine is placed. It is also neglected by some of the users if they want the same.
Now with that, let's move on to some questions which we can execute in our terminal. So how do you pass an argument to a script? For this, let me just go ahead, increase the size of this so you can see better. I think this is okay. So basically, this is how you pass an argument to a script: you use the `cat` command and the `$1` sign, which basically is used to take an argument. I'm just going to exit from here; we're going to change its permissions, and then we are going to execute it. So basically, this is how you take in an argument. The simple script is basically used to show the file name. This `$1` is a special variable which displays the file name. The file name here is question 11 or q11.sh. So what I'm gonna do is I'm gonna change permissions and then `./`. So here I have a simple script which basically what it does is it will show the file name. So here I have a concatenate `$1`. `$1` means it's going to take in your first argument, and that is basically what the question is. So I'm just going to exit this and I'm going to make sure that it is executable. So basically what I'm going to do is run that file and then pass a file name as an argument. So I have already created something known as a test file, and that is how it works.
Okay, with that, let's go on to our next question, so question 12. How to use arguments in a script? So basically, what I'm going to do is copy the file argument one to the destination which is my argument two. It's basically I'm going to take in two different arguments and copy the first one—the first one is going to be a file—to the second one, which is going to be a path. All right, pretty simple. Same thing I'm going to do again, which is make sure it's executable. So I'm going to give a file name; let's do the test file that I had created earlier, and then copy it to public. And if I put in the same path, you can see that our test file is right here. All right, pretty simple. Now let's clean this. Next, these are going to be pretty simple scripts, as this is just the first part of the interview questions; these are for beginners. So next is: how to calculate the number of passed arguments? So again, you can just go ahead and do a `$#`, but if you want to do it properly, like in a script form, we have the script for you. There's just a fancy way of doing what I just did some time ago. All right, so number of parameters passed: it's going to print, and then it's going to take in the number of parameters that you have passed, `$#`. All right, so I'm going to pass two parameters here; I'm going to write edureka learner, how's that? And as you see, I've gotten… Okay.
Next is: how to get the script name inside a script? Now, again, there's a very simple way to do it; all you have to do is `$0`, which will basically print out the script name, but since we're doing it in a script, we're just going to print it out. Same thing, `$0`, and it prints out the name of the script, which is q14. All right.
Next: how do you check if a previous command has been run successfully? Now you might have noticed that I haven't really cleared my screen out; this is so that you can see my previous command has been run successfully, right? So to check if it has been run successfully, what I can do is simply go `$?`, oh, and put in print, which is the `echo`, and if the answer is zero, basically your script has run successfully; if it is one, it has not. Now there may be other numbers shown to you depending on the kind of error that is there in your script. Now such a thing can also be done in a script form. So if you want to do it in a more organized manner, you can do this. So basically what I've done is I've created a variable and assigned the exit status, which is what this `$?` special variable is; it basically gives you the exit status of your previous script. Now if that variable is 0, which as we saw, which means your script has been run successfully, then you're supposed to print this message, and if it's not, you're supposed to be printing this message. All right, so let me exit this, and because our previous script was run successfully, it prints this message. I can see my spelling mistake here, but there's a scripting tutorial and not an English tutorial, so we can just let that slide. So let me clear that out.
Next we have question number 16: how to get the last line from a file? So basically, it's a very simple way to get the last line from a file; all you have to do is `tail -1`, and then you put in your file name, and it gives you the last line of that particular file. This is basically what's there in the file; let me concatenate and show it to you. Yeah, so this is basically a test file; it has three lines all having "test one test one test one". Now you can also go ahead and change the number, and it will print that many lines from the bottom. So there you go.
Next question: how to get the first line from a file? Now this is pretty much like the previous question; so instead of `tail` and a hyphen a certain positive integer, what you can do is you can go ahead and type `head -1`, and then put in your file name, and it'll give you the first line from that particular file called test file one. Pretty self-explanatory; it's a pretty simple question.
Next question: how to get the third element from each line from a file? So this goes along the same lines of the previous two. So basically what I'm doing here is that I'm using the `awk` to print out the third column or the third element from any given file that I am taking in as argument. Nothing too complicated. So let's just exit this. All right, so `./` Okay, so it only makes more sense if I show you the file that I am using. This is the text file; it's basically a test file three, and as you can see, my third entire row is "test test test test". This is basically what it's supposed to be printing—a row full of tests, right? So if I run this and I put in test file 3 as my argument, it prints out my third element from each given row. All right.
Next question number 19: so how to write a function in shell script? So this is a very simple example of a function; it's basically `function example`, is the name of the function, and it has a basic print statement called `echo hello learner`. There are parentheses which begin at the end of your naming the function and they close at the end of your function. It's nothing too difficult; as the function keeps on complicating, this might get complex, but the basic structure of this script will not change. Okay.
And finally, question 20: this is the last question of this particular segment. Write down the syntax for all the loops in shell scripting. Okay, let me open and edit for this. So first of all, let's start with the `for` loop. How the syntax goes is you go `for`, and then you have a variable, say i, j, k, and then you put in your condition, `for i=anything`, and then this is the beginning of your loop, says `do`, then you have your statement that you're going to execute, and then you're going to go ahead and go `done`, which is the end of your loop. So this is how your `for` loop works. All right. Now let me go ahead and quickly put in a `for` loop, a simple script that I can run and show you, and upon execution you will get this result. It was a very simple `for` loop printing out all the variables from one to nine.
Now next comes the `while` command. So again, you have your `while` statement, and then whatever condition it is that you want to imply, and then as the loop begins, you have your `do`, and then you have your statement that you want to execute, and then `done`. All right, this is how your `while` command should look like; this is the basic structure of how it should work. Again, I'll try to run the same command that I did for `for`, except for this time I'll be using the `while` command, and when we try… So this is basically the `while` command that I've written. I've taken a variable `a`, and here the `while` command states that if your value of `a` is less than 10, then you're going to print `a` and then add 1 to that particular `a`, and then this goes on and on and on till your `a` is no longer less than 10. All right, so again it prints from zero to nine, same as the `for` loop.
Then you have the `until` loop, which is kind of like the `while` loop, but it is slightly different. So I am going to clean this out. So same as `while`, you have your `until`, and then your condition, and then `do`, and your statement to be executed, and then `done`. With that, you close the loop. All right, this is basically what your `until` condition should look like. Go ahead and clean this out again. I'm going to do the same thing with the `until` command. So here, instead of `while`, I'm going to go and do `until`. So until your `a` remains less than 10, and what stayed inside the loop remains the same, you're going to print `a`. As you can see, as I done `while` before, `a` is starting from 0; that is the value that has been allotted, and then again we are adding 1 to `a`; we are incrementing `a` by one, and then we are closing the loop with a `done`. So when we run it… So when we run it, we get the same exact thing. Now that was three different loops for the same exact result, but see how differently those things are executed. Here I have put them in for achieving the same thing, but there are different loops for different utilities in shell scripting.
With that, we come to the end of the first segment of our shell scripting interview questions. Now let's move ahead to slightly tougher ones which are for the intermediate level of professionals. For shell scripting interview questions, now let's move ahead to slightly tougher ones which are for the intermediate level of professionals. So the first question in this segment: where exactly can you store the shell programs in the system? The answer is pretty simple: they're stored in a file which is tagged as `.sh` or the Bourne shell, as you might have noticed. There is the shebang angling that you put right in the beginning that basically points to the file where your program is going to be stored. What makes C shell a more preferable option?
Than the bond shell, well, there are three points which speak more in favor of the seashell than the bone shell. Firstly, all the commands in the seashell can be aliased, whereas in the bone shell, all of them cannot be aliased. Secondly, seashell is great for reusing your script; lengthy commands can be used again and again in the seashell, whereas in the bone shell it does not allow the same. And the third and final thing is the access to command history, which is there again in the case of seashell and not there for the bone shell. Okay, so the next question is, what is the difference between these two special variables? One of them is a dollar and asterisk sign, and the other one is a dollar followed by the address sign.
Now, the meaning of these two are pretty identical when not quoted or used as a parameter assignment value or as a file name. However, when you use it as a command argument, what the dollar and at sign does is that it treats each quoted argument as a separate argument; but when it is the dollar sign followed by an asterisk, it will consider the entire set of parameters as one single string. So, if you are passing a sentence as a number of parameters to a script, what the dollar and at sign will do is that it will print each word on a different line because it treats them as different parameters; but the asterisk which follows the dollar sign will not do the same; it will take the entire sentence as one single string and print them on one line. So now let's move on to the next question.
How would you compare the strings in a shell script? Now, basically you use this command known as the test command, which is used to compare the test strings. Now, how this works is that this command will compare text strings by comparing each character in each string. So, suppose I have two strings, both the same, called "word". First, the test command is going to check the first character of each, which is W; once that matches, it's going to go to O, and so on and so forth. Once all of these match, it classifies them to be the same string.
Next, how do you redirect both standard outputs and the standard error to the same location? Now, there are two methods to rewrite extended outputs and error to the same location, and they are what you see on your screens right now. These are the two commands which will redirect your standard output and standard error to the same location.
Next is a differentiation between single and double quotes, which I shall demonstrate further in this segment. So, your single quote: you use it when you do not want to evaluate the variables into values. So, if you say "Echo" and put in a single quote where you are calling a variable, it is going to print that variable as is; whereas in a double quote, you use it when all the variables that are inside the quotes need to be evaluated. So, in a double quote where there is a variable that is being called, it is going to replace that particular variable with the value stored in it. This I am going to demonstrate in a little while in this very segment.
So the question is, when should shell programming or shell scripting not be used? So, when the task is very complex, like writing an entire payroll processing system, or there's a high degree of productivity required and it involves various different software tools, it is not the most ideal to use shell scripting.
Next question is, what is the lifespan of a variable inside a shell script? So, the lifespan of a variable inside a shell script only lasts until it is executed, that is, until the end of execution, and that is it; any further than that, the variable inside the shell script is not of any use.
So what is a file system? Now, basically it is a collection of files which contain information that is related to the files in computing. A file system controls how the data is stored and retrieved. Without a file system, information placed in a storage medium would be one last body of data with no way to, well, whether one piece of information stops and where the next one begins.
Question 30: What are the default permissions of a file when it is created? So, the default permissions of a file is 666, which is: the user is allowed to read and write the file; the user group is allowed to read and write the file; and so is everybody else. As you can see, there is a table on your screen which has numbers as 0 to 7. Now, each of these numbers have a default permission which is associated with it. So, when we type in 0, it means there are no permissions; 1 is execute; 2 is write; and 4 is read. The remaining you can split as a sum of integers and find out what is the permission associated with it. 6, as you can see, is 2 + 4, so it means read and write; and finally, when you type in 7, it is equal to 1 + 2 + 4, which means you can have all permissions to execute, read, and write. When we type the same thing thrice, the first one will stand for the user permission, the second is the group permission, and the third one is permissions for everybody else. And that was all about the default permissions. Let's move on to the next question.
So, what does it mean by the shebang line, sh or bash, at the beginning of every script? I'm here at the terminal and I am going to open up a simple script to demonstrate. Now, as you can see, there is this shebang line, shebang/bin/sh, which is there, which you will find in the beginning of every shell script. Now, what this line does is it's nothing but the absolute path to the shell interpreter. It consists of the shebang, which is the hash and bang, followed by the full path of the interpreter, such as bin/sh or bin/bash. All the scripts under Linux using this particular interpreter are specified on the first line. The shebang must be the first line because it is interpreted by the kernel, which looks at the two bytes at the start of the executable file. Since the kernel will only look at the first two characters and has no notion of for the lines, you must place the hash and bang in the first line, so the program loader mechanism parses the rest of the file's initial line as an interpreter directive. That was all about the significance of the shebang line. Let's go back to the presentation and look at the next question.
Now, this is "determine the output of the following command" kind of a question. So, obviously we are going to go to our terminal. So, in bash or the bone shell or any similar shell, this is basically a shorthand way of writing an if statement. So, basically, if this is true—if this non-zero bracket is true—then echo 0; else echo 1. For a simple test like this, if you do not want to waste a lot of time or waste five lines of valuable screen editor vertical space, then you can take advantage of the logical and, which are these two ampersands, and the logical or, which is these two pipes, and how they work in a shell. So, echo 0 is executed if the statement is true, and echo 1 is executed if this statement is true and this one is false. So, basically, it returns a non-zero exit code, and this is why it should not be used if there is any chance of that occurring. This will give you a result of 0, and that is why it should not be used if there is any chance of the latter statement to come true, which is the output of 1, even though this condition is true. In other words, it's almost equivalent to these five lines of code, which I'm gonna put it right here. It's basically equivalent to these five lines of code, and you get the same answer. Now, this full form does not have the same flaw that the shorthand form does. This construct is correct and always works, while the shorthand is a quick hack, and it is useful in only limited circumstances. This particular Z flag is only a test of whether a string is empty or not, and it will always display a zero.
Next question is again "determine the output" sort of a question. So, this is your command, and you have to determine the output of this command. Now, this is the same command in the terminal. It's a very simple command; it's basically assigning the value "John" to a variable called name, and here in the string it is calling that name in single quotes—pay attention, this is a single quote—and we had discussed this earlier in this segment, the difference between single quotes and double quotes. Later, I'm going to do the same using double quotes, and you will see the difference for yourself. Here, as you can see, because it is inside single quotes, it does not call the value of name. If I try to do the same thing using double quotes, it has called the variable, which is "John," and that is the difference between single quotes and double quotes.
Question number 34 again is a "determine the output" question. Okay, so let's go to our terminal. So, basically what is happening is the variable is being assigned using this particular notation, or some people even use this to expand their own variable. Now, the answer to this is simple; the answer is going to be just "variable". So, the value "variable" is being assigned to the variable "new," but why are people doing this? Why is the variable being assigned like this? Now, this technique has its own advantages; it allows for a variable to be assigned to a value if another variable is either empty or undefined. Okay, moving on.
So, question number 35: How to get a part of the string variable with an echo command only? So, for that we have a script here, all right. So, basically we start with taking in a parameter, so a variable X and Y, where X is your start position, or from where you want to pick from the string, and your Y being length for the part of the string that you're trying to pick out from this particular sentence. So, this is the string that is allotted to the variable "variable," and finally we are printing out seven characters from position 11, which is this position; we are picking out seven characters from position 11, and it should basically print out "my name," all right, and it prints out seven characters from the 11th position, which is basically "Upasana"—that's my name.
Question number 36: So, rewrite the command that is given. So, here it is: "I like" and whatever variable we are calling. So, rewrite the command to print the settings and convert the variable to plural. Let's see how we can rewrite and convert this. Okay, so this is what's been given to us: "I like the certain variable." So, firstly, I am going to allot something to that particular variable. So, I'm gonna go ahead and… so basically allotted a string value called "plane" to "variable," and here I'm putting "variable" in curly braces and adding an S, so it will take whatever is there in the curly braces and switch it with the value of the variable, and that's it—a change to "I like planes," and it's as simple as that.
Question 37: How to print all the arguments provided to the script? The answer is pretty simple, actually. You can just go ahead and do a dollar star, or you could do a dollar at. If you want to see how it is executed, you can just do "echo dollar star," and then "happy learning," and it prints "happy learning"—it's as simple as that.
Next question is: How to print the PID of a current shell? It's simple; you just go ahead and use two dollar signs. So, if I do "echo" and two dollar signs, you get 6023, which is the PID or process ID of this particular shell. Okay.
Next: How to print the first array element? So, this is a simple script with an array, which is "hi my name is apasner," and basically what you're doing is printing out the zeroth element; it's it's really not that tough; you might have done the same while using any programming language, that is, and it printed "hi," which was the first element. And this is the final question of the segment: How to print all the array elements and their respective indexes? So, again, it's the same array that I've taken here; I'm printing out all the arrays; I'm using the at sign, which is used for all the arrays; and here, if I just use the bang before your variable, I can print the indexes, and by bang I mean the exclamatory sign. Here in Linux it is called the bang, and there you go: "hi my name is apasna," and the index number is 0 1 2 3 4. With that, we've come to the end of the intermediate section. Next, we have some questions for the experienced people with three to five years of experience in shell scripting, Linux, or Unix. This section will also have some scenario-based questions, obviously in the practical form. So, the last few questions are for professionals with three to five years of experience at least. Here we have a few scenario-based questions which may help you build on that resume that you have created with so much care. So let's go ahead.
If you're experienced, you might know there's something known as cron. The first question is: What is the crontab? Now, the crontab is a list of commands that you want to run on a regular schedule, and also the name of the command that is used to manage that list. So, the schedule is called the crontab, which stands for cron table, because it uses the job scheduler cron to execute tasks. This is also the name of the program that is used to edit that schedule. This software utility is a time-based job scheduler. Now, people who set up and maintain software environments use cron to schedule these jobs to run periodically at fixed times, dates, or intervals. So the next logical question obviously is that: What does each field do in a crontab file?
Now, the crontab file has six fields, the first five of which tell the cron when to execute the command; they specify the minute, hour, day, month, and day of the week; and the sixth field contains information on which command is to be executed. I'm sure a lot of you might be finding a lot of these questions pretty simple, but this is mostly because you must be working on Linux on a day-to-day schedule. Even if all these questions are pretty small, they are mostly knowledge-based, and there's a high possibility that people who are in touch with shell scripting and Linux because of their daily jobs or because of their university courses will do better in interviews because of practice. With that, let's move on to question number 43.
What are the two files of the crontab command? Now, the two files of the crontab command are cron.allow, which decides which users need to be permitted from using the crontab command, and next is the cron.deny; it decides whatever users need to be prevented from using the crontab command. In Red Hat-based systems such as CentOS, these crontab files are stored in the /var/spool/cron directory, while on Debian and Ubuntu files they are stored in the /etc/cron.d/crontabs directory. If you look for it, you may just find it in your particular OS.
Next question: Which command do you need to use to take backup? Now, to take backup you need the tar, which basically stands for tape archive. Now, you can go ahead and add the extension of cvf to zip the files and xvf to unzip the file. Now, tarball files are also used when you download a number of files from the Internet or your emails. So, tar is basically your most efficient command which you need to take a backup.
Question 44: What are the different commands available to check the disk usage? Now, there are three different commands which you can check the disk usage with: you have df, du, and df -h. Now, the df command, which is short for the disk file system, is used to show the disk utilization for a Linux system. You can display information of the device name, total blocks, total disk space, used disk space, and available disk space and mount points on a file system through this command. You can also get the information in a human-readable format or at a particular partition. Then there is the du command, which is short for disk usage. Now, this is a useful command because you can find disk usage for files and directories. The du command, when used with various options, provides the results in various formats. For example, you can find out the summary of disk usage for a directory with all its subdirectories using this. The output of the command shows all the files and directories in /home with block size. And finally, you have the df -h, which is the command used to check the free disk space—same as df, but in terms of MB. So that's all about checking disk usage. Let's move on to the next question.
What are the different communication commands available in shell? So, there are four different communication commands in the shell: you have mail, news, wall, and motd. Now, whenever a mail is sent, initially the mail command calls the standard sentmail binary which is located in the user file. It allows you to read or send a mail. The news command writes system news items to standard output. This command keeps you informed of news concerning the system; each news item is contained in a separate file in the news directory. Then you have the wall command. The wall, or the Linux wall, is an abbreviation of write to all. So, basically, this is a utility that displays the content of a computer file or the standard input to all the logged-in users. It is typically used by root to send out a shutting down message to all users just before power off. And finally, you have motd. So, motd basically stands for message of the day, and it is used to send a common message to all the users in a more efficient manner than sending them all an email. Message of the day systems might also have an motd feature, such as the info segment on MULTICS. This feature is a file on all Unix-like systems and can be changed at upgrade or during installation time.
Next: How would you find out the total disk space used by a specific user? Suppose the username is edureka. So, the given command here is used to find out the total disk space. As we had discussed earlier, there is the du command with the path, which is /home/edureka, with the -s flag, which will show how much the space is used by each subdirectory.
Next: How to debug the problems encountered in each script or program? So, there are two ways to do it: one is by inserting debug statements in the shell script to output or display the information which helps identify the problem; and second, by using set -x, we can enable debugging in the script.
Next: The difference between single equal sign and the double equal sign. Now, the first one is for assigning value to a variable, and the second one is used for string comparison. The comparison operator, or the double equal to sign, behaves differently within double brackets test as the single equal to sign is an arithmetic operator and the double equal to sign is a string operator as well as an arithmetic operator, which is meant not for assigning but for comparison.
Next: How to open a read-only file in a shell? Now, if you work continuously with Linux and shell scripting, you might know the answer to this. Basically, you use the vi command with the +r flag and the file name that you want to read to open a read-only file in the shell. And this is the last theory question of the module: How can the context of a file inside a JAR be read without extracting it in a shell script? Again, this is a command called tar, which we had discussed earlier—the tar, which stands for tape archive, and its flag tvf, which can basically be expanded to: t meaning the table of contents, v means verbose, and f means file, followed by the file name and the tar extension.
Next question 51: Where can you specify two method words of passing parameters to your script? Okay, let's see two methods, is it? So, the first way is going to be how we've done it many times earlier, and you might have seen it many times here in this video: you basically write your script name and then you pass your parameters. One way is this, and next is you can use your read with the -p flag, and you can pass your parameter inside with your destination hostname. So, those are the two ways in which one can read parameters.
Next: Write a shell script to get the current date, time, username, and current working directory. So, here I have written… all right, so here is our script; it's pretty simple to follow, actually. Here… hello… whatever your log…
name is. Then there is date, which is going to include time, and this is the user. And this particular statement is going to print out your current directory, which is the PWD command. So we are going to change the permissions associated to it, and then we're going to run this. So here I have my log name, which is at Eureka. The date command printed out the date and time. This is the username and the current directory /home/edureka, which you can see even here; it's pretty simple. Each command is very self-explanatory. Let's move on to our next question.
How do you find all the files modified in less than three days and print the record count of each? Let's go ahead. Okay, so basically you're going to use the find command and the mtime flag. Then here is the number of days, and we're going to execute it. And then whatever it is that we are finding out from our list that we are going to put into a text file called the last three days. All right, so it's going to take some time, and it's done. Now we go ahead and do an ls. You can see the last three days text file is created, and if we open the last three days text file, you see all the files that have been modified in the last three days. All right.
Next question: Write a shell script that adds two numbers if provided as the command line argument, and if the two numbers are not entered, it throws an error message. This seems like an interesting one. Let's go ahead and all right. So let me explain to you a little bit about what's happening in the shell script. So firstly we are starting out with an if statement, which is like a preventive step that if two inputs are not received from the standard output, then you are going to execute the below statement, and then you're going to explain to whoever the user is that you have to put in two integers for which I will print the sum, and that is what is written here. And then you have your exit statement, and then you exit the if statement. And at the end of it, if they do put in two positive integers, the statement basically prints the sum of those integers. It's pretty simple. So let me exit this. So first I'm going to run the script without entering two numbers as command line argument. So let's see what happens if I do that. Here prints out this statement; it asks you for two numbers X and Y, where X and Y are two numbers for which the script is going to print the sum. Next again, let's try to enter X and Y. When the numbers are entered as we are instructed, it says sum of 5 and 3 is 8, and that's how simple it is. Hence this script fulfills the condition as suggested in the question.
Next it asks: Print a given number in reverse order using a shell script such that the input is provided using the command line argument only. So let me open. All right, basically this is what the algorithm is: Let your input number be n, which is going to be taken in by the command line, and then we are setting the variable reverse as 0, and sd or single digits is set up to zero as well. Then your single digit is going to be achieved by taking n Mod 0 10; this will find and give the single left most digit. Then you're going to reverse the number that is generated as your reverse into 10 plus your single digit, and then decrease the input number by 1. Now then, if your n is greater than 0, then you go back to step number three, and then print reverse, and hence finally your reverse number is printed. So now I'm going to run the script, and I'm going to pass in a number, say one two three four five. Now here I haven't put in a number, so again like the previous question, it is going to instruct me on how to make use of this, for example this. So let me go ahead and give them what they want. I'll put in a space and go for one two three four five, and it gives me back the reverse number, which is five four three two one.
Next question: Calculate a real number calculation directly from the terminal and without a shell script. Now I know that this is a shell script tutorial, but there are a few things which are related to the shell script, but you have to run them directly from your terminal. So this is important. So let's go ahead and do that. So we'll need to use the BC command in a special way for this answer. So what we're going to do is we're going to print it out, and then we're going to put it; we're going to put two real numbers, let's say 4.432, just and then pipe in, and it gives us the answer. So basically what you're going to do is you need to use the pipe space BC command where the answer of these two real numbers is going to be piped into the BC command. For that, obviously you need your BC maths package installed. With that, let's move on to our next question.
How can you get the value of pi till a hundred decimal places? So basically what we're going to do is we're going to use the BC math package again. Here I'm going to directly print this out. I'm scaling this up to 100; I'm putting a scale as 100, and here I am putting in the pi, and here you have it; this is the value of pi till 100 places. Now again, I'd like to remind you that for this to work, you need to have installed your BC math package. Since my system has CentOS running, I use yum install. For other Red Hat Enterprise limited OS's, you can use apt-get, and for Debian based systems, you can use dnf.
Next question: How to check if a directory exists? This is a pretty simple script. Here you are taking in as a parameter or an argument your name of the directory, which I'm allotting into my dir, and this is your directory flag. So basically, if the answer to this is non-zero, then it's going to print your directory exists, and then you close your if statement with an fi. All right, let's go ahead and try and run this. Put in the name of a directory, say public, and then it says directory exists. So if I go ahead and type this is your question 58 and says let's see public, and you know the directory exists because if I open my list of directories here, you can see in blue you have public. Okay, so let's clear this out. So question number 59: Can you write a script to portray how set -x works? Now as we had discussed earlier, this is a way of debugging a script. So let's go and see how it works. So here I have written a script which obviously is going to throw an error at me. So if I hash out, comment out this set -x line, let's see the answer that we get. It basically shows this, as I said; it is a script that is supposed to throw an error at me. Now let me go back and uncomment this particular line, and there you have it. Now, in addition to displaying the intended output in the loop iteration lines, it enables debugging with the set -x and also shows each line of execution preceded by a plus sign. Although this can become impractical when it comes to larger shell scripts, it should be obvious how useful this can be when debugging a shell script to identify the root cause of the problem. Let me clear this out.
And finally, this is your last question: How will you find the total disk space used by a specific user? So as I had mentioned before, we are going to be using the du command and then go with my user, the current user that is edureka, and here you have each directory, each file, how much space they have taken. This seems like a pretty long list to me. [Music] Let's move on to Linux versus Windows. This might be the reason most of you are still hooked on to this session. So let's start up with users. Now there are three types of users in Linux: you have regular, administrative, and service. Now a regular user account is created for you when you install Ubuntu on the system. All your files, folders are stored in /home/, which is your home directory, and as a regular user, you do not have access to directories of other users. Next you have the root user or the administrative user. Other than your regular account, another user account is called root, and it is created at the time of installation. The root account is a super user account who can access restricted files, install software, and have administrative privileges; hence the name administrative user. Whenever you want to install software, make changes to the system files, or perform any administrative task on Linux, you need to log again as a root user. Otherwise, for general tasks like playing music and browsing the internet, you can use your regular account. And the third and final account is the service user. Linux is a widely used as a server operating system, and services such as Apache, Squid, email, etc., have their own individual service accounts. Having a service account increases the security of your computer. Now Linux can allow or deny access to various resources depending on the service.
Now in Windows, there are four types of user accounts: you have your administrative, standard, child, and guest account. Next let's go ahead and look at usage. Now, according to the market research data of September of 2007, 92 percent of the world's PCs had Windows running, while only about 1 percent of PC users use Linux. The home users, multimedia enthusiasts mainly use Windows, whereas for serious use, server application, corporation servers for running on Linux. Irrespective of the GUI, many users found it difficult to use Linux as compared to Windows, obviously due to the command line interface, and so the appeal of Linux was very limited to common people. Also, for licensing agreement with Microsoft, various PC vendors are entitled to bundle Windows OS with their PC, and for this, Windows gained the initial market popularity over Linux. Though these days, many PC vendors such as Dell and HP started to give Linux as a pre-installed OS to cut the cost of their PC system. According to the latest IDC report, Windows Server market is gaining popularity over Linux based server. The annual rate at which Linux is growing in the x86 server space has fallen from around 53 percent to 45 globally. The main reason is that while Linux servers are looking for high-performance computing and web serving, Windows is apparently adopted on a much broader basis.
Next let's move ahead and look at what the kernels are like. Now Linux uses a monolithic kernel which consumes more running space, whereas Windows uses the micro kernel as of the latest versions, which take less space. With the system running, efficiency is lower than Linux. Next let's look at file systems. In the Microsoft Windows, files are stored in folders on different data drives like C, D, E, but in Linux, files are ordered in a tree-like structure starting with the root directory. Now this root directory can be considered as the start of a file system, and it further branches out various subdirectories. Now the root is denoted with a forward slash, and a general tree-like system on your Unix may look like something like this on your screen. In Linux and Unix, everything is a file; directories are files, files are files, and devices like printer, mouse, keyboards are also files, which is not the case in your Microsoft Windows.
At number five, we have security. Every Windows user has faced security and stability issues. Since Windows is the most widely consumed OS, hackers, spammers all target Windows very frequently. Consumer versions of Windows were originally designed for ease of use of a single user PC without a network connection and did not have the security features built in. The Microsoft releases security patches through its Windows update service approximately once a month, although critical updates are made available at shorter intervals when necessary. Many times, users of Windows OS face the blue screen of death caused by the failure of the system to respond, and eventually the user has to manually restart the PC. This is super frustrating, and it also may cause you to lose valuable data. On the other hand, Linux is a very stable OS and is more secure than Windows. As Linux is community driven, developed through people collaboration and monitored constantly by the developers from every corner of the world, any new problem raised can be solved within just a few hours, and the necessary patch will be ready at the same time. Also, Linux is based on Unix architecture, which is a multi-user OS, so it is much more stable than a single user OS such as Windows.
Next let's look at compatibility of the two. Here Windows shoots and scores. Here is where the Redmond offering wipes the floor with Linux. Despite recent improvements in software being ported or developed to Linux, Windows is still the king. Users of Windows can be certain that most softwares will work, and even obscure, outdated software will continue to work even when it is abandoned by developers. Windows has good legacy support, plain and simple. I know of commercial software that still relies on technologies like Silverlight, ActiveX, and Internet Explorer 11. Linux, on the other hand, can struggle with the basics that Windows users take for granted. Adobe Flash Player is something else that is missing on Linux for a really long time, and even when it did appear with repositories, it was not as actively developed as Windows versions. With regard to file systems, Linux can also read and write to NTFS and FAT formatted devices and USB sticks, whereas Windows will have no idea what ext4 is.
At number seven, we have ease of use. Now this is a tough one to call. Linux, over the recent years, has made huge leaps in usability. Distributions like Linux Mint have made installation and setup pretty simple. Even non-technical users can install and use software and do normal day-to-day activities like web browsing, answering emails, playing music, and watching videos. Windows, due to high market proliferation, is the default OS of many devices. Now think of it; people like you and me, we grew up on Windows, right? Buy a new laptop or a PC; there is a very high chance that it comes with Windows installed. Users are used to clicking the toolbar, opening their favorite programs, which makes it good for power and non-power users.
Next we have privacy. Linux users have a private operating system that does not spy on them and does not phone home with any degree of seriousness, period. Choosing Linux means the system is yours and yours alone. Add to the mix that most Linux systems come with an option of a built-in military-grade encryption, and users can be sure that the device theft poses no real problem to their own data. As a contrast, increasingly over the last few years, Windows has gotten more ad-words driven. Users are given the choice to opt out, and there are some clever registry hacks that can help, but advertising is now a part of Redmond's plan. Windows can also watch what users do, offering syncing to Microsoft OneDrive service or to learn behavior to make Cortana, the Microsoft personal assistant, better. Personally, I do not favor these kind of intrusive tools, but some users do like these features. Like, who wouldn't want a personal assistant in your laptop? You already have your Google Assistant and your Siri, right?
Next you have source code. Now this all of you might know: Linux is open source, whereas Windows is commercial. So users have access to the source code of Linux and can alter the code as per user need, whereas Windows users do not have any access to their source code. Now this has its own advantages in Linux, like bugs and OS will fix at a rapid pace, and disadvantages like developers may take advantage of any weakness in the OS if they are found. In Windows, every user would not have access to the source code; only members of a selected and qualified group will have access to it.
Next you have license. Now the Linux kernel and the GNU utilities and libraries which accompany it in most distributions are entirely free and open source. You can download and install GNU Linux without any purchase. Some companies offer paid support for their Linux distributions, but the underlying software is still free to download and install. A funny folklore here is that Linus Torvalds actually was an introvert and did not want companies to communicate with him through email; he did not want to be spammed by all these big companies running the industry to buy the source code to his kernel. So basically what he did was he made it open source for everybody to access. Funny, isn't it? Now on the other hand, you have Microsoft Windows, which usually costs between 99 to 199 US dollars for each licensed copy. Now Windows 10 was originally being offered as a free upgrade to current owners of Windows 7 or 8.1 if they upgraded before the 29th of July 2016, but that offer is no longer available.
When you have reliability, now Windows, as we know it, becomes sluggish day after day. You will want to reinstall Windows after a while when you encounter crashes or slowdowns on your system. If you're using Linux, you will not have to worry about reinstalling it just to experience a faster, smoother system. Linux helps your system run smooth for a longer period of time; in fact, much, much longer in my experience. Also with Windows, you will have to adapt to a habit where you keep on rebooting the system for just about everything: if you just install software, reboot; if you recently uninstalled software, reboot; if you just installed a Windows update, reboot; and if the system seems to slow down, you guessed it, reboot. However, in the case of Linux, you will not have to reboot for the situations previously mentioned. You can comfortably continue with your work, and Linux will not; will allow. Another fact that proves Linux to be a reliable source are the web servers. You could observe that most of the internet giants like Google and Facebook run on Linux. Even most of all the supercomputers run on Linux. So why isn't Windows preferred over Linux? It is because Linux is far more reliable than Windows, period; no arguments.
Finally we have support. Now Windows has a support which is easily accessible online forums or websites, and it has paid support as well. In a Linux system, you'd need not hire an expert to solve a problem; you just need to search for a familiar thread on the web for a solution or post a thread to let others know of the problem. Within minutes of posting the thread on any Linux forum, you may expect a reply along with a detailed solution which would finally helps resolve your problem at no cost. It's like Linux has its own Stack Overflow community, doesn't it? Now there are a lot of active Linux users who are always ready to respond to a relevant thread that might have created. The number of community users active on such forums is more than the number of active members on any Windows focused forum any day. However, the community response might be depending on the Linux distribution being used. With that, I come to the end of my Linux versus Windows segment.
The last category is distributions. Now, before we begin, I need to address one of the more confusing aspects to the Linux platform. While Windows has maintained a fairly standard version structure with updates and versions split into tiers, Linux is far more complex. Originally designed by the Finnish student Linus Torvalds, the Linux kernel today underpins all Linux OS's. However, as it remains open source, the system can be tweaked and modified by anyone for their own purposes. What we have as a result are hundreds of bespoke Linux based operating systems known as distributions or distros. This makes it incredibly difficult to choose between them; far more complicated than simply picking Windows 7, Windows 8, or Windows 10. Given the nature of open source software, these distros can vary widely in functionality and sophistication, and many are constantly evolving. The choice can seem overwhelming, and particularly the differences between them aren't always immediately obvious. On the other hand, this also has its own benefits. The variety of different Linux distros is so great that you can all find something that suits your particular taste. Do you prefer a Mac OS style interface? You're in luck. Elementary OS is a Linux distro built to mirror the look and feel of an Apple interface. Similarly, if you yearn for the days of Windows XP, you can bring that back with a Q4OS, which harkens back to Microsoft's fan favorite. Now there are more specialized Linux flavors such as distros designed to give ancient, low-powered computers a new lease of life or super secure distros that can be booted from a USB drive to keep you safe when using an unfamiliar PC. Naturally, there are also numerous Linux versions for running servers and enterprise grade applications. For those who are new to Linux, I'd like to recommend Ubuntu as a great starting point. It is very user friendly, even compared to Windows, while still being versatile and feature rich enough to
Satisfy experienced techies is the closest thing Linux has to a default distro, although we would urge everyone to come and explore various distribution options available and find out what is your favorite.
Next, let's look at which OS is most suitable for you. Now, this one depends on what you need to do. Both Linux and Windows are rich in multimedia applications, though setting up sound and video options in the older versions of Linux can be difficult for some users. The main advantage of Linux is that most of the multimedia applications are freely available, while in the case of Windows, users might have to pay a hefty amount to get the software, although many open-source free versions are often available. Moreover, if anybody buys a copy of Windows on a CD-ROM, they do not get any application software with it other than the bundled Microsoft software. But if the same person buys a copy of a Linux, it typically comes with a lot of free application software, such as OpenOffice, a complete free office suite including spreadsheets, presentations, so on and so forth. A new computer with Windows pre-installed may have additional application software, but that is totally up to the PC renderer. But each Linux distro comes with multiple flavors; the more expensive versions come up with more application software.
If you're a gamer and need 100% compatibility with a particular software or want a user-friendly system, hands down Windows wins. Steam, amongst other clients and options, provides a huge number of games for both AAA publishers and small Indie developers. While Steam for Linux now allows you to install Windows games, it is still in beta phase and not all Windows games will work. It can be a little frustrating for Linux users like myself, and no doubt the situation will change in the future, but as of now, in 2019, many Linux users miss out on the top games with their choice of OS. The graphics card vendors also tend to support Windows platforms rather than Linux; they provide timely updates and new features that don't always filter to other OSS.
If you are an advocate of open-source software, or if your device simply is too old or lower spec to run Windows, or just plain tired of all the forced updates and reboots in Windows, then Linux is a great option. Linux supports almost all major programming languages: Python, C, C++, Java, Perl, Ruby, etc. It offers a vast range of applications useful for programming purposes too. Now, the Linux terminal is superior to use over Windows command line for developers. You would find many libraries developed natively for Linux. Also, a lot of programmers point out that the package manager on Linux helps them get things done easily. Interestingly, the ability of bash scripting is one of the most compelling reasons why programmers prefer Linux OS. Linux also brings in native support for secure shell, which would help you manage your servers quickly. You could include things like apt-get commands, which further makes Linux one of the most popular choices for programmers.
Let's move on to the differences between both of these OS's. So let's look at our first basis of difference: the use. Now, Unix is mostly used in internet servers, workstations, and PCs, while Linux is used by everyone from home users to developers and computer enthusiasts alike, because Linux OS can be installed on various types of devices like mobile phones, tablets, and computers.
Development and distribution: Now, Unix systems have different versions, and these versions are primarily developed by the ATT as well as other commercial vendors. While Linux, as most of us know, is open source, and thousands of programmers collaborate online and contribute to its development, its features through forums, etc., and is distributed by various vendors.
Now, talking about the architecture: Unix is available on PA-RISC and Titanium machines; Solaris is also available for x86 or x64-based systems. Now, Linux originally was developed for Intel's 86 hardware, so the ports available are for over two dozen CPU types, including the ARM.
Now let's talk a little bit about the processors of the two. Now, Unix supports your x86, x64, SPARC, Power, Titanium, PA-RISC, PowerPC, and many others, whereas the Linux has a wider variety of processors that it supports, which include dozens of different kinds of processors.
File system support, or the supported file type: Now, Unix supports ZFS, HFS, GPS, XFS, and VXFS systems, whereas the Linux is supported by file types XFS, NFS, TRAM, FSM from one to four, UFS, devpts, and NTFS, which again is a wider variety of file types.
Next, let's talk a little bit about something both of these are very known for: that is their shell interface. Now, the Unix was originally made to work in Bourne shell, or the basic shell that we all know of; however, it is now compatible with many other softwares. Whereas in Linux, bash is the default shell; it offers support for multiple command interpreters.
Now that we've spoken about the shell interface, the next logical question is obviously about the graphical user interface. Now, the Unix has a common desktop environment and also has GNOME, whereas Linux provides two GUIs, which are the KDE and GNOME, though there are many alternatives such as MATE, XFCE, etc., which are just a few of the millions of alternatives that it has.
Next, let's talk a little bit about the portability of each of these. Now, Unix is not portable, period. That's it. But Linux is portable and is booted from a USB stick, which is a big plus in the side of Linux.
Now, of course, this is the next question: security, which is one of the most important features when we move to a certain OS. Now, till date, there are between 80 to 120 viruses that have been reported in Unix, whereas Linux has had about 60 to 100 viruses listed to date, which are currently not spreading. So the next most logical question is the threat detection and solution procedures. While Unix users require longer wait time to get the proper bug-fixing patch, threat detection and solution is very fast in Linux because Linux is mainly community-driven. So if Linux users post any kind of threat, a team of qualified developers start working to resolve this threat.
Now next, let's talk a little bit about the source code. Now, this must be obvious to all of you, as we all know the source code of Unix is not available to anyone, whereas Linux, being an open-source OS, the source is available to the general public.
And finally, the license: This is something most of you must be waiting for. Now, in Unix, different flavors have different pricing depending upon the type of vendor, whereas Linux is freely distributed, downloaded through magazines, books, websites, etc. There are priced versions for Linux as well, but they are normally cheaper than that of Windows.
Now let's discuss a few limitations of each of these OS's, starting with Unix, shall we? Now, the limitations of Unix: Firstly, it has an unfriendly, terse, and inconsistent and non-mnemonic user interface. Apart from that, the Unix OS is designed for a slow computer system, so you can't really expect a fast performance. Versions on various machines are slightly different in Unix, so it lacks consistency. And finally, Unix does not provide any assured hardware interrupt response time, so it does not really support real-time response time systems. Apart from this, the shell interface can be treacherous because a single typing mistake can destroy a lot of files.
With that, let's move on to a few limitations that Linux possesses. So here are a few limitations in Linux: First of all, there is no standard edition of Linux. Secondly, Linux has patchy support for drivers, which basically may result in the misfunctioning of the whole entire system. Many of the programs we are using for Windows will only run on Linux with the help of complicated emulators, for example, the Microsoft Office. And finally, Linux is really suitable for only corporate users; it is way harder to introduce in a home setting. Linux, for new users at least, is not as easy to use as Windows.
[Music]
So let's get rid of interview questions here. The first question, the basic question would be: What is Linux? Okay, so as a layman, as an interviewer, if I ask this question: What is Linux? The first answer would be: It is an operating system. So before I get into Linux, first of all, let me explain you like what is an operating system. Every time you switch on your computer, you see a screen where you can perform different activities like read and write, or browse the internet, or watch a video. What is it that makes the computer hardware work like that? How does the processor on your computer know that you are asking it to run an MP3 file? Well, it is the operating system or the kernel which does this work. A kernel is the program at the heart of the operating system that takes care of fundamental stuff like letting hardware communicate with software. So to work on your computer, you need an operating system. In fact, you're using one as you read this on your computer. Now you may have used popular OSs like Windows, Apple OS X, but here we will learn what Linux is and what benefits its offers over other OS choices. So Linux is an operating system or a kernel which germinated as an idea in the mind of young and bright Linus Torvalds when he was a computer science student. Linus Torvalds is considered as the father of the Linux operating system. So when he was as a computer science student, he took a Linux kernel and he developed it from the scratch. He used to work on Unix operating system, which in those days called as a proprietary software, and thought that it needed improvements. However, when the suggestions were rejected by the designers of Unix, he thought of launching an operating system which will be receptive to changes, modifications suggested by its users.
The benefits of using Linux operating system: What are the main benefits and why it gained more popularity compared to other operating systems? The main benefits are: it offers a free operating system; you do not have to shell hundreds of dollars to get the OS like Windows. Being open source and modified source code, the Linux operating system now offers millions of programs, applications to choose from; most of them are free. Now, once you have Linux installed, you no longer needed an antivirus because Linux's highly secure system. More so, there is a global development community constantly looking at ways to enhance its security. With each upgrade, the OS becomes more secure and robust. Linux is the OS of choice for server environments due to its stability and reliability. Mega companies like Amazon, Facebook, and Google use Linux for their service. A Linux-based server could run non-stop without a reboot for eons on end. Okay, this is all about Linux. So Linux is just an operating system or a kernel, okay, which has been developed from Unix operating system. So this is what we have discussed.
Coming to the next question: How different is Linux when compared to Unix operating system? You might face different types of questions when you attend this type of interviews in Linux operating system, like what is the comparison, what is the differences did you find between like Linux and Unix operating system? As I said earlier, Linux is the Unix clone, but if you consider it according to the POSIX standards—POSIX is nothing but a portable operating system interface—according to this standards, Linux can be considered as Unix exactly. To code from official Linux kernel README file: "Linux is a Linux clone written from the scratch by Linus Torvalds with assistance of hackers across the net." So I'll just take some strategies here in terms of cost, in terms of development and distribution, in terms of manufacturer, like what are the differences between Linux and Unix? In terms of first, Linux can be freely distributed, downloaded freely distributed through magazines, books, etc. There are priced versions of Linux also, but they are normally cheaper than Windows operating system when you compare with Unix. In Unix, we have different flavors of Unix have different cost structures according to the vendors. In terms of development and distribution, Linux is developed by open-source development, that is through sharing and collaboration of code and features through forums, and it is distributed by various vendors. When coming to Unix, Unix systems are divided into various other flavors, mostly developed by AT&T as well as various commercial vendors and non-profit organizations. In terms of manufacturer, Linux kernel is developed by the community by Linus Torvalds; Linus Torvalds will oversee things. And when you talk about Unix, three biggest distributions are Solaris, which is now acquired by Oracle; AIX by IBM vendor; HP-UX it's by Hewlett-Packard; and Apple makes OS X, which is also a Unix-based operating system. Okay, so I've just taken three aspects here like cost, development and distribution, and manufacturer. Like this, we have many such differences between Linux and Unix operating system. Okay, so this is what we have discussed.
Okay, coming to the next question like what is the importance of GNU project? GNU project was launched in September 1983 by Richard M. Stallman to create a complete operating system which is free software. The main intention of GNU project is to create an operating system which is completely open source, which is completely freely available for all public users. The main licenses of the GNU project are the GNU GPL, which is nothing but the General Public Licenses. The name of the GNU project is derived from the recursive acronym, which is nothing but GNU's Not Unix. Okay, the full form of GNU, it's a recursive term: GNU's Not Unix. Unix was a very popular operating system in the mid-80s, so Richard Stallman designed GNU to be mostly compatible with Unix operating system so that it would be convenient for people to migrate to GNU. So the GNU project was intended to create a Unix-like operating system, but it should be freely available for all the public users and it should be an open-source operating system. So this led to the birth of Linux operating system, okay, with the help of Linux kernel and the GNU utilities. The importance of the GNU project: The free software movement started by Richard M. Stallman. Okay, you see the full form of GNU: GNU's Not Unix; it's a recursive term. Okay, and coming to the next question, the question is like what is Linux kernel? Okay, so this is an important question would be asked in different types of interviews, and most of the people will will get confused in answering this question: What is Linux kernel? Let me explain you in a simpler way: With over 13 million lines of code, the Linux kernel is one of the largest open-source projects in the world. But what is a kernel and what it is used for? A kernel is the lowest level of easily replaceable software that interfaces with the hardware in your computer. It is responsible for interfacing all of your applications that are running in user mode down to the physical hardware and allowing the processes which are known as the services to get information from each other using inter-process communication. Technically speaking, a kernel is nothing but the core of any operating system, and it is responsible for translating the user commands into equivalent language understood by the computer hardware. Okay, so kernel, it is nothing but the heart of any operating system; it's a core of any operating system which is responsible for translating the user commands into equal balanced language understood by the computer hardware. Okay, so if you can see this a pictorial representation on the left pane, okay, you see applications on top of kernel, you see applications and bottom of the kernel you see the hardware devices, the hardware devices like CPU, memory, and the devices which are attached to the computer. Okay, so in order to interact with the kernel, okay, applications you see on top of operating system you have applications, so in order to interact with an operating system applications you need to have some kind of language, right? So kernel would be acting as a mediator, mediator between applications and hardware devices; it just translates the user's language to the machine language and machine language to the user's language. It's a core; kernel is nothing but the core, the heart of any operating system. Okay, and coming to the next question: What is a shell and in shell what is exactly called as a bash shell? Okay, first let me explain you what is exactly a shell. A shell is a user program or its environment provided for user interaction. A shell is a common language interpreter that executes commands read from the standard input device which is called as a keyboard or from a file. Shell is not part of system kernel but use the system kernel to execute programs like creating files, creating directories, etc. Okay, so please remember shell is exactly called as a user interface. In order to interact with operating system, we need one kind of interface, right? That interface is called as a shell. Okay, shell is a command language interpreter. Most of the people often confuse between interpreter and a compiler. Okay, please remember interpreter is this type of a mechanism that executes commands which are read from the standard input device or from a file. Okay, so when you talk about shell, in shell we have different types in Linux and Unix operating system. We have bash shell, we have sh shell, we have korn shell, we have c shell, we have public domain shell. We have different types of shells used in Linux and Unix operating system, but bash is the default shell. Bash has been adopted as a default shell for most Linux systems. Okay, bash is a shell or a command language interpreter for the GNU operating systems. Once again, I'm using the term GNU, okay, GNU operating systems like Linux. In most distributions of Linux operating system, bash is incorporated as the default shell. Okay, the name is an acronym for the Bourne Again Shell. Bash stands for Bourne Again Shell. Okay, it is named after a person called Stephen Bourne. Okay, he's the author for Bourne Again Shell. Now why bash has been incorporated as the default shell? Because in bash we have many such features, features like command aliasing, command completion by using the tab keys and the command history also. Okay, like in order to execute the commands like no need to remember all the commands in Linux operating system. Okay, with lot of ease you can execute all these commands by the features of bash shell. Okay, command aliasing, command completion or file completion by using the tab keys and the command history. Okay, in order to execute like previous commands, no need to type the commands again and again; you can recall those commands by using the up and down arrow keys. Using that you can recall all those commands. Okay, if I show you practically one particular example, we have one command called clear in Linux. See this is the terminal, I'm using the command line interface, the terminal where we can gain access to Linux operating system. I'm just giving one particular example like why bash has been incorporated as a default shell. Okay, let's see what is exactly a command aliasing. I'm executing a command called clear, the command clear which is used to clear the screen. So every time you want to clear the screen you run the command clear. Once you press enter the screen will be cleared. Now instead for this lengthy program and what I'll do here I'll just make an alias, C is equal to clear. Now once you press enter for that particular command clear I've been alias to C. Now instead of running command clear I can run the alias command called C. Once you press enter the screen would be cleared. Like this for any such programs or applications if you want to do aliasing, this is possible with bash shell. Now these kind of features you cannot see in other shells. Okay, in other shells, other shells like c shell, korn shell, public domain shell, till you don't see all this types of features in other shells in Unix operating system. The default shell was sh shell. Okay, and what this person has done, Stephen Bourne has incorporated some new features. Okay, some features has been incorporated in sh shell and this has been renamed as the bash shell. Okay, bash is nothing but the Bourne Again Shell; it is named after an inventor called Stephen Bourne. Okay, in Linux if you want to see the types of shells which are supported you can check this configuration file, the configuration file called /etc/shells. Okay, this is a configuration file where you can see the number of shells supported by Linux or Unix operating system. If you want to see what is the default shell you can just recall the environment variable called SHELL. This will tell you what is the default shell used in the operating system. You see /bin/bash. Okay, so that is the importance of bash shell and you must have got an idea like what is shell and what is the importance of bash shell. Okay, and coming to the next question: What are daemons? So this would be a tricky question asked in interviews like what are daemons? If I put it in simpler format or daemon, according to my readings, daemons are services that provide several functions that may not be available under the base operating system. Its main task is to listen for service requests and at the same time to act on these requests. After the service is done, it is then disconnected and waits for further request. A daemon process has no controlling terminal; it cannot open the terminal, for example, /dev/tty. If you
do psyphen EF and look at the TTY field. All domains will have a question mark for the TTY terminal. Okay. I'll give one practical example here. If I run a command psyphen EF, you see for most of the Demons, usually in Linux and Linux operating system, a demon would end with d. Okay. You see, for example, let's take this particular demon here: K thread D. Okay. At the end, you see the character here D, which is nothing but a demon. Okay. As I told you, a demand process has no controlling terminal. If you check the TTY wife field here for this particular demon, you see a question mark. Okay. A demand process is essentially a program that runs in the background and is usually started when the operating system starts up. Okay. If you want me to take one more example, a typical demand process is a mail demon that runs in the background checking to see if we have received a new mail; when you do, it notifies you. Okay. So most domains tend to last a long time, be owned by root, or do something useful, but this is a very tricky question. Okay. What is the difference between a demon and a process? Okay. So please don't get confused between this: a demon is a service that provides several functions that may not be available under the base operating system. Okay. The main advantage, the main task, is to listen for service requests and at the same time it will act on this request. So that is about the demands. Okay. One good example: you can always run psyphen EF and you check all the demands in the TTY field; you see the question mark, that means we have not initiated this system; the operating system has initiated all this demands.
Okay. I am coming to the next question: what is a Lilo? A Lilo is a Linux loader; it's a Bootloader for the Linux operating system. It is used to load Linux into the memory and start the operating system. Uh, Lilo can be configured to boot other operating systems as well. Lilo is customizable, which means that if the default configuration is not correct, it can be changed. The main configuration file for Lilo would be /etc/lilo.conf. Okay. As I said, Lilo stands for Linux loader, which is just a bootstrap program. Lilo is the code snippet which loads PC bios into the main memory at the time of starting the computer system. Okay. And the main task it handles is locating the Linux kernel, identifying other supporting programs, and loading them into the memory and starting the kernel. Okay. So Lilo is not used nowadays; the default Bootloader for the Linux operating system is navis grub, which is called a grand unified bootloader. Okay. When you talk about the latest version of the Linux operating system, it has been replaced with grub2. Okay. Some more features have been added in grep, and they have released the new version that is called crop 2. Okay. So this is all about Lilo; it is just a Linux loader; it is called as a bootstrap program; it's a bootloader which loads the Linux operating system into the main memory.
Coming to the next question: what are the advantages of Linux being open source? Okay. So we have been discussed in the earlier questions also the advantages of Open Source operating system. Linux was one of the first open source Technologies, but many programmers have contributed and added software that's completely open source for any user. This means that you can download the source code and change it any way you like. Some developers have restrictions on how you can distribute the code; for instance, some developers allow you to change the code, but you cannot distribute it for money. One main advantage of Open Source Technologies such as Linux is a wide range of options available to users and the increased security. With Linux being open source, several distributions are available to the end user; for example, distributions such as Debian, Fedora, Ubuntu, and mint are just a few of the distributions available to end users, and these distributions are completely free to download. Security is the other main advantage; several white hat hackers have contributed to the overall security of Linux, and by making the source available to anyone, Security Experts can help identify any main security flaws in the operating system.
Coming to the next question like what are the basic components of the Linux operating system? Okay. This is a general question which would be asked in the interviews. The Linux operating system has primarily three components. What we have discussed already is the Kernel. A kernel is the core part of Linux which is responsible for all major activities of this operating system. It consists of various modules and it interacts directly with the underlying Hardware. The kernel provides a required abstraction to hide low-level Hardware details to system or application programs. Okay. We want to discuss what is Kernel. Next comes the second part: system library and system utility. Okay. System libraries are special functions or programs using which application programs or system utilities access kernel features. These libraries implement most of the functionalities of the operating system and do not require kernel modules code access rights; like when you compare with Windows, in Windows we have .dll, which is nothing but Dynamic link libraries; in Linux we have something; all the libraries which are there to read the file, write the file, all this coding part. Okay. Implementation of most of the functionalities will be there in the /usr/lib directory or /lib directory. Okay. And coming to the next question: how to check memory stats and CPU stats as a Linux admin? Okay. So in interviews, as I said earlier, the questions would be always in a tricky format; like you can expect questions in theoretical, or you can expect questions in Practical also; so you should be well Advanced; you should be well prepared for the interview in the Practical part also. So according to this question, being the Linux administrator, how you can check the memory stats and the CPU stats? So there are various commands in Linux here; one such command would be free. If you want to check memory statistics, you can run the command called free -M if you want to see the size in megabytes, or free -G if you want to see the size in gigabytes. And if you want to see the virtual memory statistics, you have a command called vmstat. The linuxbm start command is used to display statistics of a virtual memory. You can also see the kernel threads, the disks, system processes, your blocks, interrupts, CPU activity, and much more. Okay. Let me explain you this practically here. As I said, if you want to see the memory statistics, you can run the command called free -M. According to my system, I just got approximately some 10 GB of RAM, because by default I'm seeing in megabytes here: 9838 MB, out of which 651 is used, 8714 is free. Or if you want to see that in gigabytes, you can run the command free -G. If we want to see that in gigabytes, and when you talk about virtual memory statistics, you have a command called vmstat -a. Okay. So in this example, there are six columns here; the significance of the columns are explained okay in detail here. As you can see, the first is the processes, the memory, swap, IO, system, and CPU. Okay. You can just find out with the vmstat -a command. You can also check the dynamic activity of your system; like for example, you see I'm running the command here: vmstat 2 6. With this command, vmstat executes every two seconds and stops automatically after executing six intervals. See this practically; see the interval here. Okay. The interval is every two seconds and it will stop automatically after six intervals here. You can monitor like this virtual memory statistics. Okay. If you want to see along with the time format here, you run the command vmstat -t. Okay. 1, 5 for example. Once you press enter, you can see along with the time format. Okay. So like this we have many such options in vmstat; based on the requirement, based on the performance and monitoring, you can execute those. And coming to the CPU, you have a command called SAR, the system activity report. Okay. With SAR -U, you can display the CPU usage. See exactly, you can see the CPU is H. SAR -U displays this CPU usage for the current day that was collected until that point. Okay. If you want to see the real time CPU usage, it's the same like vmstat: SAR -u 1 3. Okay. Every one second, but three intervals here you can see. Okay. SAR is very, very, very important command; it is used by every administrator to monitor the day-to-day activity. Okay. In SAR also we have many such arguments here. If you want me to discuss more: SAR -R to see the memory free and used; I'll give 1, 3. You can also see with the SAR; you see the KB memory free, KB memory used, memory used in percentage; you can see all that with the SAR command also. Okay. This is all about the system monitoring and the performance. So coming to the slide, so these are some programs we have just given in the slide here. We have discussed about the free, vmstat to see the virtual memory statistics, and when you talk about CPU statistics, you can always use the program SAR, which is nothing but the system activity report. Okay. So I just gave you some basic examples, but if you dig more into this commands, you have many such options. Okay. And the frequently asked questions in interviews would be: how to reduce or shrink the size of an lvm partition? Okay. This is a frequently asked question in interviews. See the main advantage, if you just compare between a partition and a logical volume. Okay. The storage management can be created like whenever you want to create a partition. Partitions can be created by using a tool called fdisk, but if you create a partition using fdisk, it is the fixed partition size; later it is not possible for us to modify or resize or shrink the partition size; that flexibility is not available using fdisk partitioning tools. Now using an Advanced partitioning tool like lvm, which is called as a logical volume manager, we have a flexibility of either resizing a logical volume or reducing or shrinking the size of a logical volume. So let's see practically how you can do that in the Linux operating system. I'm talking about the Advanced partitioning tool called lvm, which is nothing but the logical volume manager. Okay. So, so I've already created a logical volume manager here. As you can see with the command df -h, you can see, for example, there is a logical volume here; the logical volume is zoom Linux, and the type of the file system is ext4; the size is 4.8 GB, and currently this logical volume is mounted on the mount Point called /lvm. So now I got a requirement of reducing this logical volume size. Okay. In other file systems, I am running out of space; I would like to reduce this logical volume and I want to increase the logical volume for the file systems. So let's see how exactly we can do that. Okay. So let me take one example here: there is a logical volume which is of 5 GB currently; I would like to reduce to 3 GB now. Okay. So that, that 2 GB I can accommodate to other file systems. The first thing is online shrinking is not possible; so first we need to unmount a logical volume; the command is umount and specify either the device name or the mount point. And then you can check whether you have any problem with this particular file system; you run the command e2fsck -f and specify the device name. Okay. So this is must ensured before you reduce the logical volume; you just need to scan your file system. Okay. E2fsck is the command to check the particular file system whether you have any problems or not. Now once you press enter, so exactly you should find this. Okay. So we have no problems with this particular file system. Now we can reduce by using the command resize2fs; specify the logical volume name; I would like to reduce from 5 GB to 3 GB; the current size is 5 GB; I would like to reduce to 3 GB, and the remaining 2 GB I would like to accommodate to other file systems. Enter. Now you see the logical volume size has been reduced. Okay. So now we can run the command lvreduce -l 3GB and specify your logical volume name. Now once you press enter, it will be reduced to 3 GB, enough from 5 GB to 3 GB. As you can see some information here, and then you can mount your logical volume to the mount Point called lvm. Now you can see the logical volume size; now it has been reduced from 5 GB to 3 GB. Okay. This is if you can reduce or you can shrink the size of a logical volume. Okay. So this flexibility is not available in fixed disk partitions; once you create a partition, that's it; now you don't have a flexibility of modifying the partition size or shrinking the partition size. So this is possible only by using the Advanced partitioning tool called lvm, which is nothing but the logical volume manager. So let's get back to the slides here. So we were discussing about like how to reduce or shrink the size of an lvm partition or a logical volume; it's a five-step process: first you have to unmount, run fsck, run the resize2fs to 3 GB or whatever required size you want, and then you run the command lvreduce to reduce the logical volume, then you can mount that particular file system.
Okay. The next question being: explain the functionality of a root user. Okay. In Computing Worlds, the super user is a special user account used for system administration. Depending on the operating system, the actual name of this account might be root, or if we talk about Windows, we call as an administrator or admin or supervisor. In unix-like computer operating system, root is the conventional name of the user who has all the rights or permissions to all the files and programs in all modes. Okay. The root user can do many things which an ordinary user cannot, such as changing the ownerships of files, binding to network ports numbered below 1024. So root is the default account every time Linux is installed. Okay. So there comes your question again: what is CLI and what is GUI? Okay. See, CLI is nothing but the command line interface; it is a console or text-based representation in which the user types the commands to operate the software or devices. The main advantage of CLI is multiple steps can be executed by specifying a single command, which is not possible in graphical mode. Okay. So a GUI, which is nothing but the graphical user interface, is a graphical representation in which the users can interact with software or devices through graphical icons. Okay. Simple definition: what is CLI and what is GUI? So how can you find out how much memory used in the Linux operating system? So again, uh, same question here; so how exactly you can find out? There are many such programs here; the command would be free. Okay. The free command is the most simple and easy to use command to check memory usage on the Linux operating system. So here is an example: free -n or free -G, or you can also cat the contents of /proc/meminfo; this will also give you the complete information about your memory. You can see here the total memory, okay, memory in free, and memory available, and you see the used and everything here. Okay. You can use this command also; you can just cat the contents of /proc/meminfo. Okay. Or better, the simple command would be free -G. Okay. What is swap space and what is the typical size for a swap partition under the Linux operating system? So this is also one of the most frequently asked questions in interviews. So what is a swap space? Swap space in Linux is used when the amount of physical RAM, physical memory, which is also called as RAM, okay, is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered as a replacement for more RAM. Okay. People often get confused between main memory and swap memory. Okay. If the CPU doesn't find free space in the physical RAM, so what CPU does is it just moves all inactive processes, all inactive pages, is from the main memory to these swap space, the swap space which is created onto the disk. Okay. To ensure it improves your system performance. Okay. So the preferred size for the swap partition is twice the amount of physical memory, okay, amount of physical memory available on the system. If this is not possible, then the minimum size should be the same as the amount of memory installed. Okay. Swap is used in normally desktops and laptops. Okay. Not in service, because in service we have equipped with more RAM; we have 32 GB, 64 GB, 128 GB; on those systems there is no need to create a swap space. Okay. Swap space only for low end machines where we don't have enough RAM available. Okay. So swap is just to improve the performance of the computer, nothing more. Okay. And how do you access partitions under Linux? What is the naming convention for devices in the Linux operating system? Okay. As you can see here, I'm running the program fdisk -l, and you see the first device; I got two drives connected to my Linux system; the first drivers /dev/sda and the second drivers /dev/sdb. See the naming conventions here; the conventions used for SKC drives; in case you have IDE hard drives, the first convention would be /dev/hda, hdb, something like that. If you got SKC drives or SAS drives, the naming conventions would be sda and sdb, and under this first hard drive here, if you see, you have the partition starting from sda1 to sda13. The first partition /dev/sda1 and the second partition sda2 like that. Okay. So these are the naming conventions used for your storage devices, and this itself exactly you can access partitions under the Linux operating system. Okay. You see here: IDE hard drive starts with h; in case you got SAS and SKC starts with s; sda, sdb, go on. How are hard drives and floppy drives referred in Linux? Just now I told you right: sda, sdb, and for floppy drives it would be fd0, fd1. Nowadays nobody accessing floppy drives, but it would be a question in interviews; how floppy drives would be referred in Linux: /dev/fd0, /dev/fd1, based on the number of connections you have in your system. In case of hard drives: hda, hdb, in case of IDE; if we have SKC or SAS drives: sda, sdb, something like that. Okay. These are the naming conventions used for floppy drives and hard drives. Similarly in Linux, how are names assigned to different serial ports? What we also called as communication ports? The communication ports are identified as /dev/ttyS0 to ttyS1. If you see practically here: ls -l /dev/ttyS*, you see here the communication ports. Okay. ttyS0, ttyS1. Okay. What we normally called as communication ports in Windows: communication 1, communication 2, like that. Okay. Coming to the next question asking about printer ports: how exactly you can identify the printer ports in Linux? Same thing: /dev/lp*, lp0, lp1, lp2; these are the names to use for printer ports. Okay. And the very basic question asked in interviews is: what are the kind of permissions available in Linux? Okay. What are the basic file permissions or the directory permissions available in Linux? So there are basically three levels of file and directory permissions in Linux: one is read; read like users only read the files or list the directory contents; and the second permission would be write; as the name suggests, users can write information to the file or create files inside the directories of a subdirectory; and the third permission would be execute; the users can run the file or look up a specific file within a directory. Okay. Besides these, you can have a combination of all these three levels of permissions and two of them or one of them; some combinations: read, write, execute, or read, write, or read, execute; the based on the requirement; as an administrator, I can change permissions. Okay. Basically there are three permissions; the three permissions what we see here, that is read, write, and execute. Okay. Coming to the next question like how do you change permissions under Linux? So there is a command called chmod. Chmod is a command to change permissions for files and directories, and the permissions can be changed in two formats: one is symbolic mode, another one would be absolute mode. Symbolic mode is nothing but using numbers, and absolute mode is nothing but like using characters. Okay. Like rwx or 755 or 644. With help of chmod you can change permissions. Okay. In order to change ownerships, you have a command like chown and chgrp; in order to change ownerships for files and directories. Okay. See here: the command chmod is to change permissions, and if you would like to change
The ownerships you can use the command ch on and chgrp. Okay. On the left pane, you can see some representation here: user, groups, others, and the permissions are read, write, and execute. Okay. Plus is to add permission; minus is to rework permission; and is equal to (overwrite) the existing permissions. Okay. The permissions can be changed in two different modes: symbolic mode and absolute mode. Symbolic using like characters or WX; absolute is using numbers. Okay. Combination of numbers. The read value is 4; right value is 2; execute value is 1. You can either use characters or you can use numbers. Okay. Symbolic mode or absolute mode? Yes. Chmod 700: what is seven? Read, write, execute applicable for owner; 0 means none permissions applicable for group; 0 again none; and this is applicable for others. Okay.
Coming to the next question: what are symbolic links? Very interesting question. Okay. Symbolic links. So in Linux, basically we have two types of links: one is symbolic link, which is also called as the soft link. So symbolic link you can always compare, if you take an example like in Windows, we have shortcuts. Okay. We always create desktop shortcuts. Now, instead of going to the lengthy part or navigating into directories into directories and directories, we can better create a shortcut on the desktop. Okay. For easy accessing and easy way of interacting with the operating system. Similarly, in Linux, it is called as symbolic links or soft links. So this is one special kind of file that points to another file, like I've compared with Windows, right? We have shortcuts, but please remember symbolic link does not contain the data. Okay. Symbolic language will not have the data; all the data we have in the target file, but not in the shortcut. Okay.
And what are the benefits of using symbolic link? It just allows instant access, easy of access of application or a program. Okay. Without having to navigate to multiple directories. Here, let me show you one practical example here. For example, I just want to see the configuration file of my LAN card (network interface card). The command would be: cat /etc/sysconfig/network-scripts/, and the configuration file would be starting like this: This is my configuration file for my LAN card enp0s3. See the path here: /etc/sysconfig/network-scripts/. Under this directory, we have a file called ifcfg-enp0s3. Now instead, what I'll do here, I'll create a symbolic link. See ln -s is the command. Ln stands for link. Now, what type of link I'm creating here? I'm creating a symbolic link. The path would be /etc/sysconfig/network-scripts/ifcfg-enp0s3. For this particular file, I am creating a shortcut under my root directory with the name called ifcfg. The link has been established. Now, instead of viewing the LAN information, instead of going to this lengthy path, better I can read from the shortcut. Now, which one is easy to access? Either this one or from the shortcut? I know it is from the shortcut. See the properties here: ls -l /ifcfg. Because this is exactly pointing to the original file, the target file. This is a link file, the symbolic link file, which is pointing to the target file. Now, instead of using this lengthy path here, I can better use my shortcut. Okay. So these are called symbolic links. Please remember symbolic link does not contain the data; all the data we have in the target file; we don't have anything over here. Okay.
What are the qualities of symbolic link? Now, both the files will have different inode numbers (we'll discuss about inodes). Both files, the source file and the target file, will have different inode numbers, will have different permissions, and different size also. Okay. Soft link will always have a different name; same content; both will be having same content, but different name. Okay. And remember soft links can be created only for files and directories. When you compare with hard link, hard link can be created only for files, but not for directories, but soft links can be created for files and directories, and soft link can cross the file systems also. You can establish a link between file systems, whereas hard link you cannot span across file systems. Okay. I hope you got me about symbolic links here. See the qualities of soft links what we have discussed. Okay. Both files will have different inode numbers, different permissions, different size, but the same content, but with a different name. Okay.
What are hard links? Now, in computing, a hard link is a directory entry that associates a name with a file on a file system. All directory-based file systems must have at least one hard link, giving the original file for each directory. Okay. The hard link is usually only used in the file system that allows more than one hard link for the same file. Okay. Hard links can be created only for files, but not for directories, and hard link you cannot span across partitions; it should be created within the file system. Okay. So these are some of the differences between the symbolic links and hard links here. Okay.
And coming to the next question, like what is the maximum length of a file name under Linux? This is also one of the important questions which is frequently asked in Linux interviews. Linux has the maximum file length of 255 characters. Okay. For most file systems like ext3, ext4, in those file systems you can have a file up to length of 255 characters. Okay. And the maximum path of 4096 characters. Okay. What we have discussed here: the maximum path you can have up to 4096 characters, and one particular file name you can have up to 255 characters. Okay.
Coming to the next question: which type of files are prefixed with a dot? So generally in Linux and Unix operating system, if any objects starts with dot or prefixed with dot, those are called hidden files. I'm at the super user home directory. If I want to see all the files here, you can run a command ls -a, including all the files. You see one particular file prefixed with the dot. So this is exactly a hidden file. This is a regular file which is not starting with dot, and this is a file which is prefixed with dot; this is the hidden file. Okay. And you see a directory also which is prefixed with dot, and you see the regular directory; public is the regular directory; .cache you see hidden directory. So these files can be sometimes called as the configuration files also, which holds some important data. If you see one example here: cat .bashrc, some aliases has been mentioned here for that particular environment, right? So mostly in Linux and Unix operating system, if any objects begins with dot, those are called hidden files and hidden directories.
Coming to the next question, like what is a virtual desktop? Virtual desktop: like whenever a user's desktop environment, when you talk about user's desktop environment like icons, wallpapers, Windows like folders, toolbars, okay, is stored in a remote server rather than on a local PC, then it's exactly called as a virtual desktop. Okay. The desktop virtualization software separates the physical machine from the software and presents an isolated operating system for users. Desktop virtualization tools include like Microsoft Virtual PC, VMware Workstation, and Parallels Desktop for Mac operating system. The main benefits of desktop virtualization it just includes like cost savings, because resources can be shared and allocated as a needed basis, and more efficient use of resources and energy; improved data integrity, because backup is centralized; and centralized administration. Okay. This is about the virtual desktop what we have discussed, the benefits of virtual desktops. Okay.
And what does the nameless empty directory represent? Empty directory: as you know, empty directory name serves as a nameless base for the Linux file system; serves as an attachment for other directories, files, drives, and devices. Okay. Empty directory. How can you create folders and files using the terminal? So in Linux operating system, if you want to create a directory, you can use the command mkdir, and to create files we have many such programs, for example like vi, cat command, or you can use graphical base editors like gedit and edit, pico, nano; you have many such programs to create files. Okay. You even have line editor, screen based editors, graphical base editors to create files in Linux and Unix operating system. Okay. But if we want to create a directory, you want to create a folder, use the command mkdir. Okay.
Next question would be: what are the different ways to view the contents of a file? Okay. To view the contents of a file, once again we have many such programs here; we have many such inbuilt Linux programs. You can either use graphical base editors or text-to-based editors, something like cat, vi, vim, gedit; you have pico, nano; you have many such programs. Okay.
What are environment variables? One important and interesting question: what are environment variables? Environment variables are global settings that control the behavior of a shell. Okay. Software packages installed in Linux and other processes; the path where the various softwares are installed will be stored as environment variables. Environment variables are used to pass information into processes that are spawned from the shell. Shell variables and variables that are contained exclusively within the shell in which they were set or defined while interacting with your server through a shell session. There are many pieces of information that your shell compiles to determine its behavior and access to resources. Some examples: if we want to see environment variables also, we have different types; we have system variables and we have user defined variables. In the case if we want to see the system variables, you can run the command env. Env is the command to display all the environment variables which are set by default with the operating system. Okay. One good example of an environment variable would be PATH. Okay. This is a system variable which has the information about the path of all your binaries, all your executables. Okay. If you take one more example, you see the environment variable called HOME. What is the super user home directory? Which is /root. Okay. These are some examples here: environment variables. Okay. System variables and user defined variables.
What is the functionality of a tab key in CLI? We were discussing about the features of bash shell, right? I was talking about command aliasing, command completion by using tab keys, and command history. Let me show you practically here. In the current working directory called /root, I have a file called Anaconda-case.cfg. Let's take one example here: there is a file called Anaconda-case.cfg. If I want to see the contents of this file, I can run a program called less or more or cat; you can do anything here, but I have to type the complete file name case.cfg. Rather, what I will do here, I'll simply type few letters; I'll use the Tab key here; automatically the file name would be completed. See: cat Anaconda-case.cfg. I am not typing the complete file name; I'm just using a few letters and then I'm using the Tab keys; enter to see the contents of this particular file. Similarly, there are many programs in Linux starts with the character C. I'll type c here; I'll use the Tab key; I can see a, with the c letter, I have 162 possibilities; that means I have 162 programs here. You see one such program called cat. If you want to see ca, use the Tab key here; with the ca, we have this many possibilities here. One good example is cat; one good example would be calendar. Okay. So these are the features of the bash shell. Okay. To complete a command or to complete a file name or the directory name. Okay.
What is redirection in Linux? This is also one of the frequently asked questions in the next year. Okay. So what is exactly redirection? So in Linux, redirection is used to pass the output of one operation as input to another operation in the same command. If you see one example here: as an administrator, I would like to find out like the users who logged in with my operating system, who currently using my operating system. I can run the command called w. With the w, I can have all this information. Okay. Since when my PC is up and running. Okay. For how long the PC is up and running, how many users are connected, and what is the load average of my computer, and you see the remaining information here: the users, the terminal they logged in from, which system they logged in, you see the login time, you see the idle, the jcpu, pcpu, and what exactly they're doing, what commands they're executing. Okay. I just want to send this report to one of my lead manager so that you can have this information here. w and I would like to save this particular information in one particular file. So this is exactly called as redirection. Okay. So redirection is nothing but which is used to pass the output of w command. Okay. Output of one operation will be the input for another operation. Okay. w will display all this information and this will pass to this particular file. See: cat log. All this information has been passed here. This is exactly called as a redirector, the greater than symbol. Okay. It is called as the redirector, the redirector symbol, the greater than symbol. Okay. They've given one more examples here: the cat files file1 file2. The contents of file1 file2 will be in file3. Okay. If file3 already exists, the file3 would be overwritten, and if you don't want to overwrite, if you want to append, you use double redirecting >>. Okay.
And what is grep? So this command is used for searching for a particular string, or you can also call this a word, searching for particular word in a text file. Okay. It also supports pattern based searching. The pattern based searching is done by including options and parameters in the command. Okay. One such example is the command is grep. I have one file here, the file called testing. In this particular file, I have some words and characters and numbers here. I would like to grab this word. The command is grep. The word you want to search for from the file called testing. See: grep. The string or the word you want to search for from the file called testing here. Okay. If we want to see with the line numbers, you can pass an argument called -n. At line number 17, I have the word called SD. If we want to see the count of the word, you can use an argument called -c. I just have only one word called SD in the file called testing. The count like this, we have many such arguments in grep. Okay. The pattern based searching is also possible in grep command. Okay.
And coming to the next question like how to terminate an ongoing process in Linux here. So in Linux, every process in Linux operating system is identified by a Unix process, which is called as a PID number. Okay. PID is nothing but the process ID. To terminate any process, we can use the command kill. You can either use the process name or you can use the process ID. Okay. You see the command kill. And if we want to terminate all process at once, you can use the command kill 0. Okay. It shouldn't be executed on production environment. kill 0 not recommended command, but only for information sake. And how to insert comments in command prompt? So this is a very basic question. Comments are inserted by using the hash symbol before the comment text. You see any such configuration file, for example, if you take /etc/grub.conf or /etc/profile, for example. Okay. You see the comments here. The comments can be provided by using the hash symbols. So these are the commented lines, and these are called uncommented lines. Okay.
So can you insert several commands in a single command line entry? If so, then how? It's a very good question. So this is also called as command chaining, like you can execute multiple commands one by one. Okay. By using a semicolon. Okay. If I give you one practical example here: the first thing is I would like to create a directory called directory1, and then I want to go to this directory; then under this directory I would like to create all these files. So this is called command chaining, one after the other; the commands would be executed. The first command is to create a directory, and the second command to execute a directory; under this directory I am creating all these files with the names called j, k, and l. Okay. This is exactly called the series of commands in a single entry. You go to this directory; see the files has been created here. Okay.
Write a command that will display all the txt files along with its permissions. Okay. Write a command that will display all the txt files; means we have to use the regular expressions and the common extension; we have to use this .txt. So I'll use the command ls -al *.txt. Okay. So in this particular directory I don't have anything here with *.txt, but this would be the command. The command is ls -al *.txt; it would display all the files including hidden files with the properties. Okay. See here: I got gita.txt, report.txt along with the properties here. Okay.
And the next question would you write a command that will look for files with .txt extension and has the occurrence of the string "adureka" in it? Okay. So we have to use combination of commands here, and that combination would be: I'll give an example here: find / -name "*.txt" -exec grep -i "adureka" {} \; . Find will list all the files with extension .txt, and grep is used to search for the string "adureka". This is how you can do it.
Same thing: how to find the status of a process? If we want to find the status of a process in Linux operating system, you can run the command called ps -aux. Okay. So you see the status here. The status of a process: if it is S, it is interruptible sleep state; that means it is waiting for an event to complete. Okay. If you find B somewhere here, D, that is uninterruptible sleep state; usually it is waiting for IO operation to complete. If it is R, that is a running state. If it is Z, that is nothing but the defunct process, which is also called as a zombie process. Okay. The process which is terminated but not reaped by its parent. If it is T, that is it is a stopped state, either by a job control signal or anything it can be. Okay. You can also see some code meaning here: you have the > symbol, and you have N, you have L. There, a > symbol is nothing but the process which is of high priority; you see here. Okay. Interruptible sleep state which is of high priority. If it is N here, somewhere you see N here, N is nothing but the low priority. If it is L, means the process where the pages has been logged into memory. Okay. Like this you can find out the process states by using the command ps -aux. The status of a process, you should look into this column, the status of a process. Okay.
And uh, what is the command to calculate the size of a folder? This is also one of the important question, and you can find out with the command du, which is nothing but the directory usage, and with the arguments -sh of the directory boot. You see: for the directory boot, it is occupied 135 MB. Okay. The command du is to find out the directory usage of a particular directory. Okay.
How to check the memory status of the system? The command is free -m or free -g. Okay. Same thing. And how to login as root in Linux from the terminal? I've already logged in as a root here. Let's say, for example, I have a user called edureka; this is the user logged in with the user edureka. I want to gain access to super user. Okay. I want to login as root. Simple, I can run the command sudo su -. I think I don't have sudo configured here. I'll simply run the command su -, and then I need to provide a super user password, then I can log in as root. See here: the prompt has been changed from the dollar sign to the hash prompt. Dollar sign is the prompt provided for all users, and the hash prompt is the prompt only provided for super user. Okay. The command su stands for substitute user. With the user edureka, I gained access to the operating system as root user. Okay. Like this you can do the command su. And the next question is: how can you run a Linux program in the background simultaneously when you start your Linux server?
Is a very, very important question, and this is frequently asked in interviews. The command would be nohup. Okay. The command is nohup. By using the nohub command, the process will run in the background. Okay. Any process which receives the nohup signal, okay, will be terminated when you log out, the program, okay, until then the process would be running in the background all the time. Okay. Please remember the command would be nohup. Okay. By default, it just places the process in the background, which demands tracks events on your computer, events on a Linux system. Okay. We have the daemons like syslogd. We have daemons like rsyslog. We have so many tracking events in Linux and Unix operating systems. Okay. The answer should be syslogd or rsyslog. Okay.
So what is partial backup? So partial backup is nothing but a type of backup where the complete operating system is not taken as a backup. Okay. Only certain files, certain folders have been backed up, but not the complete file system. That is exactly called as a partial backup. Okay. So when you select only some portion of a directory, okay, in a single partition, that is exactly called as a partial backup. Partial backup is not the complete backup; only certain files and folders have been backed up. Okay. So in Linux, we have many such backup programs like tar, cpio, dump, restore. Okay. Using this, you can take a backup, either complete file system backup or the selected files and folders based on the requirement.
And next question would be, I note, very, very important one. Inode is nothing but the contents of any file will be stored in data blocks, whereas information about that file will be stored in inode. So when we talk about data, data has two parts: the contents. The contents will be stored in the data blocks, and information about the file, what we called as metadata, that metadata will be there in the inode. Okay. So information, what type of information is stored in inode, like the file size, the permissions, the user ownership, the group ownership, the link counts, when exactly the file was last accessed or last modified, okay, all that you can see in inodes. So an inode number points to an inode table, which is a data structure that stores all that information: the size of the file, the device ID, the user ID, group ID, the file mode permissions, everything. Okay.
So which command is used to set a processor-intensive job to execute less CPU time? Very, very important question, and the answer would be the command nice and renice. Okay. These are the programs which are used to set a priority. Okay. You can change the process priority using nice and renice programs. So nice command will launch a process with an user-defined scheduling priority. Renice command will modify the scheduling priority of a running process. Okay. So the process scheduling priority ranges from -20 to 19. Keep this in mind; this is very important. Okay. The process scheduling priority ranges from -20 to 19. We also call this as a nice value. Okay. A nice value of -20 represents the highest priority, and the nice value of 19 represents the least priority of a process. Okay. If I show you one practical example here, let me just create one particular file: cat > redirecting_file1. I am creating a file. Okay. So in the backend, one process would be invoked because I'm creating a file here. Let me open another session here. Let me show you by just running the command -p FL and the process name called cat. Okay. See this particular process; by default, you see the nice value. The nice value is zero. Whenever you submit a process, by default, every process will have a nice value zero. Okay. See here. Similarly, if I submit a program with the less priority, for example, -10, okay, -10 cat > redirecting_file1. Here, now you see the nice value. Let me open the other, other this one. Let me recall the same command. Now you see the nice value for cat command. The nice value is 10. Okay. The nice value ranges from -20 to 19, -20 being the highest priority and 19 being the least priority. See, I launched a program with a nice value with the least value called 10. Okay. If we want to launch a program with the highest priority, I'll give -10. Okay. Do not get confused here; it is not --, it is -10. Now you see, now it is -10n. Okay. That means this command requires more CPU time. Okay. Similarly, unlike nice, if there is already a running process, that can be changed by using the command called renice. Okay. The command is renice -n the priority you want, okay, and you can give the process name or the process ID. You can do with the renice. Renice can be used if the program is already in use. Okay. Very important programs. So here the priority ranges from -20 to 19, -20 being the highest and 19 being the lowest priority.
And the last question is like, what are shadow passwords and how they are enabled? So shadow passwords are given for better system security. Every user's passwords will be stored in /etc/password file, and by implementing shadow passwords, all passwords will be stored in encrypted format in a new file called /etc/shadow. Okay. The passwords in the original file will then be replaced with x. In multi-user environments, it is very important to use shadow passwords. Okay. If I give one small example, like in Linux, we have two such database files here. One database file will have information about users, and other database file will have information about users' passwords, /etc/shadow. Okay. We have two such database files here which keeps information about users and users' passwords. Okay. So this is to improve the security. In earlier days, in earlier versions of Linux and Linux operating system, there used to be only one particular file which has everything: user and the user's file. See an example here: example calls password. Convert cat /etc/password used to have everything like this in one particular file: you have users, the user's passwords, and everything. But the problem is this particular file is readable by everyone. See here: /etc/password is owned by root. He got full permissions here; even others got read permissions. Okay. Which does not impose security on this particular file. Okay. So that is the reason there are two database files maintained: one is /etc/password and /etc/shadow files. Now you see the shadow file is only has read permissions for root; for others, you see we have none permissions. Okay. So this is stuff we have two database files here: /etc/password, which has information about users, and /etc/shadow, which has information about users' passwords. Okay. Not only passwords, we also have information about the password age also, for how long we can use this password, when password would be expired, all this information can be used in /etc/shadow file. Okay. So this is all about Linux interview. I hope the session is useful for everyone. I hope you have enjoyed listening to this video. Please be kind enough to like it, and you can comment any of your doubts and queries, and we will reply them at the earliest. Do look out for more videos in our playlist, and subscribe to any Eureka channel to learn more. Happy learning.