How to use Linux commands
Civo Academy - How to Use Linux Commands
Welcome to Civo Academy on Linux commands, a vital foundation for mastering Kubernetes. This lesson will not only familiarize you with the basics of Linux commands but also provide you with practical examples and use cases that will prove invaluable throughout your Kubernetes journey.
Essential Linux Commands
The first command to know is the
ls command, which lists information about the files and directories in your current directory. For more detailed information, use
To create a directory, use the
kdir command. You can switch to this new directory using the
cd command. To create a file in the directory, use the
To add content to the file, use the
vi command. Press
I to enter INSERT mode, then press Escape to save the file, followed by
:wq!, and hit Enter. To view the file's contents, use the
cat command. The output will be printed on the console.
Changing File Permissions
Making a Binary File Executable
Binary files are a type of file that can be executed or run as a program in your computer. They are essential in Linux as they contain compiled code or scripts that can be run directly by the computer's operating system.
We can apply several modes to a file in Linux, but the two most important ones are the read-only mode (400) and the executable mode.
First, we need to have the executable downloaded for the executable mode. We use the
curl command to transfer the data from and to a server. 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
After downloading, you can see that
kubectl is downloaded, but it's not executable. We'll run the command
chmod +x to make it executable.
chmod +x kubectl
Now, you can see it is in the executable format. We can run it with
./ and it's running.
Extracting Compressed Files
To extract a compressed file, we use a command called
tar, which is an archive utility, along with a few options. The
tar command allows you to extract the contents of a compressed file, revealing the original files and directories.
For instance, if we have a TAR file, we can extract it using the
tar command as follows:
tar -xvf file.tar
Viewing and Setting Environment Variables in Linux
In Linux, environment variables are dynamic-named values that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs.
To view all the environment variables that are already set, you can use the
env command. This command will list all the environment variables in your current shell session.
If you want to set a new environment variable, you can use the
export command followed by the variable name and its value. For example, to set a new environment variable named
demo with the value
training, you would use the following command:
After setting the new environment variable, you can verify that it has been added by running the `env` command again. You should see `demo=training` appear in the list of environment variables.
To use the value stored in an environment variable, you can use the `echo` command followed by the variable name, preceded by a dollar sign. For example, to print the value of the `demo` variable, you would use the following command:
du command is a disk utility command that provides information about the disk space used by files and directories. By default, the sizes are reported in blocks, which might not be easy to read. To get the a human-readable format, you can use the
If you want a summary of the total size of a directory, you can use the
Network Connectivity Commands
Network connectivity is a crucial Linux aspect. Various commands allow users to test and troubleshoot network connections, ensuring smooth and efficient communication between devices.
ping command is a fundamental network connectivity tool. By using
ping www.google.com, you can test the connection to Google's servers. If you want to send only one packet, you can use
ping -c 1 www.google.com.
To monitor network connections and view statistics, the
netstat command comes into play. Running
netstat will display all active network connections. If you want to filter the results to only show TCP connections, you can use
netstat -at. For UDP connections, use
nslookup command, short for name server lookup, provides DNS records, including the area code and more. To use this command, you can type
nslookup www.google.com. This command will return the Domain Name System (DNS) records for www.google.com, providing valuable information about the domain.
Process status commands
ps command, short for process status, is a powerful tool in Linux that provides information about the currently running processes, including their process identification numbers (PIDs). You can use
ps -ef to display detailed information about all the running processes.
tail command in Linux is used to print the last part of files. For instance, if you have a file named
demo with some content, you can use
tail demo to print out the last ten lines of that file.
Linux Ctl Commands
Ctl commands in Linux are powerful tools that allow you to control services, view system logs, and monitor system utilization. These commands include
systemctl command is used to control the systemd system and service manager. It allows you to start, stop, and view the status of services. For instance, if you have Docker installed, you can check its status using
systemctl status docker. If it's inactive, you can start it using
systemctl start docker. Running the status command again will show that Docker is now running.
journalctl is another ctl command that is used to view the systemd logs. Running
journalctl will display the systemd logs, which can be helpful for debugging purposes. For instance, viewing the kubelet logs can provide valuable insights when troubleshooting Kubernetes.
top command monitors the system's CPU and memory utilization. It provides a dynamic real-time view of the running system. However, the
htop command provides a more user-friendly and visually appealing interface while displaying the same information.
These commands provide valuable insights into your system's status and allow for efficient problem-solving when issues arise.
Kubectl commands - a comprehensive guide
Get more productive with kubectl, the Kubernetes command-line tool. This guide covers setting up autocompletion, managing contexts and configuration, working with namespaces, troubleshooting pods, and more.
Maximizing productivity with Kubernetes: the benefits of using K9s
An in-depth guide to some K9s features including K9s monitoring tools that help you increase your productivity with managing your Kubernetes clusters.
Webkubectl - Running Kubectl commands from your web browser
Discover Webkubectl, a browser-based tool for managing Kubernetes clusters on Civo Kubernetes. Access pre-installed tools, isolate sessions, and manage multiple clusters.