π Mastering Linux for DevOps: A Beginner's Guide Using Git Bash & Linux Terminal π§π»
16.03.2025
0 views
Introduction
When I began my DevOps journey, mastering Linux was one of the first essential steps. Since most DevOps tools and workflows are built around Linux environments, understanding its commands and operations is crucial. However, working on a Windows machine without Ubuntu or another Linux distribution meant finding an alternative. Git Bash provided a practical solution by offering a Linux-like terminal experience. In this blog, Iβll walk through essential Linux commands, demonstrating how they function in Git Bash and how they compare to a real Linux system.
By the end of this guide, you'll be comfortable with basic Linux commands, file operations, and process management. Let's dive in! π
1οΈβ£ Setting Up Your Environment
Using Git Bash on Windows
If you're on Windows like me, you can use Git Bash, which is installed along with Git. It provides a lightweight Unix-like terminal where most Linux commands work.
To open Git Bash:
Install Git for Windows (if not installed already).
Open Git Bash from the Start menu.
Using Linux Terminal
If you are on Ubuntu/Linux, simply open the Terminal using:
Ctrl + Alt + T
1οΈβ£ Navigating the File System
π₯ Linux Commands:
pwd β Shows the current directory.
ls β Lists files and directories.
cd β Changes the current directory.
mkdir β Creates a new directory.
rmdir β Removes an empty directory.
rm -r β Removes a directory and its contents.
tree β Displays the directory structure in a tree format (Not available by default in Git Bash).
find -name β Searches for a file in a directory.
π₯ Git Bash Equivalent:
β Works the same way as in Linux!
π Hands-on Practice:
Open Git Bash or a Linux terminal.
Type mkdir my_project to create a new folder.
Use cd my_project to enter the directory.
Run pwd to confirm your location.
Try ls to see if any files exist.
2οΈβ£ Working with Files
π₯ Linux Commands:
touch β Creates an empty file.
cat β Displays file content.
echo "Hello" > file.txt β Writes to a file.
vi β Opens a file in the vi editor for editing.
mv β Moves or renames a file.
cp β Copies a file.
rm β Deletes a file.
head β Displays the first 10 lines of a file.
tail β Displays the last 10 lines of a file.
grep "" β Searches for text in a file.
π₯ Git Bash Equivalent:
β All these commands work exactly the same way!
π Hands-on Practice:
Create a file: touch test.txt
Write content: echo "DevOps is amazing!" > test.txt
View content: cat test.txt
Copy file: cp test.txt backup.txt
Rename file: mv backup.txt notes.txt
Delete file: rm test.txt
3οΈβ£ Managing Processes
π₯ Linux Commands:
ps β Lists running processes.
top β Displays real-time CPU/memory usage.
kill β Terminates a process.
htop β Interactive process viewer (not available by default in Git Bash).
jobs β Lists background processes.
bg β Resumes a process in the background.
fg β Brings a background process to the foreground.
pkill β Kills a process by name.
π₯ Git Bash Equivalent:
β οΈ ps works, but top and htop are not available in Git Bash.
π Hands-on Practice:
Run ps to see active processes.
Find a process ID (PID).
Terminate it using kill .
4οΈβ£ File Permissions & Ownership
π₯ Linux Commands:
ls -l β Shows file permissions.
chmod 777 β Changes file permissions.
chown user:group β Changes ownership.
umask β Sets default permissions for new files.
stat β Displays detailed file information.
π₯ Git Bash Equivalent:
β οΈ ls -l works, but chmod and chown are limited due to Windows file system restrictions.
π Hands-on Practice:
Run ls -l to check file permissions.
Try chmod +x script.sh to make a script executable.
5οΈβ£ Networking Commands
π₯ Linux Commands:
ping β Checks network connectivity.
curl β Fetches web data.
wget β Downloads files from the internet.
netstat -tulnp β Shows network connections.
traceroute β Shows packet route to a host.
dig β Fetches DNS records.
π₯ Git Bash Equivalent:
β ping and curl work. β netstat may have limitations.
6οΈβ£ Advanced Linux Commands
π₯ System & Performance Monitoring:
uptime β Shows system uptime.
df -h β Displays disk usage.
du -sh β Shows directory size.
free -m β Displays memory usage.
vmstat β System performance monitoring.
π₯ User Management:
whoami β Shows the current user.
id β Displays user and group information.
adduser β Adds a new user.
passwd β Changes user password.
usermod -aG sudo β Adds a user to the sudo group.
π₯ Process & Job Scheduling:
nice -n β Runs a command with a priority.
renice -p β Changes the priority of a running process.
nohup & β Runs a command in the background.
alias ll="ls -la" β Creates a shortcut command.
history β Shows command history.
crontab -e β Opens scheduled jobs for automation.
π₯ Package Management:
apt-get install (Ubuntu/Debian) β Installs a package.
yum install (RHEL/CentOS) β Installs a package.
dnf install (Fedora) β Installs a package.
brew install (MacOS) β Installs a package.
Wrapping Up
Mastering Linux commands is a crucial step for any DevOps engineer. While Git Bash provides a solid foundation for practicing Linux commands on Windows, a full Linux environment offers deeper capabilities. Understanding file management, process control, permissions, and networking commands will empower you to work efficiently in DevOps workflows.