Command Line

Master the powerful Linux command line interface to unlock advanced system administration and automation capabilities.

Terminal Access

Open the terminal using Ctrl+Alt+T, searching for "Terminal" in activities, or clicking the terminal icon in the dock.

Essential Commands

File Operations

# List files and directories
ls -la

# Change directory
cd /path/to/directory

# Copy files
cp source destination

# Move/rename files
mv oldname newname

# Remove files
rm filename

# Create directory
mkdir dirname

System Information

# System uptime
uptime

# Disk usage
df -h

# Memory usage
free -h

# Running processes
ps aux

# System monitor
top

Text Processing

# View file contents
cat filename

# Page through file
less filename

# Search in files
grep "pattern" filename

# Edit files
nano filename

# Word count
wc filename

Network & System

# Network configuration
ip addr show

# Check connectivity
ping hostname

# Download files
wget URL

# Archive files
tar -czf archive.tar.gz files/

# System services
systemctl status servicename

File Permissions

Understanding and managing file permissions is crucial for system security and functionality.

Permission Numeric Symbolic Description
Read 4 r View file contents or list directory
Write 2 w Modify file or directory contents
Execute 1 x Run file or access directory

Common Permission Examples

# Make file executable
chmod +x script.sh

# Set permissions numerically
chmod 755 filename  # rwxr-xr-x
chmod 644 filename  # rw-r--r--

# Change ownership
chown user:group filename

# Recursive permissions
chmod -R 755 directory/

Permission Breakdown

  • 755: Owner (rwx), Group (r-x), Others (r-x)
  • 644: Owner (rw-), Group (r--), Others (r--)
  • 600: Owner (rw-), Group (---), Others (---)
  • 777: Everyone (rwx) - Use with caution!

Advanced Features

Pipes and Redirection

Combine commands and control output:

# Pipe output to another command
ls -la | grep ".txt"

# Redirect output to file
ls -la > filelist.txt

# Append to file
echo "new line" >> file.txt

# Redirect errors
command 2> error.log

# Redirect both output and errors
command > output.log 2>&1

Job Control

Manage running processes:

# Run in background
command &

# List background jobs
jobs

# Bring job to foreground
fg %1

# Send job to background
bg %1

# Stop current job
Ctrl+Z

# Kill current job
Ctrl+C

Environment Variables

Manage shell environment:

# View all variables
env

# Set variable
export VARNAME=value

# View specific variable
echo $VARNAME

# Add to PATH
export PATH=$PATH:/new/directory

# Make permanent (add to ~/.bashrc)
echo 'export VARNAME=value' >> ~/.bashrc

Command History and Shortcuts

History Commands

  • history - Show command history
  • !! - Repeat last command
  • !n - Repeat command number n
  • !string - Repeat last command starting with string
  • Ctrl+R - Search command history

Keyboard Shortcuts

  • Ctrl+C - Kill current process
  • Ctrl+Z - Suspend current process
  • Ctrl+A - Move to beginning of line
  • Ctrl+E - Move to end of line
  • Ctrl+U - Clear line before cursor
  • Tab - Auto-complete commands/files

Scripting Basics

Create shell scripts to automate repetitive tasks:

Simple Script Example

#!/bin/bash
# Simple backup script

DATE=$(date +%Y%m%d)
BACKUP_DIR="/backup"
SOURCE_DIR="/home/user/documents"

echo "Starting backup on $DATE"
tar -czf "$BACKUP_DIR/backup_$DATE.tar.gz" "$SOURCE_DIR"
echo "Backup completed successfully!"

Save as backup.sh, make executable with chmod +x backup.sh, then run with ./backup.sh

Pro Tips

  • • Use man command to read manual pages for any command
  • • Press Tab twice to see all available completions
  • • Use which command to find where a command is located
  • • Chain commands with && (run if previous succeeds) or || (run if previous fails)