Essential Linux command line skills and terminal operations you need to work effectively in DevOps. This covers basic commands, file management, and shell operations that are fundamental to cloud and DevOps work.
Command Line Interface (CLI) is a text-based interface for interacting with your computer. It's faster, more powerful, and essential for automation and DevOps work.
Why Learn CLI?
- Automation: Script repetitive tasks
- Remote access: Connect to servers via SSH
- DevOps tools: Most DevOps tools are CLI-based
- Cloud platforms: AWS CLI, Azure CLI, etc.
- Server management: Most servers are Linux-based
- Definition: Program that interprets commands
- Common shells: Bash (default), Zsh, Fish
- Purpose: Interface between user and operating system
- Terminal: Application that runs the shell
- Shell: Program that executes commands
- Examples: Terminal.app (macOS), Windows Terminal, iTerm2
pwd # Print working directory (show current location)
ls # List files and directories
cd # Change directory
mkdir # Make directory
rmdir # Remove empty directorycd / # Go to root directory
cd ~ # Go to home directory
cd .. # Go up one directory
cd - # Go to previous directory
ls -la # List all files (including hidden) with detailscat # Display file content
less # View file content (scrollable)
head # Show first 10 lines
tail # Show last 10 lines
tail -f # Follow file changes (useful for logs)cp # Copy files/directories
mv # Move/rename files/directories
rm # Remove files
touch # Create empty file or update timestampchmod # Change file permissions
chown # Change file owner
ls -l # List with permissionsPermission Examples:
chmod +x script.sh # Make executable
chmod 755 file.txt # Set specific permissions
chmod 644 file.txt # Read/write for owner, read for othersgrep # Search for text patterns
find # Find files by name/attributes
which # Find command location
whereis # Find command, source, and manual pagesecho # Print text
sort # Sort lines
uniq # Remove duplicate lines
wc # Count lines, words, characters
cut # Extract sections from linesps # Show running processes
top # Show system resources (interactive)
htop # Enhanced top (if available)
df # Show disk space
du # Show directory size
free # Show memory usageping # Test network connectivity
curl # Transfer data from/to server
wget # Download files
netstat # Show network connections
ss # Show socket statisticshistory # Show command history
!n # Execute command number n
!! # Execute last command
Ctrl+R # Search command history- Press Tab to auto-complete commands, filenames, paths
- Press Tab twice to show all possible completions
- Essential for efficiency and avoiding typos
command1 && command2 # Run command2 only if command1 succeeds
command1 || command2 # Run command2 only if command1 fails
command1 ; command2 # Run both commands regardless
command1 | command2 # Pipe output from command1 to command2command > file # Redirect output to file (overwrite)
command >> file # Redirect output to file (append)
command < file # Redirect input from file
command 2>&1 # Redirect stderr to stdout/ # Root directory
├── bin/ # Essential binaries
├── boot/ # Boot loader files
├── dev/ # Device files
├── etc/ # Configuration files
├── home/ # User home directories
├── lib/ # Shared libraries
├── media/ # Mount points for removable media
├── mnt/ # Mount points
├── opt/ # Optional applications
├── proc/ # Process information
├── root/ # Root user home
├── run/ # Runtime data
├── sbin/ # System binaries
├── srv/ # Service data
├── sys/ # System information
├── tmp/ # Temporary files
├── usr/ # User programs and data
└── var/ # Variable data (logs, etc.)
- /etc/: Configuration files
- /var/log/: System and application logs
- /home/: User directories
- /tmp/: Temporary files
- /opt/: Third-party applications
- Regular files: Text, binary, executable
- Directories: Contain other files
- Symbolic links: Pointers to other files
- Device files: Represent hardware devices
-rw-r--r-- 1 user group 1234 Jan 1 12:00 file.txt
││││││││││ │ │ │ │ │ │
││││││││││ │ │ │ │ │ └── Filename
││││││││││ │ │ │ │ └────────── Date
││││││││││ │ │ │ └────────────── Size
││││││││││ │ │ └──────────────────── Group
││││││││││ │ └───────────────────────── Owner
││││││││││ └──────────────────────────── Links
│││││││││└──────────────────────────────── Others (read)
││││││││└───────────────────────────────── Others (write)
│││││││└────────────────────────────────── Others (execute)
││││││└─────────────────────────────────── Group (execute)
│││││└──────────────────────────────────── Group (write)
││││└───────────────────────────────────── Group (read)
│││└────────────────────────────────────── Owner (execute)
││└─────────────────────────────────────── Owner (write)
│└──────────────────────────────────────── Owner (read)
└───────────────────────────────────────── File type (- = file, d = directory, l = link)
# View recent log entries
tail -n 50 /var/log/application.log
# Search for errors
grep "ERROR" /var/log/application.log
# Monitor log in real-time
tail -f /var/log/application.log# Create backup of configuration
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
# Find large files
find /home -type f -size +100M
# Count files in directory
ls -1 | wc -l# Check disk space
df -h
# Check memory usage
free -h
# Check running processes
ps aux | grep nginx-
Q: What command shows your current directory? A:
pwd -
Q: How do you list all files including hidden ones? A:
ls -la -
Q: What does
cd ..do? A: Goes up one directory level
-
Q: How do you copy a file? A:
cp source destination -
Q: What command removes a file? A:
rm filename -
Q: How do you make a file executable? A:
chmod +x filename
-
Q: How do you search for text in a file? A:
grep "text" filename -
Q: What does
tail -fdo? A: Follows file changes in real-time
- Navigate directories: Use
cd,ls,pwd - Create files and directories: Use
mkdir,touch - Copy and move files: Use
cp,mv - View file contents: Use
cat,less,head,tail
- Search for files: Use
findandgrep - Check system resources: Use
top,df,free - Work with permissions: Use
chmod,chown - Use command chaining: Use
&&,||,|
- Write simple scripts: Create bash scripts
- Process text data: Use
awk,sed - Network troubleshooting: Use
ping,curl,netstat - System administration: Monitor processes and logs
- Linux Journey - Interactive Linux tutorial
- Bash Guide - Comprehensive bash guide
- Linux Command Library - Command reference
- OverTheWire Bandit - Linux security wargame
- HackerRank Linux Shell - Shell scripting challenges
- Cloud Computing Basics - AWS CLI usage
- Programming & Scripting - Shell scripting
- DevOps Fundamentals - Automation concepts
Ready for the next step? Move on to Networking Fundamentals to understand network concepts!