Basic Linux commands used by DevOps engineers in day-to-day activities

Rahul Desharaj
7 min readApr 25, 2024

--

This article will help in understanding most of the important and majorly used Linux commands that would be required for a DevOps Engineer.

System Info Commands :-

hostname - shows the name of the system host.

hostid - shows the host id of the system assigned by the OS

date - shows the current date and time in UTC format.

whoami - shows the currently logged-in username of the terminal.

uptime - shows the elapsed time duration since the machine logged in.

uname - unix name.

clear - clears the screen.

history - lists all the commands executed until now.

sudo - Super User Do.

echo $? - shows the exit status of the last executed command (0 - success, 1–127 - error/failure).

Directory Commands :-

pwd - To check where you are currently in the system we use pwd command.

cd To change the working directory from one location to another we use cd command

cd .. In Linux, we refer the parent directory with .. , So in case if we want to go to parent path then simply we can go with.

mkdir - make directory.

File Commands :-

touch This Command by default creates an empty file.

ls -l To check the file created.

vim: This is a text editor used in Linux. It stands for “Vi Improved”.

  • Normal mode: This is the default mode in which vim starts. In normal mode, you can use various commands to navigate and edit the text.
  • Insert mode: In insert mode, you can type text into the file. To enter insert mode, press the “i” key. To exit insert mode and return to normal mode, press the “Esc” key.
  • Command mode: In command mode, you can enter commands to perform various actions, such as saving the file or quitting vim. To enter command mode, press the “:” key.

cat - concatenates and displays the contents of files.

rm - remove command.

  • rm -f <fileName> - removes the file.
  • rm -rf <dirName> - force remove the files & folders of directory recursively (-f force).

cp - copy command.

cp <source> <destination> - copy the files and folders from source to destination.

mv - move or rename command.

mv <fileName> <newFileName> - renames the file to new name.

Network Commands :-

ping <hostName> - tests the reachability & responsiveness of the remote host.

ifconfig - display available network interfaces.

netstat -lntp- shows all tcp open ports (-a all, t-tcp, n-active, p protocol).

Nslookup: This stands for “Name server Lookup”. This is a tool for checking DNS hostname to Ip or Ip to Hostname. This is very helpful while troubleshooting.

Process Information Commands :-

  • ps - shows the currently running process.
  • ps -ef - shows all the processes of the system.
  • top- shows the real-time, dynamic view of the running processes of a system.
  • kill <pid> - gracefully terminates the process pid.
  • df -h(disk free) command will have an account of available disk space, used by file system.

Red Hat Package related Commands

Yum - Package Manager for RHEL Linux distributions.

  • yum - a newer version of the package manager with colorized output, progress bar and additional functions.

yum update -y - updates the package list.

yum list --installed - lists all the installed packages.

Service Management

sudo systemctl list-units -t service : To list all the services which are running in the Operating System

sudo systemctl start nginx : To start a service
syntax : sudo systemctl start <service name>

sudo systemctl status nginx : check the status of the service

sudo systemctl restart nginx : To restart a service

Other Commands :-

Grep: This command searches for a particular string/ word in a text file. This is similar to “Ctrl+F” but executed via a CLI.

Tail: This command prints the last N number of data of the given input. By default, it prints 10 lines.

We can specify the number of lines, that we want to display.

Head: This command prints the first N number of data of the given input. By default, it prints 10 lines.

We can specify the number of lines, that we want to display.

Free: This command displays the total amount of free space available along with the amount of memory used and swap memory in the system, and also the buffers used by the kernel.

ssh-keygen: This command is used to generate a public/private authentication key pair.

This process of authentication allows the user to connect remote server without providing a password.

CURL: Curl is a tool used for transferring data to or from a server, using various protocols, such as HTTP, HTTPS, FTP, and more. Basic example:

Syntax: curl <url>

tar: is used to create, maintain, modify, and extract files from archives, often called “tarballs”. It can bundle multiple files and directories into a single archive file, preserving permissions, timestamps, and directory structures.

cron and crontab: cron is a system daemon used to execute scheduled tasks at predefined times. crontab is the command-line interface to manage these scheduled tasks for individual users.
Example Usage:
Editing user’s crontab: crontab -e
Specifying a cron job to run every hour: 0 * * * * /path/to/script.sh

File Permission Octal Numbers

chmod <octalNumber> <fileName> - changes mode/permissions of the file.

Syntax : chmod 777 test1.txt

This blog page covers most of the majorly used Linux commands for DevOps Warriors and is a growing document. Commands will be added as the days go and when I find some interesting commands on the same.

Do follow me for more such content related to DevOps world.

Reach me 👨‍💻

--

--

Rahul Desharaj

Currently, I am working as a DevOps engineer. I am very passionate about learning new things and writing blogs. www.linkedin.com/in/rahul-desharaju-299b872a7