"Mastering Linux Commands: Real-Life Use of Top Commands"

Hello! I am a passionate cloud enthusiast who is constantly seeking to expand my knowledge of emerging technologies and techniques. My primary focus revolves around AWS, Terraform, Azure, and Docker. Through my journey, I aim to explore and understand the intricacies of these platforms while embracing their potential to drive innovation and efficiency in cloud computing. As a result, I am excited to share my insights and experiences through informative blog posts, providing valuable resources to fellow cloud enthusiasts and those eager to learn more about these technologies. Join me on this exciting adventure as we navigate the ever-evolving world of cloud computing together!
Introduction
"Hello everyone! In this blog series, I'm excited to share with you the essential Linux commands that are invaluable for working with Linux machines in EC2 instances on AWS and virtual machines in Azure. Without further ado, let's dive right into the blog series and explore these top Linux commands that are fundamental for efficient cloud engineering."
Technology
EC2(AWS)
Virtual Machines (Azure)
Linux is unique in that it doesn't revolve around a singular version like it does on Windows or MacOS. Instead, the Linux landscape is composed of a variety of distributions, often referred to as "distros."
A "distro," short for distribution, is developed by a company or organization. It takes the Linux core and bundles it with supplementary software and tools.
In this blog, we will take an in-depth look at the most common commands used by cloud engineers. Let's dive into these commands that are fundamental for cloud engineering tasks.
sudo su
The command
sudo suis used to switch to the superuser (root) account in a Linux terminal. It combines two commands:sudo: Stands for "SuperUser Do" and is used to execute commands with elevated privileges, typically requiring the user to enter their password.su: Stands for "Switch User" and is used to change to a different user account. When used without specifying a username, it defaults to switching to the superuser account (root).
sudo su
sudo apt update
The command sudo apt update is used to update the package information of your system's package repositories on a Debian-based Linux distribution, such as Ubuntu.
sudo: This command is used to execute a command as the superuser or administrator, granting you elevated privileges.apt: Stands for "Advanced Package Tool." It is a package management utility used in Debian-based Linux distributions to install, upgrade, and manage software packages.update: This sub-command is used withaptto update the package information, also known as metadata, for the repositories. This command doesn't install or upgrade any software; it only updates the available packages.sudo yum update # For Amazon Linux or CentOS sudo apt-get update && sudo apt-get upgrade # For Ubuntu/Debian
Apache HTTP Server (httpd):
- The above command installs the httpd Server
sudo yum install httpd # For Amazon Linux or CentOS
sudo apt-get install httpd # For Ubuntu/Debian
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl stop httpd
Nginx,
- The above command installs the Nginx
sudo yum install nginx # For Amazon Linux or CentOS
sudo apt-get install nginx # For Ubuntu/Debian
sudo systemctl start ngnix
sudo systemctl enable nginx
sudo systemctl stop nginx
Docker
- The above command installs the docker
sudo yum install docker
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl stop docker
Shell scripts
Create a new file named
hello.shusing a text editor:nano hello.shAdd the following lines to the
hello.shfile:#!/bin/bash # This is a simple shell script that prints "Hello, World!" echo "Hello, World!"Save and exit the text editor (in nano, press
Ctrl+X, thenY, and finallyEnter).Give the script execute permissions:
chmod +x hello.shRun the script:
./hello.sh
Ping
The ping command is used to test network connectivity between your computer and a remote server or host.
Basic Ping:
ping google.com
uname -a
- This command displays comprehensive system information. The output typically includes details about the kernel version, machine hardware, operating system, architecture, and more.
uname-a
df -h
df -h: This command is used to display disk space usage in a human-readable format. The-hflag stands for "human-readable," and it presents sizes in a more readable format (e.g., KB, MB, GB).
df -h
free -m
free -m: This command shows memory usage statistics in megabytes. It displays information about total memory, used memory, free memory, and memory used by buffers and caches.
free -m
nano
Open or create the "red" file using the
nanotext editor:nano redThe
nanoeditor interface will open, allowing you to write or edit the content of the "red" file.After you've finished writing or editing the content, press
Ctrl+Oto save the changes. It will ask you to confirm the filename, pressEnterto confirm.Press
Ctrl+Xto exit thenanoeditor.
date
- Display or set the system date and time.
date
sudo date +%Y%m%d -s "20230825"
sudo date +%T -s "16:30:00"
ls
- List files and directories in the current directory.
ls
If you need to add a folder name or path, it will print that folder's contents:
ls -al /bin

mkdir
- You can create folders using the
mkdirCommand:
mkdir red
- You can create multiple folders with one command:
mkdir red blue
- You can also create multiple nested folders by adding -p :
mkdir -p red/doll
cd
Once you have a folder, you can also move into that folder by using cd commands cd means change directory:
cd red
Now you are in the red folder.
- To exit from the current directory by using the above command:
cd ..
pwd
- Print the current working directory.
pwd
rmdir
- If you want to delete the folder you use the following command to delete a folder using
rmdir
mkdir red
rmdir red
- To delete folders with files in them, we'll use
rmcommand which deletes files and folders, using the-rfoptions:
rm -rf red doll
mv
- Once you create a file, you can move it around using the
mvcommand:
touch red #will create a file
mv red blue #it will rename it from red to blue
- If you have a file and you are required to move that file into a new directory you can use the above command:
touch red
touch blue
mkdir colours
mv red blue colours
Now if you use ls command and cd colours you can see that your files are moved into new directory
cp
- You can copy a file using the
cpcommand:
touch red
cp red new_red
- To copy folders you need to add the
-roption to copy the whole folder contents
mkdir colours
cp -r clours red
touch
- You can create an empty file using the
touchcommand:
touch red
gzip
- You can compress a file using the gzip compression using
gzipcommand
gzip red
User
- The above command creates a user:
sudo useradd -m -g red colour
-m: This creates the user's home directory if it doesn't exist.-g red: This assigns the user to the "red" group.
group
- The above command creates a group:
sudo groupadd red
chown
Every file/directory in an operating system Linux has an owner. The owner of a file can do anything with it
sudo chown code script.sh#chown <owner> <file>
echo test >> script.sh
chmod
Every file in Linux has three permissions: read, write, execute
astands for alustands for usergstands for groupostands for others
chmod a+r filename #everyone can read now
chmod a+rw filename #everyone can read and write
chmod o-rwx filename #others
0no permissions1can execute2can write3can write, execute4can read5can read, execute6can read, write7can read, write and execute
We use them in three pairs, to set the permissions of all the 3 groups altogether
chmod 777 filename
chmod 755 file name
chmod 644 filename
ps
- You can use
pscommands to inspect all the processes in your computer
ps
wget
wgetis a command-line utility for downloading files from the internet. You can use it to fetch files from web servers.
wget https://example.com/file.txt
Conclusion:
Guys, we are end of our blog series Thanks a lot for reading the blog and I hope you have learned some things about Linux and its Capabilities. Please share your experience and feedback in the comment


