linux-command-reference.
md 2024-11-25
Linux Command Reference Guide
Essential Navigation & File Operations
Basic Navigation
pwd: Print Working Directory - shows current directory path
ls: List files and directories
ls -l: Long format with permissions and details
ls -a: Show hidden files
ls -lh: Human-readable file sizes
cd [directory]: Change Directory
cd ..: Move up one directory
cd ~: Go to home directory
cd -: Go to previous directory
File Operations
cp [source] [destination]: Copy files/directories
cp -r: Copy directories recursively
mv [source] [destination]: Move/rename files
rm [file]: Remove files
rm -r: Remove directories recursively
rm -f: Force remove without confirmation
mkdir [directory]: Create directory
touch [file]: Create empty file/update timestamp
File Permissions
Understanding Permissions
rwx rwx rwx = 777
─┬─ ─┬─ ─┬─
│ │ │
│ │ └─── Others (Everyone else)
│ └─────── Group
└─────────── Owner
r (read) = 4
w (write) = 2
x (execute) = 1
chmod Commands
chmod [permissions] [file]: Change file permissions
Numeric format:
1/3
linux-command-reference.md 2024-11-25
chmod 755 file: rwxr-xr-x
chmod 644 file: rw-r--r--
chmod 777 file: rwxrwxrwx
Symbolic format:
chmod u+x file: Add execute for user
chmod g-w file: Remove write for group
chmod o=r file: Set others to read only
chmod a+x file: Add execute for all
OpenRC Environment Variables
Service Management
rc-service [service] start: Start a service
rc-service [service] stop: Stop a service
rc-service [service] restart: Restart a service
rc-status: Show status of all services
rc-update add [service] [runlevel]: Add service to runlevel
rc-update del [service] [runlevel]: Remove service from runlevel
Environment Variables
env: Display all environment variables
echo $VARIABLE: Display specific variable
export VARIABLE=value: Set environment variable
source /etc/profile: Reload environment variables
/etc/env.d/: Directory for environment variable files
Log File Operations
tail Command Options
tail [file]: Show last 10 lines of file
tail -n [number] [file]: Show last N lines
tail -f [file]: Follow file in real-time (useful for logs)
tail -F [file]: Follow file by name (works even if file is rotated)
tail -n +[number] [file]: Start showing from line N
Common Log Monitoring Commands
tail -f /var/log/syslog: Monitor system logs
tail -f /var/log/auth.log: Monitor authentication logs
tail -f /var/log/messages: Monitor general system messages
tail -f /var/log/apache2/access.log: Monitor Apache access logs
journalctl -f: Monitor systemd journal logs
System Information & Process Management
System Commands
2/3
linux-command-reference.md 2024-11-25
top: Display system processes in real-time
htop: Interactive process viewer
ps aux: Show all running processes
df -h: Show disk space usage
free -h: Show memory usage
uname -a: Show system information
Process Management
kill [PID]: Terminate process by ID
killall [name]: Terminate processes by name
pkill [pattern]: Kill processes matching pattern
nice [value] [command]: Run command with modified priority
Additional Tips
1. Combining Commands:
Use | (pipe) to chain commands
Use && to run commands sequentially if previous succeeds
Use ; to run commands sequentially regardless of success
2. Shortcuts:
Ctrl + C: Interrupt current process
Ctrl + Z: Suspend current process
Ctrl + D: Exit current shell
Ctrl + R: Search command history
!!: Repeat last command
3. Common Log Locations:
/var/log/: Main log directory
/var/log/syslog: System logs
/var/log/auth.log: Authentication logs
/var/log/messages: General message logs
3/3