Linux Command Line Basics
Last Updated: 2025-01-01
3 min read
Introduction
The Linux command line (also called the terminal or shell) is the primary way to manage your hosting server via SSH. This guide covers the most essential commands every beginner should know.
Navigating Directories
pwd — Print Working Directory
Displays your current location in the filesystem:
pwd
# Output: /home/username
cd — Change Directory
Move between directories:
cd /var/www/html # Go to an absolute path
cd my-site # Enter a subdirectory
cd .. # Go up one level
cd ~ # Go to your home directory
cd - # Go back to the previous directory
ls — List Directory Contents
View files and folders in the current directory:
ls # Basic listing
ls -l # Detailed list (permissions, size, date)
ls -la # Include hidden files (those starting with .)
ls -lh # Human-readable file sizes
ls -lt # Sort by modification time (newest first)
Creating and Removing Files & Directories
mkdir — Make Directory
mkdir new-folder # Create a single directory
mkdir -p path/to/nested/dir # Create nested directories at once
touch — Create an Empty File
touch newfile.txt # Create a new empty file
touch file1.txt file2.txt # Create multiple files
cp — Copy Files and Directories
cp file.txt backup.txt # Copy a file
cp -r my-folder/ my-folder-backup/ # Copy a directory recursively
mv — Move or Rename
mv oldname.txt newname.txt # Rename a file
mv file.txt /var/www/html/ # Move a file to another directory
rm — Remove Files and Directories
rm file.txt # Delete a file
rm -r my-folder/ # Delete a directory and its contents
rm -rf my-folder/ # Force delete without confirmation
Warning:
rm -rfis irreversible. Always double-check your path before running it.
Viewing File Contents
cat — Display Entire File
cat config.php # Print entire file to screen
less — Scroll Through a File
less largefile.log # Navigate with arrow keys; press q to quit
head and tail — View Start or End of a File
head -n 20 access.log # Show the first 20 lines
tail -n 50 error.log # Show the last 50 lines
tail -f error.log # Follow the file in real time (great for logs)
Helpful Tips
- Press Tab to auto-complete file and directory names.
- Use the Up/Down arrow keys to cycle through command history.
- Run
clearto clean up the terminal screen. - Use
man <command>(e.g.,man ls) to read the built-in manual for any command.
These commands form the foundation of everything you’ll do on a Linux server. Once you’re comfortable here, explore more advanced tools like grep, find, and du to manage your hosting environment efficiently.
Tags:
ssh
linux
command-line
basics