Skip to main content

Basic Linux Commands for DevOps

 Basic Linux Commands: The Essential Guide for Beginners

Master the fundamental commands that form the foundation of all Linux system administration and DevOps work.

📅 Published: Feb 2026
⏱️ Estimated Reading Time: 18 minutes
🏷️ Tags: Linux Commands, CLI Basics, Terminal, Beginners Guide, Command Line


📖 Introduction: Why Learn Linux Commands?

Before we dive into specific commands, let's understand why learning Linux commands is so important. Imagine you're given keys to a building, but you only know how to open the front door. Linux commands are like having the master keychain - you can open every door, control every system, and fix any problem.

In the world of technology, especially in DevOps and system administration, 90% of servers run Linux. These servers don't have graphical interfaces like your Windows or Mac computer. They're managed entirely through commands typed into a terminal. Whether you're deploying a website, troubleshooting a database, or automating backups, you'll be using these basic Linux commands.

Think of it this way: If Linux were a car, commands would be the steering wheel, pedals, and gear shift. You need to learn them to drive effectively. The good news? Once you learn about 20 basic commands, you can do 80% of all common tasks!


🗺️ Navigation Commands: Finding Your Way Around

pwd: Where Am I?

The pwd command stands for Print Working Directory. It's like looking at your GPS location or checking the address of the building you're in. Whenever you feel lost in the Linux filesystem (and everyone does at first), just type pwd to see exactly where you are.

bash
pwd
# Output: /home/yourusername
# This tells you're in your home directory

Real-world analogy: You're in a large shopping mall and check the "You Are Here" map. pwd gives you that same "You Are Here" information for your Linux system.

ls: What's Here?

The ls command stands for List. It shows you what files and folders are in your current location. Think of it as opening a drawer or looking around a room to see what's inside.

bash
# Basic listing
ls

# Detailed listing (most useful)
ls -l
# Shows: permissions, owner, size, date, filename

# Human readable sizes
ls -lh
# Shows sizes in KB, MB, GB instead of bytes

# Show all files (including hidden ones starting with .)
ls -la
# Hidden files are configuration files, usually not shown by default

# Sort by modification time (newest first)
ls -lt

Why the options matter:

  • -l gives you the "details view" like in Windows Explorer

  • -a shows hidden files (configuration files that start with dot)

  • -h makes file sizes readable (1.5M instead of 1572864 bytes)

Real-world use: When you connect to a server for the first time, ls is usually the first command you run to see what's there.

cd: Changing Locations

The cd command stands for Change Directory. It's how you move between folders, just like walking from one room to another in a building.

bash
# Go to home directory
cd ~
# The ~ symbol always means "home directory"

# Go to root directory (top level)
cd /

# Go up one level
cd ..
# The .. means "parent directory"

# Go to specific directory
cd /var/log
# This takes you directly to the log directory

# Go to previous directory
cd -
# This takes you back to where you just were

Common mistake: Forgetting that Linux is case-sensitive. cd Documents is different from cd documents.

Real-world scenario: You're troubleshooting and need to check logs. You'd use cd /var/log to go to the log directory, then ls to see what log files are available.


📁 File and Directory Management

mkdir: Creating New Folders

The mkdir command stands for Make Directory. It creates new folders (directories) for organizing your files.

bash
# Create a single directory
mkdir projects

# Create multiple directories at once
mkdir docs images scripts

# Create nested directory structure
mkdir -p projects/{src,test,docs,backup}
# This creates: projects/src, projects/test, etc.

# Create directory with specific permissions
mkdir -m 755 shared_folder
# Sets read/write/execute for owner, read/execute for others

The -p flag is magical: It creates parent directories if they don't exist. Without -p, if you try mkdir a/b/c and directory a doesn't exist, you'll get an error.

Real-world use: Setting up a new project structure with organized folders for different types of files.

touch: Creating Empty Files

The touch command creates empty files. It's named "touch" because it can also update the timestamp of existing files (like "touching" them to update).

bash
# Create a single file
touch notes.txt

# Create multiple files
touch file1.txt file2.txt file3.txt

# Create files with pattern
touch file{1..5}.txt
# Creates: file1.txt, file2.txt, file3.txt, file4.txt, file5.txt

# Update timestamp of existing file
touch existing_file.txt
# Updates the "last modified" time to now

Why create empty files? Often you need placeholder files, configuration files that will be filled later, or you want to mark that a task was completed.

rm: Removing Files and Directories

The rm command stands for Remove. This is the Linux equivalent of deleting files, but with an important warning: Linux has no recycle bin. Deleted files are gone forever unless you have backups.

bash
# Delete a file (carefully!)
rm file.txt

# Delete multiple files
rm file1.txt file2.txt file3.txt

# Delete directory and everything in it
rm -r directory_name
# -r means "recursive" - goes through all subdirectories

# Force delete without confirmation
rm -f file.txt
# -f means "force" - suppresses warnings

# Interactive delete (safer)
rm -i file.txt
# Asks: "remove file.txt?" before deleting

⚠️ DANGER ZONE: rm -rf / would delete EVERYTHING on your system. Never run this unless you want to destroy your Linux installation!

Safety tip: Always use ls first to confirm what you're deleting. Some people create an alias: alias rm='rm -i' to make rm always ask for confirmation.

cp: Copying Files

The cp command stands for Copy. It duplicates files or directories.

bash
# Copy file to another location
cp source.txt destination/

# Copy with new name
cp oldfile.txt newfile.txt

# Copy directory recursively
cp -r sourcedir/ destinationdir/
# -r means copy all files and subdirectories

# Preserve file attributes
cp -p importantfile.txt backup/
# -p preserves timestamps and permissions

# Interactive copy (ask before overwriting)
cp -i source.txt destination/

Common mistake: Forgetting the trailing slash. cp -r dir1 dir2 behaves differently than cp -r dir1/ dir2/. With the slash, you copy the contents. Without, you might create dir2/dir1/ structure.

mv: Moving or Renaming

The mv command stands for Move, but it's also used for renaming files. Think of it as picking up a file and putting it somewhere else.

bash
# Rename a file
mv oldname.txt newname.txt

# Move file to another directory
mv file.txt /home/user/documents/

# Move and rename at same time
mv file.txt /backup/file-backup.txt

# Move directory
mv olddir/ newlocation/

# Interactive mode (ask before overwriting)
mv -i source.txt destination/

Key insight: In Linux, renaming is just moving a file to the same location with a different name. That's why mv handles both operations.


👀 Viewing and Examining Files

cat: Concatenate and Display

The cat command stands for Concatenate, but it's most commonly used to display file contents. It shows you the entire file at once.

bash
# View a file
cat filename.txt

# View multiple files
cat file1.txt file2.txt

# Combine files (actual concatenation)
cat part1.txt part2.txt > combined.txt

# Add line numbers
cat -n filename.txt

# Show non-printing characters
cat -A filename.txt
# Shows tabs as ^I, line endings as $

Best for: Small files. If you try cat on a 1GB log file, you'll be watching text scroll for a long time!

Real-world use: Quick checks of configuration files or small scripts.

less: The Smart File Viewer

The less command is for viewing large files. It shows one screen at a time and lets you navigate through the file.

bash
# View a file page by page
less largefile.log

# Once in less, you can:
# Spacebar = Next page
# b = Previous page
# /pattern = Search for pattern
# q = Quit
# g = Go to beginning
# G = Go to end

Why it's called "less": It's a pun! There was an older program called more that could only go forward. less is "more" but can go backward too (less is more).

Pro tip: less is what runs automatically when you use man commands or when Git shows you diff outputs.

head and tail: Seeing Beginnings and Ends

These commands show just the beginning or end of files, which is incredibly useful for logs.

bash
# Show first 10 lines (default)
head filename.txt

# Show first 20 lines
head -20 filename.txt

# Show last 10 lines (default)
tail filename.txt

# Show last 50 lines
tail -50 filename.txt

# Watch a log file in real-time
tail -f /var/log/syslog
# -f means "follow" - shows new lines as they're added

Real-world scenario: Your application is having issues. You check the last 100 lines of the error log: tail -100 /var/log/app/error.log. If you need to watch it live as you test: tail -f /var/log/app/error.log.


🔍 Searching and Finding

find: Locating Files

The find command searches for files based on various criteria. It's one of the most powerful Linux commands.

bash
# Find files by name (current directory and subdirectories)
find . -name "*.txt"

# Find files modified in last 7 days
find /home -mtime -7

# Find files larger than 100MB
find / -size +100M 2>/dev/null
# 2>/dev/null hides "permission denied" errors

# Find and execute command on results
find . -name "*.tmp" -exec rm {} \;
# Finds all .tmp files and deletes them

# Find empty files
find . -type f -empty

Real-world troubleshooting: Disk is full. You need to find large files: find / -type f -size +500M 2>/dev/null | head -20

grep: Searching Inside Files

While find searches for files, grep searches inside files for specific text patterns.

bash
# Search for "error" in a file
grep "error" logfile.txt

# Case-insensitive search
grep -i "error" logfile.txt

# Search recursively in directory
grep -r "TODO" /home/user/projects/

# Show line numbers
grep -n "function" script.py

# Count occurrences
grep -c "warning" logfile.txt

# Search for multiple patterns
grep -e "error" -e "fail" logfile.txt

Name origin: grep comes from "Global Regular Expression Print" - it searches using patterns.

Real-world use: Checking if a configuration setting is enabled: grep "Listen" /etc/nginx/nginx.conf


📊 System Information Commands

df: Disk Free Space

The df command shows Disk Free space - how much space is used and available on your disks.

bash
# Basic disk usage
df

# Human readable format (MB, GB)
df -h

# Show filesystem type
df -T

# Show specific filesystem
df -h /home

Output explanation:

text
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   35G   12G  75% /
  • Size = Total capacity

  • Used = Space used

  • Avail = Space available

  • Use% = Percentage used

  • Mounted on = Where it's accessible

Monitoring tip: Set up alerts when Use% reaches 80% or 90% to prevent disk-full emergencies.

du: Disk Usage by Directory

While df shows disk-level usage, du shows Disk Usage by directory - which folders are taking up space.

bash
# Show size of current directory
du -sh
# -s = summary (total only)
# -h = human readable

# Show sizes of all subdirectories
du -h --max-depth=1

# Sort by size (largest first)
du -sh * | sort -rh

# Find largest directories
du -ah /home | sort -rh | head -20

Troubleshooting use: Server is running out of space. Run du -sh /* | sort -rh | head -10 to find which top-level directories are largest.

free: Memory Usage

The free command shows memory (RAM) usage statistics.

bash
# Basic memory info
free

# Human readable
free -h

# Show in megabytes
free -m

# Continuous monitoring
free -h -s 5
# Updates every 5 seconds

Understanding output:

text
              total        used        free      shared  buff/cache   available
Mem:           7.7G        2.1G        1.2G        456M        4.4G        4.8G
Swap:          2.0G        512M        1.5G
  • used = Memory used by applications

  • free = Completely unused memory

  • buff/cache = Memory used for disk caching (can be freed if needed)

  • available = Memory available for new applications

Key insight: Linux uses free memory for disk caching to speed things up. This is why "used" memory might seem high even when your system isn't busy.


🔧 Utility Commands

echo: Displaying Text

The echo command prints text to the screen. It's simple but used everywhere, especially in scripts.

bash
# Print text
echo "Hello World"

# Print variable value
echo $HOME

# Create a file with content
echo "server configuration" > config.txt

# Append to file
echo "new setting" >> config.txt

# With escape characters
echo -e "Line 1\nLine 2"
# -e enables interpretation of \n as newline

Scripting use: echo is often used to show progress messages: echo "Starting backup process..."

which: Finding Command Locations

The which command shows you where a command is located on your system.

bash
# Find where ls command is
which ls
# Output: /bin/ls

# Find where python is installed
which python3

# Check if a command exists
which somecommand || echo "Command not found"

Why it matters: Sometimes you have multiple versions of a program installed. which tells you which one will run when you type the command.

man: Getting Help

The man command stands for Manual. It shows the official documentation for any command.

bash
# View manual for ls
man ls

# Search manuals
man -k "copy"
# Shows all commands related to copying

# Within man pages:
# Spacebar = Next page
# b = Previous page
# /pattern = Search
# q = Quit

Pro tip: If you forget man options, man man shows the manual for the manual command itself!

Alternative: Most commands also support --help flag: ls --help


🎯 Practice Exercises

Exercise 1: Create a Project Structure

Let's practice by creating a realistic project folder structure:

bash
# 1. Go to your home directory
cd ~

# 2. Create project directory
mkdir my_website_project

# 3. Go into it
cd my_website_project

# 4. Create subdirectories
mkdir -p {html,css,js,images,backup}

# 5. Create some files
touch index.html about.html contact.html
touch css/style.css js/main.js

# 6. Check what you created
ls -la
find . -type f

# 7. Create a backup
cp -r css/ backup/
ls backup/

Exercise 2: Log File Analysis

Practice with a simulated log file:

bash
# 1. Create a sample log file
cat > app.log << EOF
2024-01-10 10:00:00 INFO: Application started
2024-01-10 10:05:00 WARNING: High memory usage detected
2024-01-10 10:10:00 ERROR: Database connection failed
2024-01-10 10:15:00 INFO: Retrying connection
2024-01-10 10:20:00 ERROR: Connection timeout
2024-01-10 10:25:00 INFO: Switching to backup server
2024-01-10 10:30:00 INFO: Connection established
EOF

# 2. View the log
cat app.log

# 3. Find only error lines
grep "ERROR" app.log

# 4. Count warning and error lines
grep -c "WARNING\|ERROR" app.log

# 5. Watch last 3 lines
tail -3 app.log

# 6. Add a new log entry
echo "2024-01-10 10:35:00 INFO: Backup completed" >> app.log

# 7. Check the new entry
tail -2 app.log

Exercise 3: System Check Script

Create a simple system monitoring script:

bash
# Create the script
cat > system_check.sh << 'EOF'
#!/bin/bash
echo "=== System Health Check ==="
echo "Date: $(date)"
echo
echo "1. Disk Usage:"
df -h /
echo
echo "2. Memory Usage:"
free -h
echo
echo "3. Top 5 largest directories in /home:"
du -sh /home/* 2>/dev/null | sort -rh | head -5
echo
echo "4. Running as user: $(whoami)"
echo "5. System uptime: $(uptime -p)"
EOF

# Make it executable
chmod +x system_check.sh

# Run it
./system_check.sh

🚨 Common Mistakes and How to Avoid Them

Mistake 1: Using rm Carelessly

Wrong: rm -rf / home/user/documents (space after / deletes everything!)
Right: rm -rf /home/user/documents

Protection: Always double-check paths. Use ls first to see what you'll delete.

Mistake 2: Case Sensitivity

Wrong: cd Documents when folder is documents
Right: Match the exact case or use tab completion

Tip: Press Tab to auto-complete. It prevents typos.

Mistake 3: Forgetting -r for Directories

Wrong: cp directory newlocation (won't copy contents)
Right: cp -r directory newlocation

Remember: -r means recursive for directory operations with cprm, and chmod.

Mistake 4: Not Using man or --help

Wrong: Guessing command options
Right: man commandname or commandname --help

Pro tip: If you forget a command, use apropos: apropos "copy files"


📋 Daily Command Reference Cheat Sheet

TaskCommandExampleWhen to Use
See locationpwdpwdWhen you're lost
List filesls -lals -la ~First command in new directory
Change directorycdcd /var/logNavigating folders
Create directorymkdir -pmkdir -p project/{src,test}Setting up projects
Create filetouchtouch config.yamlCreating empty files
View filelessless largefile.logReading files (better than cat)
View start of fileheadhead -20 file.txtChecking file beginnings
View end of filetail -ftail -f app.logMonitoring logs in real-time
Copycp -rcp -r source/ dest/Copying directories
Move/Renamemvmv old.txt new.txtMoving or renaming
Deleterm -irm -i oldfile.txtSafer deletion (asks first)
Find filesfindfind . -name "*.log"Searching for files
Search in filesgrepgrep "error" *.logFinding text in files
Disk spacedf -hdf -h /homeChecking storage
Directory sizedu -shdu -sh *Finding large folders
Memoryfree -hfree -hChecking RAM usage
Get helpmanman lsLearning commands

🚀 Next Steps in Your Command Line Journey

  1. Week 1-2: Master the 10 essential commands (ls, cd, pwd, cat, less, cp, mv, rm, mkdir, grep)

  2. Week 3-4: Learn file permissions (chmod, chown) and process management (ps, top)

  3. Week 5-6: Practice with real projects - set up a web server, analyze logs

  4. Week 7-8: Learn shell scripting basics to automate your tasks

Remember: You don't need to memorize everything. Focus on understanding what each command does. The muscle memory will come with practice.


🔗 Practice with Interactive Labs

The best way to learn Linux commands is through hands-on practice in a safe environment where you can experiment without fear of breaking anything.

👉 Master Linux commands through guided, interactive exercises at:
https://devops.trainwithsky.com/

Our platform offers:

  • Real terminal in your browser

  • Step-by-step tutorials

  • Practical exercises based on real-world scenarios

  • Instant feedback and hints

  • Progress tracking and achievements


Frequently Asked Questions

Q: How many commands do I really need to know?
A: About 20 commands will let you do 80% of common tasks. Start with the ones in this guide.

Q: I keep forgetting commands. Is that normal?
A: Absolutely! Even experts use man and Google. Focus on understanding concepts, not memorization.

Q: Should I learn all the command options?
A: No! Learn the common options first. You can always look up rare options when needed.

Q: How long until I'm comfortable with the command line?
A: With 30 minutes of daily practice, most people feel comfortable in 2-3 weeks.

Q: What if I make a mistake and delete something important?
A: That's why we recommend practicing in virtual machines or our safe online labs first!

Have questions about specific commands or scenarios? Ask in the comments below - we're here to help! 💬

Comments

Popular posts from this blog

Introduction to Terraform – The Future of Infrastructure as Code

  Introduction to Terraform – The Future of Infrastructure as Code In today’s fast-paced DevOps world, managing infrastructure manually is outdated . This is where Terraform comes in—a powerful Infrastructure as Code (IaC) tool that allows you to define, provision, and manage cloud infrastructure efficiently . Whether you're working with AWS, Azure, Google Cloud, or on-premises servers , Terraform provides a declarative, automation-first approach to infrastructure deployment. Shape Your Future with AI & Infinite Knowledge...!! Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! In today’s digital-first world, agility and automation are no longer optional—they’re essential. Companies across the globe are rapidly shifting their operations to the cloud to keep up with the pace of innovatio...

📊 Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd

  Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd Monitoring and logging are essential for maintaining a healthy and well-performing Kubernetes cluster. In this guide, we’ll cover why monitoring is important, key monitoring tools like Prometheus and Grafana, and logging tools like Fluentd to help you gain visibility into your cluster’s performance and logs. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction In today’s fast-paced cloud-native environment, Kubernetes has emerged as the de-facto container orchestration platform. But deploying and managing applications in Kubernetes is just half the ba...

🔒 Kubernetes Security – RBAC, Network Policies, and Secrets Management

  Kubernetes Security – RBAC, Network Policies, and Secrets Management Security is a critical aspect of managing Kubernetes clusters. In this guide, we'll cover essential security mechanisms like Role-Based Access Control (RBAC) , Network Policies , and Secrets Management to help you secure your Kubernetes environment effectively. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction: Why Kubernetes Security Is Non-Negotiable As Kubernetes becomes the backbone of modern cloud-native infrastructure, security is no longer optional—it’s mission-critical . With multiple moving parts like containers, pods, services, nodes, and more, Kuberne...