๐ง Linux Essentials: An Easy-to-Understand Guide
๐ Index
๐ฆ Package Management
RPM-Based (YUM & RPM)
YUM Commands
Command | Purpose | Example |
---|---|---|
yum update |
Update repos & packages | yum update |
yum search <package> |
Search package | yum search httpd |
yum install <package> |
Install package | yum install nginx |
yum check-update <package> |
Check if package needs updates | yum check-update nginx |
yum remove <package> |
Remove package | yum remove nginx |
RPM Commands
Command | Purpose | Example |
---|---|---|
rpm -ipv <file>.rpm |
Install package with progress & verbose | rpm -ipv nano.rpm |
rpm -qi <package> |
Query detailed info | rpm -qi nano |
rpm -e <package> |
Remove package | rpm -e nano |
Debian-Based (APT & dpkg)
APT Commands
Command | Purpose | Example |
---|---|---|
apt-get update |
Refresh package cache | apt-get update |
apt-cache search <package> |
Search for packages | apt-cache search nginx |
apt-get install <package> |
Install package | apt-get install nginx |
apt-get remove --purge <package> |
Remove package & config files | apt-get remove --purge nginx |
dpkg Commands
Command | Purpose | Example |
---|---|---|
dpkg -i <file>.deb |
Install Debian package | dpkg -i nginx.deb |
dpkg --get-selections |
List installed packages | dpkg --get-selections |
dpkg --purge <package> |
Completely remove package | dpkg --purge nginx |
๐ป Command-Line Basics
Shell and Environment
- Interactive Shell: CLI session.
- Non-Interactive Shell: Background scripts/processes.
# Check current shell
echo $SHELL
# Command history
history # Show all commands
history 10 # Last 10 commands
!10 # Execute command #10
!! # Repeat last command
^typo^fix^ # Fix typo in previous command
Basic Linux Commands
Command | Usage |
---|---|
cd |
Change directories (e.g., cd /home ) |
ls -la |
List files detailed, including hidden files |
top |
View active processes |
whoami |
Display current user |
Command-Line Syntax
- Command Structure:
<command> [options] [arguments]
Example:
ls -l -a /var/log
Working with Variables
# Set and export variable
MY_VAR="Hello World"
export MY_VAR
echo $MY_VAR # prints Hello World
File Globbing
Wildcard | Meaning |
---|---|
* |
Match 0 or more chars |
? |
Match exactly 1 char |
[abc] |
Match a, b, or c |
Examples:
ls *.txt # all .txt files
ls file?.txt # files like file1.txt, fileA.txt
๐ Getting CLI Help
Using Man Pages
- Quickly reference command details
man ls
Info Pages
- Detailed documentation with hyperlinks
info coreutils
Quick Help Commands
Command | Description | Example |
---|---|---|
whatis <command> |
Brief command purpose | whatis ls |
apropos <keyword> |
Search keyword in manuals | apropos file |
๐ Examples and Practice
Example 1: Find large files in the home directory:
find ~/ -size +50M
Example 2: Compress and archive a folder:
tar -czvf archive.tar.gz folder/
Example 3: Search logs for errors:
grep -i error /var/log/*.log
โจ Practice Tip: Try running these commands on your system for hands-on experience.
Happy Learning! ๐ง๐