Docs / Getting Started / Beginner's Guide to the Linux Command Line

Beginner's Guide to the Linux Command Line

By Admin · Mar 15, 2026 · Updated Apr 23, 2026 · 494 views · 4 min read

The Linux command line (also called the terminal, shell, or CLI) is your primary interface for managing a VPS. While it might seem intimidating at first, mastering a handful of commands will let you accomplish most server administration tasks efficiently.

Understanding the Shell Prompt

# Typical prompt format:
user@hostname:~$

# Breakdown:
# user     — Your username
# hostname — The server's name
# ~        — Current directory (~ means your home directory)
# $        — Regular user (# means root user)

Essential Navigation Commands

# Print current directory
pwd
# Output: /home/deploy

# List files and directories
ls          # Basic listing
ls -la      # Detailed listing with hidden files
ls -lh      # Human-readable file sizes
ls -lt      # Sort by modification time

# Change directory
cd /var/log          # Go to an absolute path
cd ..                # Go up one directory
cd ~                 # Go to your home directory
cd -                 # Go to the previous directory

File Operations

# Create files
touch newfile.txt              # Create empty file
echo "Hello" > file.txt        # Create file with content
echo "More" >> file.txt        # Append to file

# Create directories
mkdir myproject                # Create a directory
mkdir -p path/to/nested/dir    # Create nested directories

# Copy files and directories
cp file.txt backup.txt         # Copy a file
cp -r mydir/ backup/           # Copy a directory recursively

# Move/rename files
mv old-name.txt new-name.txt   # Rename
mv file.txt /var/www/          # Move to another directory

# Delete files and directories
rm file.txt                    # Delete a file
rm -r mydir/                   # Delete a directory and contents
rm -i important.txt            # Ask for confirmation before deleting

Reading File Contents

# Display entire file
cat file.txt

# Display with line numbers
cat -n file.txt

# View large files page by page
less /var/log/syslog           # Navigate with arrows, q to quit

# View first/last lines
head -20 file.txt              # First 20 lines
tail -20 file.txt              # Last 20 lines
tail -f /var/log/syslog        # Follow log in real time (Ctrl+C to stop)

Searching and Filtering

# Search for text in files
grep "error" /var/log/syslog           # Find lines containing "error"
grep -i "error" /var/log/syslog        # Case-insensitive search
grep -r "TODO" /var/www/               # Search recursively in directory
grep -c "error" /var/log/syslog        # Count matching lines

# Find files
find / -name "nginx.conf"              # Find by name
find /var/log -name "*.log" -size +10M # Find log files larger than 10MB
find /tmp -mtime +7 -delete            # Delete files older than 7 days

Pipes and Redirection

Pipes (|) connect the output of one command to the input of another. This is one of the most powerful features of the command line.

# Pipe examples
cat /var/log/syslog | grep "error" | wc -l     # Count error lines
ps aux | sort -k3 -rn | head -10               # Top 10 CPU-consuming processes
du -sh /var/*  | sort -rh | head -5             # 5 largest directories in /var

# Redirect output to a file
ls -la > filelist.txt          # Overwrite file with output
ls -la >> filelist.txt         # Append output to file
command 2> errors.log          # Redirect errors only
command > output.log 2>&1      # Redirect both stdout and stderr

Process Management

# List running processes
ps aux                          # All processes
ps aux | grep nginx             # Find specific processes

# Interactive process viewer
htop                            # Better than top (install with apt/dnf)

# Kill a process
kill PID                        # Graceful stop (SIGTERM)
kill -9 PID                     # Force kill (SIGKILL) — last resort
killall nginx                   # Kill all processes by name

# Background and foreground
long-command &                  # Run in background
jobs                            # List background jobs
fg %1                           # Bring job 1 to foreground
Ctrl+Z                          # Suspend current process
bg %1                           # Resume suspended job in background

Package Management

# Ubuntu/Debian (apt)
sudo apt update                         # Update package index
sudo apt upgrade                        # Upgrade installed packages
sudo apt install nginx                  # Install a package
sudo apt remove nginx                   # Remove a package
sudo apt autoremove                     # Remove unneeded dependencies
apt search keyword                      # Search for packages

# AlmaLinux/Rocky (dnf)
sudo dnf check-update                   # Check for updates
sudo dnf upgrade                        # Upgrade packages
sudo dnf install nginx                  # Install a package
sudo dnf remove nginx                   # Remove a package
dnf search keyword                      # Search for packages

Permissions

# Understanding permission output
# -rwxr-xr-- 1 deploy www-data 4096 Jan 15 10:30 script.sh
# │├──┤├──┤├──┤
# │ │   │   └── Others: read only
# │ │   └────── Group: read + execute
# │ └────────── Owner: read + write + execute
# └──────────── File type (- = file, d = directory)

# Change permissions
chmod 755 script.sh             # rwxr-xr-x
chmod 644 config.txt            # rw-r--r--
chmod +x script.sh              # Add execute permission

# Change ownership
chown deploy:www-data file.txt  # Change owner and group
chown -R deploy:www-data /var/www/  # Recursive

Helpful Shortcuts

  • Tab — Auto-complete file names and commands
  • Ctrl+C — Cancel the current command
  • Ctrl+R — Search command history
  • Up/Down arrows — Navigate command history
  • Ctrl+A / Ctrl+E — Jump to start/end of line
  • Ctrl+L — Clear the screen (same as clear)
  • !! — Repeat the last command (e.g., sudo !! to rerun with sudo)

Practice these commands regularly and they'll become second nature. For more details on any command, use man command-name or command --help.

Was this article helpful?