Opening the Terminal

The terminal (also called a shell, console, or command line) is a text-based interface where you type commands for the operating system to execute. On most Linux desktops, you can open a terminal with the keyboard shortcut Ctrl + Alt + T, or by searching for "Terminal" in your application menu.

When you open the terminal, you will see a prompt that typically looks like this:

username@hostname:~$

This tells you your username, the computer's hostname, the current directory (~ means your home directory), and the privilege level ($ for normal user, # for root).

Navigating the file system is the most fundamental skill. These commands let you move around and see what is where:

CommandDescriptionExample
pwdPrint working directory — shows your current locationpwd → /home/user
lsList files and directories in the current locationls -la
cdChange directory — move to a different locationcd /var/log
cd ..Move up one directory levelcd ..
cd ~Go to your home directory from anywherecd ~
cd -Go back to the previous directorycd -

Understanding ls Options

The ls command becomes much more powerful with flags:

# Long format with details (permissions, owner, size, date)
ls -l

# Show hidden files (those starting with a dot)
ls -a

# Combine both: long format + hidden files
ls -la

# Human-readable file sizes (KB, MB, GB)
ls -lh

# Sort by modification time (newest first)
ls -lt

# Recursive listing (include subdirectories)
ls -R

File Management

These commands let you create, copy, move, rename, and delete files and directories:

CommandDescriptionExample
touchCreate an empty file or update timestamptouch newfile.txt
mkdirCreate a new directorymkdir projects
mkdir -pCreate nested directoriesmkdir -p a/b/c
cpCopy files or directoriescp file.txt backup.txt
cp -rCopy directories recursivelycp -r dir1 dir2
mvMove or rename files/directoriesmv old.txt new.txt
rmRemove (delete) filesrm unwanted.txt
rm -rRemove directories recursivelyrm -r old_folder
rmdirRemove empty directoriesrmdir empty_dir

Be Careful with rm

The rm command permanently deletes files — there is no recycle bin in the terminal. Always double-check before using rm -rf. Consider using rm -i (interactive mode) which asks for confirmation before each deletion, especially when learning.

Viewing and Editing Files

Reading file contents is something you will do constantly on Linux:

# Display entire file contents
cat filename.txt

# View file with pagination (scroll with Space, quit with q)
less filename.txt

# Display first 10 lines (or specify a number)
head filename.txt
head -20 filename.txt

# Display last 10 lines
tail filename.txt

# Follow a file in real-time (great for logs)
tail -f /var/log/syslog

# Count lines, words, and characters
wc filename.txt
wc -l filename.txt    # lines only

Text Editors in the Terminal

Linux offers several terminal-based text editors:

  • nano — Beginner-friendly editor with on-screen shortcut hints. Open with nano filename.txt. Save with Ctrl+O, exit with Ctrl+X.
  • vim — Powerful modal editor with a steep learning curve. Highly efficient once mastered. Open with vim filename.txt. Press i to enter insert mode, Esc then :wq to save and quit.
  • vi — The classic Unix editor, available on virtually every system. Similar to vim but with fewer features.

Searching and Finding

Quickly locating files and content is essential for efficient system management:

# Find files by name
find /home -name "*.txt"

# Find files modified in the last 7 days
find /var/log -mtime -7

# Find files larger than 100MB
find / -size +100M -type f

# Search for text inside files
grep "error" /var/log/syslog

# Recursive search through directories
grep -r "function" /home/user/project/

# Case-insensitive search
grep -i "warning" logfile.txt

# Show line numbers with matches
grep -n "TODO" *.py

Pipes and Redirection

Pipes and redirection are fundamental concepts that let you chain commands and control input/output:

Pipes ( | )

Pipes send the output of one command as input to another:

# Count number of files in a directory
ls -1 | wc -l

# Find a specific process
ps aux | grep nginx

# Sort and display unique lines
cat names.txt | sort | uniq

# View long output with pagination
dmesg | less

Redirection

# Write output to a file (overwrites)
echo "Hello World" > output.txt

# Append output to a file
echo "Another line" >> output.txt

# Redirect errors to a file
command 2> errors.log

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

# Discard output completely
command > /dev/null 2>&1

System Information Commands

# Display system information
uname -a

# Show disk usage
df -h

# Show directory size
du -sh /var/log

# Display memory usage
free -h

# Show running processes
ps aux
top
htop    # interactive (install separately)

# Display network information
ip addr show
ip route show

# Show current date and time
date

# Show system uptime
uptime

# Show who is logged in
who
w

Helpful Keyboard Shortcuts

ShortcutAction
TabAuto-complete commands, filenames, and paths
Ctrl + CCancel/interrupt the current running command
Ctrl + ZSuspend the current process (resume with fg)
Ctrl + DLog out of the current shell / end input
Ctrl + LClear the terminal screen (same as clear)
Ctrl + RSearch through command history
Up/Down ArrowNavigate through previous commands
Ctrl + AMove cursor to the beginning of the line
Ctrl + EMove cursor to the end of the line
!!Repeat the last command (useful with sudo !!)

Getting Help

Linux has excellent built-in documentation:

# Manual pages - comprehensive documentation
man ls
man grep

# Quick help - most commands support --help
ls --help
grep --help

# One-line command description
whatis ls

# Search for commands by description
apropos "copy files"

# Info pages (alternative to man)
info coreutils

Practice Makes Perfect

The best way to learn the command line is by using it daily. Start by navigating your file system, creating and organizing files, and gradually incorporate more advanced commands into your workflow. Next, explore the Linux File System to understand the directory structure you are navigating.