Skip to main content

Command Palette

Search for a command to run...

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

Published
7 min read
"Mastering Linux Commands: Real-Life Use of Top Commands"
T

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 su is used to switch to the superuser (root) account in a Linux terminal. It combines two commands:

    1. sudo: Stands for "SuperUser Do" and is used to execute commands with elevated privileges, typically requiring the user to enter their password.

    2. 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 with apt to 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

  1. Create a new file named hello.sh using a text editor:

      nano hello.sh
    
  2. Add the following lines to the hello.sh file:

     #!/bin/bash
     # This is a simple shell script that prints "Hello, World!"
    
     echo "Hello, World!"
    
  3. Save and exit the text editor (in nano, press Ctrl + X, then Y, and finally Enter).

  4. Give the script execute permissions:

     chmod +x hello.sh
    
  5. Run 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 -h flag 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 nano text editor:

      nano red
    
  • The nano editor 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 + O to save the changes. It will ask you to confirm the filename, press Enter to confirm.

  • Press Ctrl + X to exit the nano editor.

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 mkdir Command:
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 rm command which deletes files and folders, using the -rf options:
rm -rf red doll

mv

  • Once you create a file, you can move it around using the mv command:
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 cp command:
touch red
cp red new_red
  • To copy folders you need to add the -r option to copy the whole folder contents
mkdir colours
cp -r clours red

touch

  • You can create an empty file using the touch command:
touch red

gzip

  • You can compress a file using the gzip compression using gzip command
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

  • a stands for al

  • u stands for user

  • g stands for group

  • o stands for others

chmod a+r filename #everyone can read now
chmod a+rw filename #everyone can read and write
chmod o-rwx filename #others
  • 0 no permissions

  • 1 can execute

  • 2 can write

  • 3 can write, execute

  • 4 can read

  • 5 can read, execute

  • 6 can read, write

  • 7 can 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 ps commands to inspect all the processes in your computer
ps

wget

  • wget is 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