Lesson 4 · Fundamentals

Basic Commands & Navigation

Master the essential Linux commands every administrator needs to know.

Navigation Commands

pwd

Print Working Directory - shows your current location in the filesystem.

$ pwd
/home/pranav
cd [directory]

Change Directory - navigate to a different location.

$ cd /var/log
$ cd .. # Go up one level
$ cd ~ # Go to home directory
$ cd - # Go to previous directory
ls [options] [path]

List directory contents with various formatting options.

$ ls # Basic listing
$ ls -l # Long format with details
$ ls -la # Include hidden files
$ ls -lh # Human-readable sizes

File Operations

cp [source] [destination]

Copy files and directories.

$ cp file.txt backup.txt
$ cp -r folder/ backup/ # Copy directory recursively
mv [source] [destination]

Move or rename files and directories.

$ mv old.txt new.txt # Rename
$ mv file.txt /backup/ # Move
rm [options] [file]

Remove files and directories. Use with caution!

$ rm file.txt
$ rm -r folder/ # Remove directory
$ rm -i file.txt # Prompt before deletion
mkdir [directory]

Create new directories.

$ mkdir projects
$ mkdir -p a/b/c # Create nested directories

Viewing File Contents

cat [file]

Display entire file contents.

head -n [lines] [file]

Display first N lines of a file (default: 10).

tail -n [lines] [file]

Display last N lines. Use -f to follow log files in real-time.

less [file]

View large files with pagination. Press q to quit.

Searching: find + grep

Two of the most valuable admin skills are (1) finding the right file and (2) finding the right line. Use find for files and grep for content.

# Find files by name
$ find /var/log -name \"*.log\" 2>/dev/null | head

# Find files modified in last 24h
$ find /etc -type f -mtime -1 2>/dev/null | head

# Search for a string inside files
$ grep -R \"PermitRootLogin\" /etc/ssh 2>/dev/null
$ grep -n \"error\" /var/log/syslog | tail

Pipes and Redirection (Linux Superpower)

The shell lets you connect commands like building blocks. This is why Linux admins can solve problems fast.

# stdout (>) and append (>>)
$ echo \"hello\" > file.txt
$ echo \"world\" >> file.txt

# stderr redirection (2>)
$ find / -name \"*.log\" 2> errors.txt

# Pipes: pass output to next command
$ ps aux | grep nginx
$ journalctl -u ssh | tail -50

# tee: write to file + keep output on screen
$ uname -a | tee system.txt

Getting Help Fast

If you can read man pages, you can learn anything in Linux.

$ man cp
$ cp --help | head
$ man -k \"disk usage\" | head

Common Gotchas

  • Spaces in filenames: quote paths: cp \"My File.txt\" /tmp/
  • rm is permanent: there’s no recycle bin on most servers. Use rm -i for safety.
  • Copying directories: you need cp -r (or use rsync for serious work).

✅ Practice (15–20 minutes)

  • Create a directory tree with mkdir -p, then copy it to a backup location.
  • Find all files ending in .conf under /etc and count them.
  • Search your SSH config for key settings like PermitRootLogin.

💡 Pro Tip

Use tab completion to autocomplete file and directory names. Press Tab once for completion, twice to see all options.