Online admissions open for the SEO, web development and networking & cybersecurity courses. Enquire for the next batch.

The Command Line for Beginners: Terminal, Shell and Essential Commands

5 min read Updated By the SkillNewton team

What is the command line?

The command line is a text interface where you type commands for the operating system to run, instead of clicking icons. A terminal is the window that shows the text, and a shell such as bash, zsh or PowerShell is the program that reads your commands and runs them. Developers use it to manage files, run code and automate tasks.

Terminal, shell and prompt: the key terms

  • Terminal (terminal emulator): the application window, such as Windows Terminal, macOS Terminal or GNOME Terminal.
  • Shell: the command interpreter running inside it. bash is common on Linux, zsh is the default on macOS, and PowerShell is the modern shell on Windows.
  • Prompt: the text before your cursor, often showing the user and current folder, ending in $ (bash), % (zsh) or > (PowerShell).
  • Command, options and arguments: in ls -l /etc, ls is the command, -l an option and /etc an argument.

On Windows you can also run bash through WSL (Windows Subsystem for Linux) or Git Bash, which is useful because most server documentation assumes a Linux shell.

Paths and navigation

Every file has a path. An absolute path starts from the root (/home/asha/notes.txt on Linux, C:\Users\Asha\notes.txt on Windows). A relative path starts from your current folder. . means the current folder, .. the parent and ~ your home folder.

pwd                 # print working directory
ls                  # list files
ls -la              # long listing, including hidden files
cd projects         # move into a folder (relative path)
cd ..               # up one level
cd ~                # home folder
cd /var/log         # absolute path

Getting help for any command

You rarely need to memorise options. On Linux and macOS, man ls opens the manual page and most tools also accept --help. In PowerShell, Get-Help Get-ChildItem shows the documentation for a cmdlet. Linux and macOS paths are case-sensitive and use forward slashes; Windows paths are case-insensitive and traditionally use backslashes, although PowerShell accepts forward slashes as well.

Working with files and folders

mkdir -p site/css          # create folders, including parents
touch site/index.html      # create an empty file
cp site/index.html backup.html
mv backup.html old.html    # move or rename
cat site/index.html        # print a file
less /var/log/syslog       # page through a long file (q quits)
head -n 5 data.csv         # first five lines
rm old.html                # delete a file: no recycle bin
rm -r site                 # delete a folder and its contents

rm deletes permanently. Run ls on the same path first to confirm what you are about to remove. Our Linux commands guide lists many more commands for system administration.

Pipes and redirection

Every command has standard input, standard output and standard error. A pipe (|) sends one command's output into the next command's input. Redirection sends output to a file instead of the screen.

SymbolMeaningExample
|Pipe output to another commandls | wc -l
>Write output to a file (overwrites)ls > files.txt
>>Append output to a filedate >> log.txt
<Read input from a filesort < names.txt
2>Redirect error messagespython app.py 2> errors.txt
2>&1Send errors to the same place as outputmake > build.log 2>&1

Redirection works in PowerShell too, with the same |, > and >> symbols. The difference is that PowerShell pipes objects rather than plain text, so commands such as Get-ChildItem | Sort-Object Length sort by a real property instead of parsing columns.

# count how many lines in access.log contain "404"
grep "404" access.log | wc -l

# five most common IP addresses in the first column
cut -d " " -f 1 access.log | sort | uniq -c | sort -rn | head -n 5

Chaining small tools like this is the core idea of the Unix command line. grep searches with patterns; our regular expressions guide explains the syntax.

Environment variables and the PATH

An environment variable is a named value that the shell passes to every program it starts. PATH is the most important one: it lists the folders the shell searches when you type a command name. If a newly installed tool gives "command not found", its folder is usually missing from PATH.

# bash / zsh
echo $HOME
echo $PATH
export APP_ENV=development     # set for this session
APP_ENV=test python app.py     # set for one command only

# PowerShell
$env:Path
$env:APP_ENV = "development"

Variables set this way last only for the current terminal session. To make them permanent, add the export line to ~/.bashrc or ~/.zshrc, or use the Windows environment variables settings. Keep secrets such as API keys out of scripts you commit to Git.

PowerShell and bash equivalents

PowerShell defines aliases such as ls, cd and cat, so many basic commands look familiar, but the underlying cmdlets work on objects rather than text and accept different options.

TaskbashPowerShell
Current folderpwdGet-Location
List filesls -laGet-ChildItem -Force
Change foldercd pathSet-Location path
Show a filecat file.txtGet-Content file.txt
Copycp a bCopy-Item a b
Move or renamemv a bMove-Item a b
Delete folderrm -r dirRemove-Item dir -Recurse
New foldermkdir -p a/bNew-Item -ItemType Directory a/b
Search textgrep "error" app.logSelect-String "error" app.log
Read a variableecho $HOME$env:USERPROFILE
Find a commandwhich python3Get-Command python

Practical exercise: organise a project folder from the terminal

  1. Open a terminal and use cd ~ then mkdir -p practice/logs practice/src to create a folder structure.
  2. Move into practice and create three files in src with touch (or New-Item in PowerShell).
  3. Run ls -R > inventory.txt and view the result with cat.
  4. Append the date with date >> inventory.txt.
  5. Use a pipe to count the entries in src: ls src | wc -l.
  6. Set an environment variable called PROJECT to practice and print it.
  • Done looks like this: inventory.txt lists both folders and the three files with a date at the end, and the count prints 3.
  • Extension: repeat every step in PowerShell using the table above.

The command line is central to working with servers and networks; the Networking Foundation course uses it throughout, and debugging techniques often start with reading terminal output.

Common mistakes

  • Running rm -r on a path without checking it first, since the shell has no undo.
  • Using > when you meant >>, which overwrites a file instead of appending to it.
  • Forgetting to quote paths that contain spaces, so the shell treats them as two separate arguments.
  • Pasting commands from the internet with sudo without understanding what they do.
  • Expecting an export or $env: setting to survive after the terminal is closed.

Frequently asked questions

Is Command Prompt the same as PowerShell?

No. Command Prompt (cmd.exe) is the older Windows shell with its own commands such as dir and copy. PowerShell is newer, object-based and far more capable for scripting.

What is the difference between bash and zsh?

Both are Unix shells with very similar syntax for everyday commands. zsh adds richer completion and customisation and is the default on macOS; bash is the usual default on Linux servers.

What does sudo do?

On Linux and macOS, sudo runs a single command with administrator rights after asking for your password. Use it only when a command genuinely needs those rights.

Do I need the command line to learn programming?

You can start in an editor, but you will soon need it to run scripts, install packages, use Git and deploy code, so learning the basics early pays off.

Want to Learn This Properly?

The Networking & Cybersecurity: Foundation & Practical Implementation (Online) turns guides like this into practised skills, with projects on real websites.

WhatsApp Call Us Now

Free counselling

Send an Enquiry

Tell us which course you are interested in. We reply by email or phone with the next batch and how to enrol.

Protected by reCAPTCHA. Google Privacy and Terms apply.

We reply by email or phone within working hours. No spam.