Google Cloud Platform (GCP) - 20 basic linux commands for everyone (2021) | Hands-on demo on google cloud (gcp) linux vm





 If you are opening a very, very big file, an application log file, and the error has happened only in the last few minutes, then it's better to run a tail command.


Let me share an interesting story with you. Eight years back when I was going for my first onsite Engagement in 2013, I was put on a role of a bi administrator and I was asked to manage a cluster which was all deployed on Linux. I had zero idea about how Linux works. I was so frightened just by seeing that black screen because I was all working on Windows. But trust me guys, when I started working on Linux and by no means I can say today after working so much on Linux that I know a lot.


But whatever experience I have gained so far, I'm pretty sure that once you start understanding how Linux works and how efficient it is, you just fall in love with this platform. So I'm pretty sure that now with you going on to your cloud journey in GCP or in any other platform, working on Kubernetes everywhere, you would find Linux expertise as a mandatory skill set. So I'm pretty sure these 20 commands would help you kickstart your journey. What we'll do today, we'll go to my laptop and we'll create a VM instance on GCP and then we'll take control of that VM instance, log into a Linux fell and try to run whichever command we want to.


So the first command is DF. Now don't take it in any sequence. It just came to my mind and I have written it down. So don't take it in this sequence or any priority as such. But the first command which I have written is D, which is disk free. It is like going to your Windows laptop and going to my computer seeing what all disks you have, how much space you have in that. Similarly, when you run DF, you see all the Mount points on Linux, what kind of space utilization it has.


So this is def command. Top is like going to your Windows task manager and seeing all the processes, whichever is running similarly to command helps you do that on Linux. Cd is changed directory. When you want to go from one directory to another, you use CD mkdir very self expiatory is making a new directory. Touch touch is used when you want to create an empty file, you can run the Touch command and create it. M is removed whenever you want to remove a file or remove a directory, then you use RM command you need to use or switch if you want to do it, recursively for entire directory.


So all these commands will have various switches. And for all those switches you need to go and understand it through the Help manual which you get in Linux. I think I should tell you that command first. And that command is Man command which stands for manual. So if you use and you add any other command in front of it, it will give you all the usage, all the switches which you can use for that command. So coming back to MB MB move. If you want to move file from one place to end that you use M command.


Cat cat is about opening a file and reading the content of that file. So if you have a file you want to read it, you will issue a Cat command for that how it changes the ownership of a file. So suppose a file is being owned by me. If that has to be that ownership might need to be changed to a person in my team, then Chon can be used for that is very, very common. Listing all the files in a directory you want to issue a list command graph will help you find specific contents in a file.


So suppose if you have a blog file, you are trying to troubleshoot an issue and you want to identify specific error messages. If you can get those in that particular file so you can run GRAP command for that, do you again? Disk usage. So it is also a mechanism to see how much disk space and disk usage you have to. Suppose if you have a directory and you have multiple sub directories, if you issue a command, it will tell you that which particular subdirectory is utilizing how much space?


Very useful command Tail command. When you run it on a file, as you know tail, it denotes the bottom, so it tells you all the data from the bottom. So if you say I run a command tail and the file name, it will show you all the last ten lines of that particular file. Kill very important guys. Very important. As an administrator, you would use it quite a lot for killing a process. Suppose some thread is in hung state. How you would kill it like you go into Task manager in Windows and kill the thread.


Similarly, you kill a process using this command. Pseudo is super user. So whenever you want to run a command with super user or root privileges, you run it through pseudo. Ch mode is change mode. This is suppose if there is a file and that file has to be accessed only in a specific manner, then there is the CS mode. There are different codes which you give in front of this to tell Linux. That OK. I want this file to be used in a certain way only.


So it could be that it cannot be executed. It could only be read. No one could write to that particular file. All those kind of access you can manage from Chmod. Who am I? If you want to log in, you want to understand with which users you have logged in, then you will use Run. Who am I? Star is again a very important command to run when you want to zip or unzip files on Linux. And if again a very good command for programmer. Suppose if you have two different files and two different codes, you want to compare the differences between the two.


You can run the Dev command with the files with both the files, and it will display you the differences. One command which I think I have missed is PWD, which is present working directory. So when you when you log in and you want to know in which directory you are presently in, you can issue PWD. So now these are some basic commands. I think when you are working on Linux, you will use most of these commands day in and day out. So let me go to my screen and try to show you whatever commands I can with GCP Linux VM instance.


So.


Friends, we are now on my Google Cloud console. So we will first create a Linux VM instance. So we'll go to compute. So as you can see, I've already created a VM instance, but for our understanding, let's create a new one. So I have clicked on Create instance. Okay, so I'll just name it Basic Linux. And by default we have DB flavor of Linux ten. And I think we should suffice our requirement for this video. So I'll just go ahead and I'll create with all the default settings.


So now it is spinning up a new Linux instance and we should see a green tick box as soon as it is ready to be used. So I will now click on SSH to take the control on the VM instance. So we enter into the shell of this Linux VM and then we'll run our commands. All right.


So you can see that we have now logged into this Linux instance. So I will not be able to run all the commands in one particular sequence. I'll just randomly run through whatever comes to my mind and you can correlate it with the first half of the video. So right now I'm logged in. So first thing which I would want to do is understand who M. And one thing is, all these commands are case sensitive.


So.


This tells me the user with which I am logged in. Now I will also see where I am right now. So I will see the present working directory. So it is my home. So whenever you log in, you log into your home. Now I would want to see what all Mount Points I have. So I will run D H gives us it in human readable form. So this is how our Mount Points are looking, and it shows how much available space we have, how much is being used.


So, yes, this is I can also now run a top, and I could see what all processes are running.


So as you can see.


All these process and process IDs are running an under which user. So suppose if I want to.