Saiyam Pathak avatar
By Saiyam Pathak
Director of Technical Evangelism

Description

With Civo Academy, learn about the various linux commands needed as a prerequisite for learning Kubernetes.


Transcription

Introduction

Hello, everyone, and welcome to this lecture on Linux commands. Now, before diving into the concepts of Docker and Kubernetes, it is very important that we know some basic Linux commands that we will be using throughout the course.

Basic linux commands

The first command is the ls command that gives the list of information about the files and the directories in the current directory; ls -ltr gives a little more information about that. Now, let's create a directory using mkdir. Let's switch to that directory using the cd command. Next, let's create a file in the directory using the touch command. Now, you can see the file is created. And if you want to add the contents to the file, use the vi command. Press I to get in the INSERT mode. Press Escape to save the file, followed by :wq!, and Enter. To view the contents of the file, use the cat command. And you can see the output is printed on the console, clear to clear the screen, cp command to copy the file and double dot to the previous directory. Let's switch to the previous directory by using the command cd .. then apply ls, and we can see civotest is already there.

Next, let's go back into the civo directory. Do ls -ltrM. And now, you can see there is some redirect formation over here. Now, in order to change the permission of a file, there's a command called chmod 400 which represents the read-only mode. Now, apply the command, ls -ltr and you can see that it has changed to read-only mode.

How to make a binary file executable

Now, there are other modes that we will not discuss in detail. But the two most important ones are the read-only one, which is 400, and the executable one. Now, for the executable one, first, let's have the executable downloaded. We use the curl command to transfer the data from and to a server. So the curl command to get the kubectl binary downloaded to our system is curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl. Now, you can see that kubectl is downloaded, but it's not executable. We'll now run the command, chmod +x, to make it executable. And we can see it is in the executable format now. Now we can run it with ./ and it's running.

Extraction of compressed files

We also have a TAR file over here. Now, in order to extract this, we use a command called tar, which is an archive utility, with a few of the options. With this command, you can see the directory has been extracted.

How to view environment variables

For viewing the environment variables, there's a command called env. You can see all the environment variables that are already set. To set a new environment variable, you can use demo=training. And we have to write an export keyword for that. Hence, the full command will be export demo=training And now, let's do env again, and we can see demo=training has appeared in the environment variables.

To use that, we can directly use the command echo $demo. Now, du is a disk utility command, which gives you information about the disk occupied by the files and the directories, but it's not in a human-readable format. So we can use the command du -h. After that, we will get a proper human-readable format. And if you want a complete summary, we can use the command du -sh. So it gives us a summary.

Network Connectivity commands

Now ping is a network connectivity tool. We'll use the command ping www.google.com. You will see that it has started pinging the Google servers. If you only want to send one packet, use the command ping -c 1 www.google.com. If you're going to see the statistics and monitor the network connections, there's a command called netstat. You can see all the connections. If you only want to see TCP connections, then use the command netstat -at and use netstat -au for the UDP ones.

Now, the lookup command is the name server lookup which gives the DNS records, the area code, etc. For this, we will use the command nslookup www.google.com.

Process status commands

Ps is the process status command, and we list by ps -ef for all the process ID, etc. We do this because we can kill anything with the process ID if we want to kill anything.

Tail commands

I have a demo file, which has some contents in it. Now, we will do a tail on that. If we use the command tail demo, it prints out the last ten lines of that particular file. So if we want to print only a few lines, we can use the command tail -n 5 demo.

Ctl commands

Now, the systemctl command is used to control services such as start, stop, look at the status, etc., of a service. So I have already downloaded Docker, but let's start using systemctl. First, let's look at the status using the command systemctl status docker. It's inactive now. So, we will use the command systemctl start docker to start it. Then, let's see the status again. And we can see it is running. So in this way, we can play with the status of the services.

Next is journalctl. We use it basically to view the systemd logs. By using the command Journalctl, you can see the systemd logs. In addition, it's sometimes helpful to see the kubelet logs for debugging purposes.

The top command is used to see the memory and the CPU utilization of the system. And there are other commands like htop, which gives a much clearer view, but it provides the same information in a clearer picture.

So that's it for this lecture. See you in the next one.

Don't stop now, check out your next lesson