avatarKarthick Dk

Summary

The article provides a comprehensive overview of essential Linux commands tailored for DevOps professionals and system administrators.

Abstract

This article, targeted at DevOps engineers and sysadmins, meticulously outlines a range of Linux commands crucial for day-to-day operations. It covers commands related to file system management, process handling, service control, package management, system miscellany, advanced command execution, and text manipulation. The author emphasizes the importance of command proficiency for efficient task execution on Linux-based systems, which are prevalent in both cloud and on-premises environments. Practical examples are given for common tasks such as disk usage analysis, process monitoring, service status checks, and system updates. The article also touches on using utilities like at for scheduling tasks without relying on cron jobs, and Vim for text editing, demonstrating the versatility of the Linux command line interface.

Opinions

  • The author expresses enthusiasm by greeting readers in a friendly manner and exclaiming the usefulness of Linux commands for their profession.
  • Commands like tree -a and du -sh * | sort -h | tail -n 20 suggest a preference for a neat and informative file system overview.
  • There is a clear suggestion to use journalctl for log inspection and htop for real-time process monitoring, indicating a preference for these tools over traditional alternatives.
  • The recommendation to use free -h, sync; echo 3 > /proc/sys/vm/drop_caches, and similar commands demonstrates an interest in memory management and system cleanup.
  • The lsof and ss commands reflect the author's mindset of thorough network monitoring and security by ensuring a keen eye on open ports and files.
  • The inclusion of commands such as init 6 and the use of at for machine shutdown without cron, indicates the author values various methods for system power control.
  • Advance command chaining like && and || reflects an understanding that complex tasks require nuanced command structures.
  • The tutorial-style examples provided in Vim showcase the author's expertise in efficient text editing, with the implicit recommendation that Vim should be part of a power user's toolkit.
  • The author's sharing of personal links to platforms like LinkedIn, Medium, GitHub, Hashnode, and Dev.to conveys openness to knowledge sharing and professional networking within the DevOps community.

Linux Commands for DevOps & Sysadmins

Photo by Lewis Kang'ethe Ngugi on Unsplash

Hey Folks, ✌️

Welcome to another one! 😊

Here, we will deep dive into commands used by DevOps engineers for day-to-day activities. Command is most important when comes to Linux. Whether it's Cloud or On-premises it’s the end we mostly use Linux-based machines. We must know about the commands to run the tasks efficiently.

File System:

df -hT                               --> Check the files system, partiton status
fdisk -l                             --> Check the device all disk details
tree -a                              --> Check direcotory structure 
du  -sh * | sort -h | tail -n 20     --> Sort the file the Size in current directory
du -a /dir/ | sort -n -r | head -n 20 --> Sort the file the Size inlude directory
cat /etc/fstab                        --> Check the current disk mounts,Partition
mkdir -p /tmp/sub_folder1/sub_folder2 --> Create sub directories

Process:

ps -aux | grep -i nginx            --> Check the nginx process,PID,user,etc
ss -tunlp | grep -i nginx           --> Check the nginx servie is listening
journalctl -f -u nginx              --> Check the service logs for nginx  
lsof  /dev/null                     --> Check Open Files 
lsof -u karthick                    --> Check Open Files for user karthick
lsof -i TCP:80                      --> Check Open Files for port 80 used 
top                                 --> Task Manager ( Process,CPU,Memory )
htop                                --> Advanced Task Manager
free -h                             --> Check RAM info
lscpu                               --> check the CPU info
sync; echo > 3 /proc/sys/vm/drop_caches --> Remove the cache memory
pkill <process>                      --> Kill the process
kill -9 <PID>                        --> Kill the pid of the process
loginctl                             --> Login session details 
logintctl terminate-user <user_name> --> Terminate the user who logged

Service:

systemctl status nginx        --> Check 'nginx' status 
service nginx status          --> Check 'nginx' status 
sudo systemctl restart nginx  --> Restart 'nginx' status 
ss -tunlp | grep -i nginx     --> Check 'nginx' port

Package:

apt install <package>              --> Install the package
apt remvoe <package>               --> Remove the package
apt purge <package>                --> Remove the package also data,config files 
apt autoremove                     --> Remove unused packages
apt update                         --> Update the application packages
apt upgrade                        --> Upgrade the all packages
dpkg -i <package.deb>              --> Install the downloaded package.deb file

Misc:

sudo echo "shutdown -h now" | at -m 00:00 --> Shutdown the machine at 12 AM ( without using Crontab )
atq                        --> List jobs in at
atrm 2                     --> Delete the 2nd task
init 6                     --> Restart the machine
Text Search:

Advanced :

&&  --> Execute when first command sucess, then proceed next command 
Ex: apt update && upgrade
|| --> Execute when first command failed, then proceed next command 
Ex: apt update || apt autoremove
;  --> Execute the command continuosly
Ex: echo 1; echo 3;

Text:

grep karthick log.txt        -->  search "karthick"  in file 
grep -i karthick log.txt     --> search ( Karhick,KARTHICK) without case-sensitive 
grep "text1|value1" log.txt  --> use two values in log
awk '{print $2}' /file       --> Print 2nd column files in all lines 
awk 'NR==1 {print $2}' file    --> Print '1st' row and '2nd' Column only
grep -rin "host_name"        --> search 'host_name' for all files in current directory
diff log1.txt old_log.txt     --> Check diffrence of two files

VIM:

# Command Mode ( Press  " : " for goto command mode )
:$1,%s/abc/xyz/g    --> Replace "abc" vaules into "xyz"
/abc             --> search "abc"  in file
:x                --> Save and Quit
:se nu            --> Set line numbers
# Normal Mode:
yy                --> Copy the full line
p                 --> Paste the copied line
dd                --> Delete the line
# Insert Mode
i - Go to insert mode
R - Replace

Follow for more: ✌️

LinkedIn: linkedin.com/in/karthick-dkk

Medium: karthidkk123.medium.com

Github: github.com/karthick-dkk

Hashnode: karthick-dk.hashnode.dev

Dev.to: dev.to/karthickdkk

Linux
DevOps
Ubuntu
Command Line
Commands
Recommended from ReadMedium