Command Line Fundamentals
Use a shell safely to navigate files, inspect a system, and understand command structure.
- Certification
- CompTIA A+
- Recommended study time
- 6h 10m
- Status
- Not started
Recommended study time
About 6h 10m in total, measured from the material on this page. At your session length of 45 minutes that is 9 sittings.
- Read the lesson20 min
About 2,597 words at a careful technical reading pace.
- Second pass with notes12 min
Re-read the harder parts and write your own notes.
- Work through the examples40 min
2 worked examples and 6 practice questions.
- Recall from memory12 min
2 written recall questions.
- Practice decision12 min
One applied decision with feedback.
- Teach it back20 min
Write the topic in your own words.
- Real-world scenario15 min
Read the situation and justify your decision in writing.
- Hands-on practice2h 40m
Labs, commands and configuration until you can do it unaided.
- Spaced review1h 20m
4 short review sessions spread over the following weeks.
Learning objectives
- Read a prompt and distinguish a command, option, argument, and path.
- Navigate directories and inspect files without relying on a graphical interface.
- Use help output and cautious habits before running unfamiliar commands.
Start here
About 22 minutes of reading, in 9 short parts.
The command line is the interface where professional IT work actually gets done: it is scriptable, remote-friendly, precise, and it leaves a record. This lesson teaches the structure of commands, the filesystem paths they operate on, and a working starter vocabulary in both Bash and PowerShell.
Where you meet it: Remote server sessions over SSH, Windows administration with PowerShell, network diagnostics, cloud shells, container work, and every automation task.
The lesson, part by part
Open one part at a time. Each part stands on its own, so you can stop and come back.
A shell is a program that reads a line of text, interprets it, asks the operating system to do the work, and prints the result. Bash is the standard Linux and macOS shell; PowerShell is the standard Windows administrative shell; cmd.exe survives as a legacy Windows shell.
The critical difference: Bash passes plain text between commands, while PowerShell passes .NET objects with named properties. That is why Bash pipelines lean on text tools such as grep, awk, and cut, and PowerShell pipelines use property names directly.
Key ideas
If you remember nothing else from this topic, remember these.
- Bash pipelines pass plain text between commands while PowerShell pipelines pass structured .NET objects with named properties, which is why PowerShell scripts filter on property names and Bash scripts filter on text patterns.
- Wildcards are expanded by the shell itself before the command ever sees them, meaning rm *.log never receives an asterisk at all, it receives a fully expanded list of matching filenames, which is exactly why an unintended match is dangerous.
- Every command returns an exit code where zero means success and anything else means failure, and automation that ignores that exit code silently continues after a failed step, which is one of the most common causes of broken scripts.
- Absolute paths behave identically no matter the current directory, while relative paths depend entirely on where you currently are, so printing your working directory before acting is the single cheapest way to avoid operating on the wrong files.
- Redirection operators send a command's streams somewhere other than the screen: greater-than overwrites a file, double greater-than appends, and the number 2 followed by greater-than captures error output specifically, separate from normal output.
- The PATH variable is simply an ordered list of directories the shell searches for executables, and a 'command not found' error usually means the program either does not exist, is misspelled, or exists but sits outside every directory on that list.
Finding and stopping a process that is saturating a Linux server's CPU
A worked example, step by step.
A colleague reports that a Linux web server has become unresponsive to new connections, and CPU usage appears very high in the monitoring dashboard.
- 01Connect and confirmSSH into the server, then run top to see live process activity sorted by CPU usage.
- 02Identify the processA process named backup-sync.sh is consuming 98 percent of one CPU core, with process ID 4821.
- 03Check what it is doingRun ps aux | grep 4821 to see the full command line, revealing it is running an unbounded find across the entire filesystem.
- 04Check disk and memory impact tooRun free -h and df -h to confirm memory is not also exhausted and the disk is not full, narrowing this specifically to a CPU-bound runaway process.
- 05Check logs for contextRun tail -n 50 /var/log/backup-sync.log to see it has been looping and retrying every few seconds since a scheduled job failed to exit cleanly overnight.
- 06Stop the process safelyRun kill 4821 to request a graceful stop; after ten seconds the process is still listed, so run kill -9 4821 to force termination.
- 07Verify the fixRun top again; CPU usage returns to a normal baseline near 5 percent and the web server begins accepting new connections again.
- 08Prevent recurrenceEdit the cron job with crontab -e to add a lock file check so the script cannot start a second overlapping run, then document the root cause and fix in the ticket.
Outcome: A runaway backup script that failed to exit was consuming an entire CPU core and starving the web server; identifying and force-killing the specific process ID restored service, and adding a lock check to the scheduled job prevented the same overlap from recurring.
Command-Line Facts Worth Memorising
Worth keeping at hand while you work.
- pwd / Get-Location
- Print the current working directory in Bash / PowerShell
- ls -la / Get-ChildItem -Force
- List all files including hidden ones
- chmod 644 file
- Owner read/write, group and others read-only
- chown user:group file
- Changes file ownership and group in Linux
- grep -ri pattern .
- Case-insensitive recursive text search from the current directory
- | (pipe)
- Sends one command's standard output into the next command's standard input
- $? in Bash
- Holds the exit code of the last command; 0 means success
- ss -tulpn
- Lists listening TCP/UDP ports and the process holding each one
- systemctl status <service>
- Shows whether a systemd-managed service is running, and recent log lines
- Test-NetConnection -Port
- PowerShell equivalent of testing whether a specific TCP port is reachable
- sudo vs Run as Administrator
- Elevates a single command on Linux versus elevating an entire session on Windows
- history / Get-History
- Shows previously run commands in the current shell session
Common misunderstandings
What most beginners get wrong here.
Typing rm -rf on a directory you are unsure about is fine because you can undo it later.
Neither rm -rf nor Remove-Item -Recurse -Force use a recycle bin; deletion is immediate and permanent, so listing the target first is the only real safeguard.
The command line is only for advanced users and GUI tools are always safer.
The command line is often the faster and more precise tool, especially for remote or headless systems with no GUI, and it produces an exact, reproducible record of what was done.
PowerShell pipelines work exactly like Bash pipelines, just with different command names.
PowerShell passes structured objects with properties between commands, while Bash passes plain text, so filtering syntax and mental model differ, not just vocabulary.
A script that runs without printing any errors definitely succeeded.
A script can silently continue after a failed step if its exit code is never checked, so absence of visible errors does not guarantee every command actually succeeded.
File and folder names behave the same way on Windows and Linux.
Linux filesystems are case-sensitive, so Config.yml and config.yml are different files, while Windows is generally case-insensitive, treating them as the same file.
Exam traps
How the question writers try to catch you out.
- Performance-based questions often require you to actually type the correct command for a stated outcome, so recognising a command in a list is not sufficient practice.
- Expect Linux and Windows command pairs to be tested together, such as being asked for the Windows equivalent of chmod or the Linux equivalent of Get-Process.
- A question describing a script that 'ran but had no effect' is often testing understanding of relative paths and current working directory, not syntax errors.
- Elevation questions expect you to know sudo elevates only the single command it prefixes, while Run as Administrator elevates the entire launched session.
- Redirection questions expect precise knowledge that greater-than overwrites while double greater-than appends, and that 2> specifically targets standard error, not standard output.
Check yourself
Answer in your head first, then reveal. This is not scored.
Why is it safer to list the files a wildcard matches before running a destructive command against that same wildcard?
What is the practical difference between how Bash and PowerShell pass data through a pipeline?
A script exits with code 1 but the automation continues to the next step anyway. What is the underlying problem?
On a headless Linux server, how would you find which process is currently listening on port 443?
Why does an unquoted path containing spaces commonly break a command?
Quick reference
A condensed summary of the lesson above, for revision.
What It Is
A shell is a program that reads commands and asks the operating system to perform them. A command usually contains an executable name followed by options that change behavior and arguments that name targets. Paths locate files or directories; absolute paths begin from the filesystem root, while relative paths begin from the current directory.
Why It Matters
Support, networking, cloud, and security tools frequently expose their full capability through a shell. Commands are easy to document and repeat, work over remote connections, and reveal exact output. Understanding command structure is more valuable than memorizing a long list because built-in help can explain unfamiliar tools.
How It Works
- A shell parses the command name, options, and arguments, then asks the OS to run it.
- The working directory provides the base for relative paths.
- Exit status and output report whether the operation succeeded.
Where You See It
- PowerShell administration, Linux shells, remote support, network tools, cloud consoles, and automation.
Key Terms
- Shell
- The command interpreter, such as PowerShell, Bash, or zsh.
- Prompt
- The indicator that a shell is ready to accept input.
- Option
- A modifier that changes how a command behaves.
- Argument
- A value or target supplied to a command.
- Working directory
- The directory used as the starting point for relative paths.
Examples
- A technician lists a log directory, changes into it, and reads a recent file without opening a desktop session.
- A network command displays the machine's address configuration so the result can be copied into a support ticket.
Common Problems
- Wrong working directory
- Misspelled command or path
- Missing permission
- Unsafe wildcard or destructive option
How It Fails
- A command may not exist in the current shell or PATH.
- Quoting errors can split one argument into several.
- Elevated commands can change the wrong target immediately.
How to Troubleshoot
- Read the exact error and confirm the current directory.
- Use built-in help and verify command syntax.
- Run a read-only inspection before a modifying command.
Practical Knowledge
- Use pwd/Get-Location, ls/Get-ChildItem, cd/Set-Location, and help safely.
- Quote paths containing spaces and use least privilege.
Exam Coverage
- Commands, options, arguments, and paths
- Navigation and file inspection
- Safe administrative practice
Interview Questions
- What is the difference between an absolute and relative path?
- How do you approach an unfamiliar command safely?
Worked examples
Each calculation is shown one step at a time, then you try it yourself before revealing the answer.
Read and set Linux file permissions
A script shows as -rwxr-xr-- . What are its numeric permissions, and what command would make it rwxr-x---?
- 1. Split the stringIgnore the leading file-type character, then take three groups: owner rwx, group r-x, others r--.
- 2. Score each groupread = 4, write = 2, execute = 1. Owner 4+2+1 = 7. Group 4+0+1 = 5. Others 4+0+0 = 4.
- 3. Read the numberThe permissions are 754.
- 4. Build the targetrwx = 7, r-x = 5, --- = 0, so the goal is 750.
Answer: -rwxr-xr-- is 754; chmod 750 script.sh produces rwxr-x---. A 'Permission denied' on your own script is usually a missing execute bit (chmod +x).
Now you try
What is rw-r--r-- numerically?
What does chmod 600 key.pem allow?
Which command changes the owning user?
Build a command line pipeline
Find every failed SSH login in /var/log/auth.log and count them per source address.
- 1. Filter the linesgrep 'Failed password' /var/log/auth.log narrows thousands of lines to the ones that matter.
- 2. Extract the fieldPipe into awk '{print $(NF-3)}' to pull the source IP from each line.
- 3. Group themsort groups identical addresses together; uniq -c then counts each group.
- 4. Rank themsort -nr puts the noisiest address at the top.
Answer: grep 'Failed password' /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr — each command does one job and the pipe passes text along.
Now you try
How would you keep the output for a ticket?
Which command shows a log as it is being written?
What does | actually do?
Watch and read
Verified official and reputable sources for this topic. Links open in a new tab.
Video training
Reading and courses
Lesson notes and bookmark
Notes and bookmarks for this lesson, saved with everything else you have marked.
No notes on this item yet.
Learning progress
0% across six evidence areas. Reading alone does not change progress.
Prerequisites
Next steps
- 01Practice displaying the current directory and listing its contents.
- 02Use a command's built-in help before trying options you do not recognize.