Linux Command Line Basics: Essential Commands for Beginners
Learn essential Linux command line commands: file navigation, management, editing, permissions, and system info. Perfect for VPS/Dedicated server beginners.
On this page
Navigation: cd, pwd, ls
pwd - Print working directory (shows current location):
$ pwd
/home/username/public_html
ls - List directory contents:
$ ls # List files in current directory
$ ls -la # List with details and hidden files (-a shows hidden, -l is long format)
$ ls -lh # Human-readable file sizes
cd - Change directory:
$ cd /var/www # Go to absolute path
$ cd .. # Go to parent directory
$ cd ~ # Go to home directory
$ cd - # Go to previous directory
File Management: cp, mv, rm
cp - Copy files:
$ cp file.txt file-copy.txt # Copy file
$ cp -r directory/ directory-copy/ # Copy directory recursively
mv - Move or rename:
$ mv oldname.txt newname.txt # Rename file
$ mv file.txt /home/backup/ # Move file to directory
rm - Delete (CAUTION: no recovery):
$ rm file.txt # Delete file
$ rm -r directory/ # Delete directory and contents
$ rm -f file.txt # Force delete (no confirmation)
Viewing Files: cat, less, tail
cat - Display entire file:
$ cat filename.txt
less - View file with pagination (scroll with arrow keys, 'q' to quit):
$ less logfile.txt
tail - View last lines (useful for logs):
$ tail logfile.txt # Last 10 lines
$ tail -20 logfile.txt # Last 20 lines
$ tail -f logfile.txt # Follow in real-time (Ctrl+C to stop)
Permissions: chmod, chown
chmod - Change file permissions (755 = rwxr-xr-x):
$ chmod 755 script.sh # Make executable (owner: all, others: read+execute)
$ chmod 644 file.txt # Readable but not executable
$ chmod -R 755 dir/ # Change directory and all contents
chown - Change file owner:
$ sudo chown user:group file.txt # Change owner and group
$ sudo chown -R user:group dir/ # Recursively
System Information
Common system info commands:
$ whoami # Current user
$ hostname # Server name
$ uname -a # System information
$ df -h # Disk space usage
$ free -h # RAM usage
$ top # Real-time system stats (Ctrl+C to exit)
$ ps aux # List running processes
Text Editing: nano, vi
nano - Simple text editor (recommended for beginners):
$ nano filename.txt
# Edit, then press Ctrl+O (save), Ctrl+X (exit)
vi/vim - Powerful but steeper learning curve:
$ vi filename.txt
# Press 'i' to insert/edit
# Press Esc, then ':wq' to save and exit
# Press Esc, then ':q!' to exit without saving
Pipes and Redirects
Redirect output to file (> overwrites, >> appends):
$ ls > files.txt # Save output to file
$ echo "text" >> file.txt # Append to file
Pipe (|) - send output from one command to another:
$ ps aux | grep nginx # Find nginx process
$ ls -la | wc -l # Count files
Wildcards and Globbing
Common wildcards:
$ ls *.txt # All .txt files
$ ls file?.txt # file1.txt, file2.txt (single character)
$ ls [abc]*.txt # Files starting with a, b, or c
Don't remember a command's options? Use man commandname (e.g., man ls) to view the manual. Press 'q' to quit.
Related: Bash scripting | SSH connection | File permissions detailed
Need a developer-friendly server?
Use an UnderHost Cloud VPS for SSH, Git, Node.js, Python, Laravel, Docker, cron, and custom development workflows.





















