Command Line
Linux/Mac Command Line Cheat Sheet
A comprehensive Linux and Mac command line cheat sheet for beginners covering navigation, file management, text search, scripting, networking, and practical examples.

Access this command line cheat sheet for quick reference to essential Linux and Mac terminal commands. It covers file management, navigation, viewing and editing files, searching text, scripting basics, networking commands, and practical command examples.
For QA engineers and automation students, terminal confidence matters. You will use the command line to run tests, inspect logs, manage files, work with Git, start Docker containers, connect to servers, and debug automation projects.
Table Of Contents
- Command Line Cheat Sheet
- Navigating The File System
- File And Directory Management
- Viewing And Editing Files
- Searching And Filtering Text
- Scripting Basics
- Command Line For Networking
- Command Line Tools And Utilities
- Commands And Examples
- Tail Command Tutorial
- Grep Command Tutorial
Command Line Cheat Sheet
Navigating The File System
| Command | What It Does | Example |
|---|---|---|
pwd | Print the current working directory. | pwd |
ls | List directory contents. | ls -l |
ls -a | List all files, including hidden files. | ls -a |
cd | Change the current directory. | cd /home/user |
cd .. | Move up one directory. | cd .. |
touch | Create a new empty file. | touch newfile.txt |
clear | Clear the terminal screen. | clear |
pwd
ls -l
ls -la
cd /home/user
cd ..
touch newfile.txt
clear
File And Directory Management
| Command | What It Does | Example |
|---|---|---|
mkdir | Create a new directory. | mkdir new_folder |
mkdir -p | Create nested directories. | mkdir -p new_folder/nested_folder |
rm | Remove a file. | rm file.txt |
rm -r | Remove a directory and its contents. | rm -r folder |
mv | Move or rename files and directories. | mv old_name.txt new_name.txt |
cp | Copy files. | cp file.txt copy_of_file.txt |
cp -r | Copy directories recursively. | cp -r dir1 dir2 |
mkdir new_folder
mkdir -p new_folder/nested_folder
rm file.txt
rm -r folder
mv old_name.txt new_name.txt
mv file.txt /new/location/
cp file.txt copy_of_file.txt
cp -r dir1 dir2
Viewing And Editing Files
| Command | What It Does | Example |
|---|---|---|
cat | Display file content. | cat file.txt |
cat file1 file2 | Display multiple files. | cat file1.txt file2.txt |
nano | Open a simple terminal text editor. | nano file.txt |
less | View a file one screen at a time. | less file.txt |
head | Show the first part of a file. | head file.txt |
head -n | Show a specific number of starting lines. | head -n 20 file.txt |
tail | Show the last part of a file. | tail file.txt |
tail -n | Show a specific number of ending lines. | tail -n 20 file.txt |
tail -f | Follow file changes in real time. | tail -f file.txt |
cat file.txt
cat file1.txt file2.txt
nano file.txt
less file.txt
head file.txt
head -n 20 file.txt
tail file.txt
tail -n 20 file.txt
tail -f file.txt
Searching And Filtering Text
| Command | What It Does | Example |
|---|---|---|
grep | Search for text in a file. | grep "search_term" file.txt |
grep -i | Search case-insensitively. | grep -i "search_term" file.txt |
grep -r | Search recursively through a directory. | grep -r "search_term" /path/to/directory |
grep -ri | Recursive case-insensitive search. | grep -ri "search_term" /path/to/directory |
grep -rl | Show only file names with matches. | grep -rl "search_term" /path/to/directory |
find | Search for files in a directory hierarchy. | find /path -name "filename" |
find . -type f | Find files by pattern. | find . -type f -name "*.txt" |
awk | Process columns and patterns. | awk '{print $1}' file.txt |
sed | Filter and transform text. | sed 's/old/new/g' file.txt |
grep "search_term" file.txt
grep -i "search_term" file.txt
grep -r "search_term" /path/to/directory
grep -ri "search_term" /path/to/directory
grep -rl "search_term" /path/to/directory
find /path -name "filename"
find . -type f -name "*.txt"
awk '{print $1}' file.txt
sed 's/old/new/g' file.txt
Scripting Basics
| Command | What It Does | Example |
|---|---|---|
bash | Execute a bash script. | bash script.sh |
bash -x | Run a script in debug mode. | bash -x script.sh |
sh | Execute a shell script. | sh script.sh |
sh -v | Run a shell script in verbose mode. | sh -v script.sh |
bash script.sh
bash -x script.sh
sh script.sh
sh -v script.sh
Command Line For Networking
| Command | What It Does | Example |
|---|---|---|
ping | Test network connectivity. | ping google.com |
ping -c | Limit ping to a specific number of packets. | ping -c 4 google.com |
ssh | Log in to another host over SSH. | ssh user@hostname |
ssh -i | Use a specific SSH key. | ssh -i ~/.ssh/id_rsa user@hostname |
ping google.com
ping -c 4 google.com
ssh user@hostname
ssh -i ~/.ssh/id_rsa user@hostname
Command Line Tools And Utilities
| Command | What It Does | Example |
|---|---|---|
tar -cvf | Create a tar archive. | tar -cvf archive.tar file1 file2 |
tar -xvf | Extract a tar archive. | tar -xvf archive.tar |
tar -cvf archive.tar file1 file2
tar -xvf archive.tar
Commands And Examples
The cheat sheet above gives quick command references. The examples below explain how to use important commands in real workflows.
Tail Command Tutorial
The tail command displays the last part of a file. It is especially useful for monitoring log files that are constantly being updated.
Basic Usage: View The Last 10 Lines
tail filename
This displays the last 10 lines of filename. It is useful when you want to quickly check the newest content in a log file or configuration file without opening the whole file.
Customize Line Count
tail -n 100 filename
The -n flag lets you specify exactly how many lines you want to see from the end of the file. For example, tail -n 100 filename shows the last 100 lines.
This is useful when you need more context than the default 10 lines but do not want to read the whole file.
Follow A File In Real Time
tail -n 100 -f filename
The -f flag puts tail into follow mode. Instead of showing the current end of the file and exiting, it keeps watching the file and displays new lines as they are added.
This is one of the most useful commands for QA and debugging. For example, if a web application is writing to app.log, you can run:
tail -n 100 -f app.log
You will see the last 100 log entries first, then new log entries will appear live as the app runs.
Use this when:
- Monitoring test logs
- Watching server logs
- Debugging application behavior
- Confirming whether an action triggers expected backend events
Stop following the file with Ctrl+C.
Grep Command Tutorial
The grep command searches for text patterns inside files and command output. It is one of the most useful tools for debugging, log analysis, and searching through code.
Search In A Single File
grep "search_term" file.txt
This searches for the exact text search_term inside file.txt and prints matching lines. The search is case-sensitive by default, so Error and error are different matches.
Example:
grep "ERROR" app.log
This shows every line in app.log that contains ERROR.
Case-Insensitive Search
grep -i "search_term" file.txt
The -i flag ignores letter case. This means it matches error, Error, ERROR, and other case variations.
Example:
grep -i "error" app.log
Use this when logs or files are inconsistent about capitalization.
Recursive Directory Search
grep -r "search_term" /path/to/directory
The -r flag searches recursively through all files in the directory and its subdirectories.
Example:
grep -r "function_name" /path/to/project
This is useful when searching through a codebase for a function, setting, test name, endpoint, or error message.
Recursive Case-Insensitive Search
grep -ri "search_term" /path/to/directory
You can combine flags. The -ri combination searches recursively and ignores case.
Example:
grep -ri "database" /path/to/project
This finds database, Database, DATABASE, and other case variations across the project.
Show Only File Names With Matches
grep -rl "search_term" /path/to/directory
The -l flag shows only file names that contain matches instead of printing every matching line.
Example:
grep -rl "TODO" /path/to/project
This lists every file that contains TODO.
Filter Command Output With Grep
You can combine grep with other commands using pipes:
ls -la | grep ".txt"
This filters the directory listing and only shows lines containing .txt.
Free Software Testing Fundamentals
If you are learning the command line because you want to move into QA or automation, start with the testing foundations too.
The free Software Testing Fundamentals course covers:
- Testing basics, test cases, bug reporting, and core QA concepts
- SQL and database testing
- API testing
- Jira and real team workflows
