Show description
EEE120 Command Line Cheat Sheet
EEE120 Command Line Cheat Sheet
EEE120 Terminal Cheat Sheet 🖥️
Your guide to Bash (macOS/Linux) and PowerShell (Windows) commands.
macOS (Bash/Zsh)
Linux (Bash)
Windows (PowerShell)
Navigation & Info
pwd
Print Working Directory (shows where you are).
whoami
Shows your account username.
cd [dir]
Change Directory. Use cd .. to go up, cd to go home.
cd -
Go to the previous directory you were in.
ls
List files and directories.
ls -l
List with long format (permissions, owner, size).
ls -a
List all files (including hidden . files).
ls -alF
Combine flags: all, long, F (adds / to dirs).
history
Shows command history. history -75 shows last 75.
Up Arrow
Scroll through last-used commands.
Tab
Auto-completes filenames or commands.
clear
Clears the terminal screen.
man [cmd]
Shows the manual for a command (e.g., man ls).
which [cmd]
Shows the full path to a command (e.g., which ls).
File & Directory Manipulation
mkdir [name]
Make a new directory.
touch [file]
Creates a new, empty file (or updates timestamp).
cp [src] [dest]
Copy a file. (e.g., cp hi.txt bye.txt).
cp -r [src] [dest]
Copy recursively (copies a whole directory).
mv [src] [dest]
Move a file or directory. Also used to rename files.
rm [file]
Remove a file. Be careful! This is permanent.
rmdir [dir]
Remove an empty directory.
rm -r [dir]
Remove a directory recursively (and all its contents).
ln [target] [link]
Creates a hard link between two files.
ln -s [target] [link]
Creates a symbolic link (a "shortcut"). More common.
Viewing & Reading Files
echo "text"
Prints "text" to the terminal.
cat [file]
Concatenate. Dumps the entire file content to the screen.
cat f1.txt f2.txt
Combines and prints two files.
more [file]
View a file one page at a time (scroll down only).
less [file]
View a file one page at a time (scroll up and down).…
EEE120 Command Line Cheat Sheet
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EEE120 Command Line Cheat Sheet</title>
<style>
/* --- shadcn-inspired B&W Theme --- */
:root {
--background: #ffffff;
--foreground: #09090b;
--card: #fdfdfd;
--card-foreground: #09090b;
--popover: #ffffff;
--popover-foreground: #09090b;
--primary: #09090b;
--primary-foreground: #fafafa;
--secondary: #f4f4f5;
--secondary-foreground: #18181b;
--muted: #f4f4f5;
--muted-foreground: #71717a;
--accent: #f4f4f5;
--accent-foreground: #18181b;
--destructive: #ef4444;
--destructive-foreground: #fafafa;
--border: #e4e4e7;
--input: #e4e4e7;
--ring: #09090b;
--radius: 0.5rem;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background-color: var(--background);
color: var(--foreground);
line-height: 1.6;
padding: 2rem;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
main {
max-width: 1200px;
margin: 0 auto;
}
header {
text-align: center;
margin-bottom: 2.5rem;
border-bottom: 1px solid var(--border);
padding-bottom: 1.5rem;
}
header h1 {
font-size: 2.5rem;
font-weight: 700;
letter-spacing: -0.025em;
}
header p {
font-size: 1.125rem;
color: var(--muted-foreground);
}
/* --- Tab Navigation --- */
.tabs {
display: flex;
justify-content: center;
border-bottom: 1px solid var(--border);
margin-bottom: 2rem;
}
.tab-button {
padding: 0.75rem 1.5rem;
font-size: 1rem;
font-weight: 500;
background: none;
border: none;
border-bottom: 2px solid transparent;
cursor: pointer;
color: var(--muted-foreground);
transition: all 0.2s ease-in-out;
}
.tab-button[aria-selected="true"] {
color: var(--foreground);
border-bottom-color: var(--primary);
}
.tab-button:hover:not([aria-selected="true"]) {
color: var(--foreground);
background-color: var(--accent);
}
/* --- Content Sections --- */
.tab-content {
display: none;
}
.tab-content[aria-hidden="false"] {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
gap: 1.5rem;
}
/* --- Cards --- */
.card {
background-color: var(--card);
border: 1px solid var(--border);
border-radius: var(--radius);
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
.card-header {
padding: 1rem 1.5rem;
border-bottom: 1px solid var(--border);
}
.card-header h2 {
font-size: 1.25rem;
font-weight: 600;
margin: 0;
}
.card-content {
padding: 1.5rem;
}
.card-content table {
width: 100%;
border-collapse: collapse;
font-size: 0.95rem;
}
.card-content th,
.card-content td {
text-align: left;
padding: 0.75rem 0.5rem;
border-bottom: 1px solid var(--border);
}
.card-content tr:last-child td {
border-bottom: none;
}
.card-content th {
color: var(--muted-foreground);
font-weight: 500;
font-size: 0.9rem;
}
/* --- Code & Preformatted Text --- */
code {
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
background-color: var(--secondary);
color: var(--secondary-foreground);
padding: 0.2rem 0.4rem;
border-radius: 0.3rem;
font-size: 0.9em;
}
td:first-child code {
white-space: nowrap;
}
pre {
background-color: var(--secondary);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 1rem;
overflow-x: auto;
font-size: 0.9rem;
}
pre code {
background: none;
padding: 0;
border-radius: 0;
font-size: 1em;
}
footer {
text-align: center;
margin-top: 3rem;
padding-top: 1.5rem;
border-top: 1px solid var(--border);
color: var(--muted-foreground);
font-size: 0.9rem;
}
</style>
</head>
<body>
<main>
<header>
<h1>EEE120 Terminal Cheat Sheet 🖥️</h1>
<p>Your guide to Bash (macOS/Linux) and PowerShell (Windows) commands.</p>
</header>
<nav class="tabs" role="tablist">
<button class="tab-button" role="tab" aria-selected="true" data-tab="mac">macOS (Bash/Zsh)</button>
<button class="tab-button" role="tab" data-tab="linux">Linux (Bash)</button>
<button class="tab-button" role="tab" data-tab="windows">Windows (PowerShell)</button>
</nav>
<section id="mac" class="tab-content" role="tabpanel" aria-hidden="false">
<div class="card">
<div class="card-header"><h2>Navigation & Info</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>pwd</code></td>
<td><b>P</b>rint <b>W</b>orking <b>D</b>irectory (shows where you are).</td>
</tr>
<tr>
<td><code>whoami</code></td>
<td>Shows your account username.</td>
</tr>
<tr>
<td><code>cd [dir]</code></td>
<td><b>C</b>hange <b>D</b>irectory. Use <code>cd ..</code> to go up, <code>cd</code> to go home.</td>
</tr>
<tr>
<td><code>cd -</code></td>
<td>Go to the previous directory you were in.</td>
</tr>
<tr>
<td><code>ls</code></td>
<td><b>L</b>i<b>s</b>t files and directories.</td>
</tr>
<tr>
<td><code>ls -l</code></td>
<td>List with <b>l</b>ong format (permissions, owner, size).</td>
</tr>
<tr>
<td><code>ls -a</code></td>
<td>List <b>a</b>ll files (including hidden <code>.</code> files).</td>
</tr>
<tr>
<td><code>ls -alF</code></td>
<td>Combine flags: <b>a</b>ll, <b>l</b>ong, <b>F</b> (adds <code>/</code> to dirs).</td>
</tr>
<tr>
<td><code>history</code></td>
<td>Shows command history. <code>history -75</code> shows last 75.</td>
</tr>
<tr>
<td><code>Up Arrow</code></td>
<td>Scroll through last-used commands.</td>
</tr>
<tr>
<td><code>Tab</code></td>
<td>Auto-completes filenames or commands.</td>
</tr>
<tr>
<td><code>clear</code></td>
<td>Clears the terminal screen.</td>
</tr>
<tr>
<td><code>man [cmd]</code></td>
<td>Shows the <b>man</b>ual for a command (e.g., <code>man ls</code>).</td>
</tr>
<tr>
<td><code>which [cmd]</code></td>
<td>Shows the full path to a command (e.g., <code>which ls</code>).</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>File & Directory Manipulation</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>mkdir [name]</code></td>
<td><b>M</b>a<b>k</b>e a new <b>dir</b>ectory.</td>
</tr>
<tr>
<td><code>touch [file]</code></td>
<td>Creates a new, empty file (or updates timestamp).</td>
</tr>
<tr>
<td><code>cp [src] [dest]</code></td>
<td><b>C</b>o<b>p</b>y a file. (e.g., <code>cp hi.txt bye.txt</code>).</td>
</tr>
<tr>
<td><code>cp -r [src] [dest]</code></td>
<td><b>C</b>opy <b>r</b>ecursively (copies a whole directory).</td>
</tr>
<tr>
<td><code>mv [src] [dest]</code></td>
<td><b>M</b>o<b>v</b>e a file or directory. Also used to rename files.</td>
</tr>
<tr>
<td><code>rm [file]</code></td>
<td><b>R</b>e<b>m</b>ove a file. <b>Be careful! This is permanent.</b></td>
</tr>
<tr>
<td><code>rmdir [dir]</code></td>
<td><b>R</b>e<b>m</b>ove an <i>empty</i> <b>dir</b>ectory.</td>
</tr>
<tr>
<td><code>rm -r [dir]</code></td>
<td><b>R</b>emove a directory <b>r</b>ecursively (and all its contents).</td>
</tr>
<tr>
<td><code>ln [target] [link]</code></td>
<td>Creates a hard <b>l</b>i<b>n</b>k between two files.</td>
</tr>
<tr>
<td><code>ln -s [target] [link]</code></td>
<td>Creates a <b>s</b>ymbolic link (a "shortcut"). More common.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Viewing & Reading Files</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>echo "text"</code></td>
<td>Prints "text" to the terminal.</td>
</tr>
<tr>
<td><code>cat [file]</code></td>
<td>Con<b>cat</b>enate. Dumps the entire file content to the screen.</td>
</tr>
<tr>
<td><code>cat f1.txt f2.txt</code></td>
<td>Combines and prints two files.</td>
</tr>
<tr>
<td><code>more [file]</code></td>
<td>View a file one page at a time (scroll down only).</td>
</tr>
<tr>
<td><code>less [file]</code></td>
<td>View a file one page at a time (scroll up and down). (<code>more</code> is <code>less</code>!)</td>
</tr>
<tr>
<td><code>head [file]</code></td>
<td>Shows the first 10 lines of a file.</td>
</tr>
<tr>
<td><code>tail [file]</code></td>
<td>Shows the last 10 lines of a file.</td>
</tr>
<tr>
<td><code>nano [file]</code></td>
<td>Opens the <code>nano</code> text editor to create or edit a file.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Search, Sort & Redirects</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>find . -name "f.txt"</code></td>
<td><b>Find</b>s files with <code>-name</code> starting from <code>.</code> (current dir).</td>
</tr>
<tr>
<td><code>grep "term" [file]</code></td>
<td>Searches for "term" inside a file.</td>
</tr>
<tr>
<td><code>grep -r "term" .</code></td>
<td>Searches <b>r</b>ecursively for "term" in all files in current dir.</td>
</tr>
<tr>
<td><code>sort [file]</code></td>
<td>Sorts the lines of a file alphabetically.</td>
</tr>
<tr>
<td><code>|</code> (Pipe)</td>
<td><b>Pipeline</b>. Uses the output of one command as the input for another.</td>
</tr>
<tr>
<td><code>sort f.txt | grep "e"</code></td>
<td>Example: <b>sorts</b> the file, then <b>pipes</b> the sorted list to <b>grep</b>.</td>
</tr>
<tr>
<td><code>></code> (Redirect)</td>
<td>Redirects standard output to a file (<b>overwrites</b>).</td>
</tr>
<tr>
<td><code>ls > files.txt</code></td>
<td>Example: Puts the output of <code>ls</code> into <code>files.txt</code>.</td>
</tr>
<tr>
<td><code>>></code> (Append)</td>
<td>Redirects output to a file (<b>appends</b> to end).</td>
</tr>
<tr>
<td><code><</code> (Input)</td>
<td>Redirects standard input from a file.</td>
</tr>
<tr>
<td><code>./app < input.txt</code></td>
<td>Example: Runs <code>app</code> and feeds it <code>input.txt</code> as if you typed it.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Permissions & Ownership</h2></div>
<div class="card-content">
<p><code>ls -l</code> shows permissions like <code>-rwxr-xr--</code></p>
<ul>
<li>First char: <code>d</code> (directory) or <code>-</code> (file).</li>
<li>Group 1: <b>Owner</b> (<code>rwx</code> = Read, Write, eXecute)</li>
<li>Group 2: <b>Group</b> (<code>r-x</code> = Read, no Write, eXecute)</li>
<li>Group 3: <b>Other</b> (<code>r--</code> = Read, no Write, no eXecute)</li>
</ul>
<table>
<tr>
<td><code>chmod [###] [file]</code></td>
<td><b>Ch</b>ange <b>mod</b>e (permissions) using numbers.</td>
</tr>
<tr>
<td><code>4=Read, 2=Write, 1=X</code></td>
<td>Permission numbers. Add them up for each group.</td>
</tr>
<tr>
<td><code>chmod 755 script.sh</code></td>
<td><b>Owner</b>: 7 (4+2+1), <b>Group</b>: 5 (4+0+1), <b>Other</b>: 5 (4+0+1).</td>
</tr>
<tr>
<td><code>chmod 660 file.txt</code></td>
<td><b>Owner</b>: 6 (4+2+0), <b>Group</b>: 6 (4+2+0), <b>Other</b>: 0.</td>
</tr>
<tr>
<td><code>sudo [command]</code></td>
<td><b>S</b>uper <b>U</b>ser <b>Do</b>. Runs a command as administrator.</td>
</tr>
<tr>
<td><code>sudo chown [user] [file]</code></td>
<td><b>Ch</b>ange <b>own</b>er of a file.</td>
</tr>
<tr>
<td><code>sudo chgrp [group] [file]</code></td>
<td><b>Ch</b>ange <b>gr</b>ou<b>p</b> of a file.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Processes & Networking</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>ping [ip/host]</code></td>
<td>Sends packets to a host (e.g., <code>ping 8.8.8.8</code>). (<code>Ctrl+C</code> to stop).</td>
</tr>
<tr>
<td><code>traceroute [host]</code></td>
<td>Traces the network hops to a host.</td>
</tr>
<tr>
<td><code>ifconfig</code></td>
<td>Shows network <b>i</b>nter<b>f</b>ace <b>config</b>uration (your IP address).</td>
</tr>
<tr>
<td><code>ps</code></td>
<td>Shows your active <b>p</b>rocesse<b>s</b>.</td>
</tr>
<tr>
<td><code>ps aux</code></td>
<td>Shows <b>a</b>ll <b>p</b>rocesses from <b>a</b>ll <b>u</b>sers in detail.</td>
</tr>
<tr>
<td><code>top</code></td>
<td>Shows a dynamic, real-time list of processes. (<code>q</code> to quit).</td>
</tr>
<tr>
<td><code>[cmd] &</code></td>
<td>Runs a command in the <b>background</b>.</td>
</tr>
<tr>
<td><code>Ctrl+Z</code></td>
<td>Suspends the current foreground job.</td>
</tr>
<tr>
<td><code>jobs</code></td>
<td>Lists suspended or background jobs.</td>
</tr>
<tr>
<td><code>bg %1</code></td>
<td>Puts job <code>%1</code> into the <b>b</b>ack<b>g</b>round.</td>
</tr>
<tr>
<td><code>fg %1</code></td>
<td>Brings job <code>%1</code> to the <b>f</b>ore<b>g</b>round.</td>
</tr>
<tr>
<td><code>kill [PID]</code></td>
<td>Kills a process by its <b>P</b>rocess <b>ID</b> (get from <code>ps</code>).</td>
</tr>
<tr>
<td><code>kill -9 [PID]</code></td>
<td>Force-kills a stubborn process.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Scripting, Archive & Transfer</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>alias fs=./script.sh</code></td>
<td>Creates a shortcut <code>fs</code> to run your script.</td>
</tr>
<tr>
<td><code>unalias fs</code></td>
<td>Removes the <code>fs</code> alias.</td>
</tr>
<tr>
<td><code>tar -zcvf a.tar.gz [dir]</code></td>
<td><b>T</b>ape <b>Ar</b>chive: <b>z</b>ip, <b>c</b>reate, <b>v</b>erbose, <b>f</b>ile. Compresses <code>[dir]</code>.</td>
</tr>
<tr>
<td><code>tar -xzvf a.tar.gz</code></td>
<td>E<b>x</b>tracts (unzips) the <code>.tar.gz</code> file.</td>
</tr>
<tr>
<td><code>ssh [user]@[host]</code></td>
<td><b>S</b>ecure <b>Sh</b>ell. Logs into a remote server.</td>
</tr>
<tr>
<td><code>scp [file] [user]@[host]:~</code></td>
<td><b>S</b>ecure <b>C</b>o<b>p</b>y. Sends <code>[file]</code> to the remote host's home (<code>~</code>) dir.</td>
</tr>
<tr>
<td><code>logout</code></td>
<td>Logs out of an <code>ssh</code> session.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Disk & Package Mgmt (Added)</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>du -h</code></td>
<td><b>D</b>isk <b>U</b>sage for current dir, in <b>h</b>uman-readable format.</td>
</tr>
<tr>
<td><code>df -h</code></td>
<td><b>D</b>isk <b>F</b>ree space for all volumes, in <b>h</b>uman-readable format.</td>
</tr>
<tr>
<td><code>brew install [name]</code></td>
<td>(Homebrew) Installs software. (e.g., <code>brew install htop</code>).</td>
</tr>
<tr>
<td><code>brew update</code></td>
<td>(Homebrew) Updates the list of available software.</td>
</tr>
<tr>
<td><code>brew upgrade</code></td>
<td>(Homebrew) Upgrades all installed software.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Example: Bash Script</h2></div>
<div class="card-content">
<p>A file like <code>firstScript.sh</code>. Run with <code>./firstScript.sh</code> after <code>chmod 755</code>.</p>
<pre><code>#!/bin/bash
# ^ This is the "shebang", tells the OS to use bash
i=1
echo "Enter a number: "
read a # Read user input into variable 'a'
# Check if input is a positive integer
if ! [[ $a =~ ^[0-9]+$ ]] || (( a < 1 )); then
echo "Error: please enter a positive integer." >&2
exit 1
fi
while [[ $i -le $a ]]; do
echo "$i"
if (( i % 2 == 0 )); then
echo "$i is divisible by 2"
else
echo "$i is odd"
fi
if (( i % 6 == 0 )); then
echo "$i is divisible by 6"
fi
(( i += 1 )) # Increment 'i'
done
ls # Runs 'ls' at the end of the script
</code></pre>
</div>
</div>
</section>
<section id="linux" class="tab-content" role="tabpanel" aria-hidden="true">
<div class="card">
<div class="card-header"><h2>Navigation & Info</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>pwd</code></td>
<td><b>P</b>rint <b>W</b>orking <b>D</b>irectory (shows where you are).</td>
</tr>
<tr>
<td><code>whoami</code></td>
<td>Shows your account username.</td>
</tr>
<tr>
<td><code>cd [dir]</code></td>
<td><b>C</b>hange <b>D</b>irectory. Use <code>cd ..</code> to go up, <code>cd</code> to go home.</td>
</tr>
<tr>
<td><code>cd -</code></td>
<td>Go to the previous directory you were in.</td>
</tr>
<tr>
<td><code>ls</code></td>
<td><b>L</b>i<b>s</b>t files and directories.</td>
</tr>
<tr>
<td><code>ls -l</code></td>
<td>List with <b>l</b>ong format (permissions, owner, size).</td>
</tr>
<tr>
<td><code>ls -a</code></td>
<td>List <b>a</b>ll files (including hidden <code>.</code> files).</td>
</tr>
<tr>
<td><code>ls -alF</code></td>
<td>Combine flags: <b>a</b>ll, <b>l</b>ong, <b>F</b> (adds <code>/</code> to dirs).</td>
</tr>
<tr>
<td><code>history</code></td>
<td>Shows command history. <code>history -75</code> shows last 75.</td>
</tr>
<tr>
<td><code>Up Arrow</code></td>
<td>Scroll through last-used commands.</td>
</tr>
<tr>
<td><code>Tab</code></td>
<td>Auto-completes filenames or commands.</td>
</tr>
<tr>
<td><code>clear</code></td>
<td>Clears the terminal screen.</td>
</tr>
<tr>
<td><code>man [cmd]</code></td>
<td>Shows the <b>man</b>ual for a command (e.g., <code>man ls</code>).</td>
</tr>
<tr>
<td><code>which [cmd]</code></td>
<td>Shows the full path to a command (e.g., <code>which ls</code>).</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>File & Directory Manipulation</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>mkdir [name]</code></td>
<td><b>M</b>a<b>k</b>e a new <b>dir</b>ectory.</td>
</tr>
<tr>
<td><code>touch [file]</code></td>
<td>Creates a new, empty file (or updates timestamp).</td>
</tr>
<tr>
<td><code>cp [src] [dest]</code></td>
<td><b>C</b>o<b>p</b>y a file. (e.g., <code>cp hi.txt bye.txt</code>).</td>
</tr>
<tr>
<td><code>cp -r [src] [dest]</code></td>
<td><b>C</b>opy <b>r</b>ecursively (copies a whole directory).</td>
</tr>
<tr>
<td><code>mv [src] [dest]</code></td>
<td><b>M</b>o<b>v</b>e a file or directory. Also used to rename files.</td>
</tr>
<tr>
<td><code>rm [file]</code></td>
<td><b>R</b>e<b>m</b>ove a file. <b>Be careful! This is permanent.</b></td>
</tr>
<tr>
<td><code>rmdir [dir]</code></td>
<td><b>R</b>e<b>m</b>ove an <i>empty</i> <b>dir</b>ectory.</td>
</tr>
<tr>
<td><code>rm -r [dir]</code></td>
<td><b>R</b>emove a directory <b>r</b>ecursively (and all its contents).</td>
</tr>
<tr>
<td><code>ln [target] [link]</code></td>
<td>Creates a hard <b>l</b>i<b>n</b>k between two files.</td>
</tr>
<tr>
<td><code>ln -s [target] [link]</code></td>
<td>Creates a <b>s</b>ymbolic link (a "shortcut"). More common.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Viewing & Reading Files</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>echo "text"</code></td>
<td>Prints "text" to the terminal.</td>
</tr>
<tr>
<td><code>cat [file]</code></td>
<td>Con<b>cat</b>enate. Dumps the entire file content to the screen.</td>
</tr>
<tr>
<td><code>cat f1.txt f2.txt</code></td>
<td>Combines and prints two files.</td>
</tr>
<tr>
<td><code>more [file]</code></td>
<td>View a file one page at a time (scroll down only).</td>
</tr>
<tr>
<td><code>less [file]</code></td>
<td>View a file one page at a time (scroll up and down). (<code>more</code> is <code>less</code>!)</td>
</tr>
<tr>
<td><code>head [file]</code></td>
<td>Shows the first 10 lines of a file.</td>
</tr>
<tr>
<td><code>tail [file]</code></td>
<td>Shows the last 10 lines of a file.</td>
</tr>
<tr>
<td><code>nano [file]</code></td>
<td>Opens the <code>nano</code> text editor to create or edit a file.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Search, Sort & Redirects</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>find . -name "f.txt"</code></td>
<td><b>Find</b>s files with <code>-name</code> starting from <code>.</code> (current dir).</td>
</tr>
<tr>
<td><code>grep "term" [file]</code></td>
<td>Searches for "term" inside a file.</td>
</tr>
<tr>
<td><code>grep -r "term" .</code></td>
<td>Searches <b>r</b>ecursively for "term" in all files in current dir.</td>
</tr>
<tr>
<td><code>sort [file]</code></td>
<td>Sorts the lines of a file alphabetically.</td>
</tr>
<tr>
<td><code>|</code> (Pipe)</td>
<td><b>Pipeline</b>. Uses the output of one command as the input for another.</td>
</tr>
<tr>
<td><code>sort f.txt | grep "e"</code></td>
<td>Example: <b>sorts</b> the file, then <b>pipes</b> the sorted list to <b>grep</b>.</td>
</tr>
<tr>
<td><code>></code> (Redirect)</td>
<td>Redirects standard output to a file (<b>overwrites</b>).</td>
</tr>
<tr>
<td><code>ls > files.txt</code></td>
<td>Example: Puts the output of <code>ls</code> into <code>files.txt</code>.</td>
</tr>
<tr>
<td><code>>></code> (Append)</td>
<td>Redirects output to a file (<b>appends</b> to end).</td>
</tr>
<tr>
<td><code><</code> (Input)</td>
<td>Redirects standard input from a file.</td>
</tr>
<tr>
<td><code>./app < input.txt</code></td>
<td>Example: Runs <code>app</code> and feeds it <code>input.txt</code> as if you typed it.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Permissions & Ownership</h2></div>
<div class="card-content">
<p><code>ls -l</code> shows permissions like <code>-rwxr-xr--</code></p>
<ul>
<li>First char: <code>d</code> (directory) or <code>-</code> (file).</li>
<li>Group 1: <b>Owner</b> (<code>rwx</code> = Read, Write, eXecute)</li>
<li>Group 2: <b>Group</b> (<code>r-x</code> = Read, no Write, eXecute)</li>
<li>Group 3: <b>Other</b> (<code>r--</code> = Read, no Write, no eXecute)</li>
</ul>
<table>
<tr>
<td><code>chmod [###] [file]</code></td>
<td><b>Ch</b>ange <b>mod</b>e (permissions) using numbers.</td>
</tr>
<tr>
<td><code>4=Read, 2=Write, 1=X</code></td>
<td>Permission numbers. Add them up for each group.</td>
</tr>
<tr>
<td><code>chmod 755 script.sh</code></td>
<td><b>Owner</b>: 7 (4+2+1), <b>Group</b>: 5 (4+0+1), <b>Other</b>: 5 (4+0+1).</td>
</tr>
<tr>
<td><code>chmod 660 file.txt</code></td>
<td><b>Owner</b>: 6 (4+2+0), <b>Group</b>: 6 (4+2+0), <b>Other</b>: 0.</td>
</tr>
<tr>
<td><code>sudo [command]</code></td>
<td><b>S</b>uper <b>U</b>ser <b>Do</b>. Runs a command as administrator.</td>
</tr>
<tr>
<td><code>sudo chown [user] [file]</code></td>
<td><b>Ch</b>ange <b>own</b>er of a file.</td>
</tr>
<tr>
<td><code>sudo chgrp [group] [file]</code></td>
<td><b>Ch</b>ange <b>gr</b>ou<b>p</b> of a file.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Processes & Networking</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>ping [ip/host]</code></td>
<td>Sends packets to a host (e.g., <code>ping 8.8.8.8</code>). (<code>Ctrl+C</code> to stop).</td>
</tr>
<tr>
<td><code>traceroute [host]</code></td>
<td>Traces the network hops to a host.</td>
</tr>
<tr>
<td><code>ip addr</code></td>
<td>Shows network <b>ip</b> <b>add</b>resse<b>s</b> (your IP address). (Modern)</td>
</tr>
<tr>
<td><code>ifconfig</code></td>
<td>(Older) Shows network <b>i</b>nter<b>f</b>ace <b>config</b>uration.</td>
</tr>
<tr>
<td><code>ps</code></td>
<td>Shows your active <b>p</b>rocesse<b>s</b>.</td>
</tr>
<tr>
<td><code>ps aux</code> or <code>ps -ef</code></td>
<td>Shows <b>a</b>ll <b>p</b>rocesses from <b>a</b>ll <b>u</b>sers in detail.</td>
</tr>
<tr>
<td><code>top</code> or <code>htop</code></td>
<td>Shows a dynamic, real-time list of processes. (<code>q</code> to quit).</td>
</tr>
<tr>
<td><code>[cmd] &</code></td>
<td>Runs a command in the <b>background</b>.</td>
</tr>
<tr>
<td><code>Ctrl+Z</code></td>
<td>Suspends the current foreground job.</td>
</tr>
<tr>
<td><code>jobs</code></td>
<td>Lists suspended or background jobs.</td>
</tr>
<tr>
<td><code>bg %1</code></td>
<td>Puts job <code>%1</code> into the <b>b</b>ack<b>g</b>round.</td>
</tr>
<tr>
<td><code>fg %1</code></td>
<td>Brings job <code>%1</code> to the <b>f</b>ore<b>g</b>round.</td>
</tr>
<tr>
<td><code>kill [PID]</code></td>
<td>Kills a process by its <b>P</b>rocess <b>ID</b> (get from <code>ps</code>).</td>
</tr>
<tr>
<td><code>kill -9 [PID]</code></td>
<td>Force-kills a stubborn process.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Scripting, Archive & Transfer</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>alias fs=./script.sh</code></td>
<td>Creates a shortcut <code>fs</code> to run your script.</td>
</tr>
<tr>
<td><code>unalias fs</code></td>
<td>Removes the <code>fs</code> alias.</td>
</tr>
<tr>
<td><code>tar -zcvf a.tar.gz [dir]</code></td>
<td><b>T</b>ape <b>Ar</b>chive: <b>z</b>ip, <b>c</b>reate, <b>v</b>erbose, <b>f</b>ile. Compresses <code>[dir]</code>.</td>
</tr>
<tr>
<td><code>tar -xzvf a.tar.gz</code></td>
<td>E<b>x</b>tracts (unzips) the <code>.tar.gz</code> file.</td>
</tr>
<tr>
<td><code>ssh [user]@[host]</code></td>
<td><b>S</b>ecure <b>Sh</b>ell. Logs into a remote server.</td>
</tr>
<tr>
<td><code>scp [file] [user]@[host]:~</code></td>
<td><b>S</b>ecure <b>C</b>o<b>p</b>y. Sends <code>[file]</code> to the remote host's home (<code>~</code>) dir.</td>
</tr>
<tr>
<td><code>logout</code></td>
<td>Logs out of an <code>ssh</code> session.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Disk & Package Mgmt (Added)</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>du -h</code></td>
<td><b>D</b>isk <b>U</b>sage for current dir, in <b>h</b>uman-readable format.</td>
</tr>
<tr>
<td><code>df -h</code></td>
<td><b>D</b>isk <b>F</b>ree space for all volumes, in <b>h</b>uman-readable format.</td>
</tr>
<tr>
<td><code>apt install [name]</code></td>
<td>(Debian/Ubuntu) Installs software.</td>
</tr>
<tr>
<td><code>apt update</code></td>
<td>(Debian/Ubuntu) Updates the list of available software.</td>
</tr>
<tr>
<td><code>yum install [name]</code></td>
<td>(RedHat/CentOS) Installs software.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Example: Bash Script</h2></div>
<div class="card-content">
<p>A file like <code>firstScript.sh</code>. Run with <code>./firstScript.sh</code> after <code>chmod 755</code>.</p>
<pre><code>#!/bin/bash
# ^ This is the "shebang", tells the OS to use bash
i=1
echo "Enter a number: "
read a # Read user input into variable 'a'
# Check if input is a positive integer
if ! [[ $a =~ ^[0-9]+$ ]] || (( a < 1 )); then
echo "Error: please enter a positive integer." >&2
exit 1
fi
while [[ $i -le $a ]]; do
echo "$i"
if (( i % 2 == 0 )); then
echo "$i is divisible by 2"
else
echo "$i is odd"
fi
if (( i % 6 == 0 )); then
echo "$i is divisible by 6"
fi
(( i += 1 )) # Increment 'i'
done
ls # Runs 'ls' at the end of the script
</code></pre>
</div>
</div>
</section>
<section id="windows" class="tab-content" role="tabpanel" aria-hidden="true">
<div class="card">
<div class="card-header"><h2>Navigation & Info</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>pwd</code> or <code>Get-Location</code></td>
<td><b>P</b>rint <b>W</b>orking <b>D</b>irectory (shows where you are).</td>
</tr>
<tr>
<td><code>$env:USERNAME</code></td>
<td>Shows your account username.</td>
</tr>
<tr>
<td><code>cd [dir]</code> or <code>Set-Location</code></td>
<td><b>C</b>hange <b>D</b>irectory. Use <code>cd ..</code> to go up, <code>cd ~</code> to go home.</td>
</tr>
<tr>
<td><code>cd -</code></td>
<td>(PowerShell 7+) Go to the previous directory.</td>
</tr>
<tr>
<td><code>ls</code> or <code>Get-ChildItem</code></td>
<td><b>L</b>i<b>s</b>t files and directories.</td>
</tr>
<tr>
<td><code>ls -Hidden</code></td>
<td>List <b>hidden</b> files and directories.</td>
</tr>
<tr>
<td><code>ls -Force</code></td>
<td>Lists all items, including hidden and system files.</td>
</tr>
<tr>
<td><code>ls -Recurse</code></td>
<td>Lists items <b>r</b>ecursively (in subfolders).</td>
</tr>
<tr>
<td><code>Get-History</code></td>
<td>Shows command history.</td>
</tr>
<tr>
<td><code>Up Arrow</code></td>
<td>Scroll through last-used commands.</td>
</tr>
<tr>
<td><code>Tab</code></td>
<td>Auto-completes filenames or commands.</td>
</tr>
<tr>
<td><code>clear</code> or <code>cls</code></td>
<td>Clears the terminal screen.</td>
</tr>
<tr>
<td><code>Get-Help [cmd]</code></td>
<td>Shows the <b>help</b> for a command (e.g., <code>Get-Help ls</code>).</td>
</tr>
<tr>
<td><code>Get-Command [cmd]</code></td>
<td>Shows the full path to a command (e.g., <code>Get-Command ls</code>).</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>File & Directory Manipulation</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>New-Item -Type Dir [name]</code></td>
<td>Creates a new <b>Dir</b>ectory.</td>
</tr>
<tr>
<td><code>New-Item -Type File [file]</code></td>
<td>Creates a new, empty <b>File</b>.</td>
</tr>
<tr>
<td><code>cp [src] [dest]</code> or <code>Copy-Item</code></td>
<td><b>C</b>o<b>p</b>y an item.</td>
</tr>
<tr>
<td><code>cp -Recurse [src] [dest]</code></td>
<td><b>C</b>opy <b>r</b>ecursively (copies a whole directory).</td>
</tr>
<tr>
<td><code>mv [src] [dest]</code> or <code>Move-Item</code></td>
<td><b>M</b>o<b>v</b>e an item.</td>
</tr>
<tr>
<td><code>Rename-Item [src] [new]</code></td>
<td>Renames an item (e.g., <code>mv file.txt new.txt</code>).</td>
</tr>
<tr>
<td><code>rm [file]</code> or <code>Remove-Item</code></td>
<td><b>R</b>e<b>m</b>ove an item. <b>Prompts for confirmation.</b></td>
</tr>
<tr>
<td><code>rm -Recurse -Force [dir]</code></td>
<td>Removes a directory <b>r</b>ecursively and <b>f</b>orces deletion (no prompt).</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Viewing & Reading Files</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>echo "text"</code> or <code>Write-Host "text"</code></td>
<td>Prints "text" to the terminal.</td>
</tr>
<tr>
<td><code>cat [file]</code> or <code>Get-Content</code></td>
<td>Dumps the entire file <b>content</b> to the screen.</td>
</tr>
<tr>
<td><code>more [file]</code></td>
<td>View a file one page at a time.</td>
</tr>
<tr>
<td><code>cat -Head 10 [file]</code></td>
<td>Shows the first 10 lines (<b>head</b>) of a file.</td>
</tr>
<tr>
<td><code>cat -Tail 10 [file]</code></td>
<td>Shows the last 10 lines (<b>tail</b>) of a file.</td>
</tr>
<tr>
<td><code>notepad [file]</code></td>
<td>Opens the file in Notepad.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Search, Sort & Redirects</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>ls -Recurse -Filter "*.txt"</code></td>
<td>Finds all <code>.txt</code> files recursively.</td>
</tr>
<tr>
<td><code>Select-String "term" [file]</code></td>
<td>Searches for "term" inside a file. (Like <code>grep</code>).</td>
</tr>
<tr>
<td><code>Get-Content [file] | Sort-Object</code></td>
<td><b>Sorts</b> the lines of a file alphabetically.</td>
</tr>
<tr>
<td><code>|</code> (Pipe)</td>
<td><b>Pipeline</b>. Uses the output of one command as the input for another.</td>
</tr>
<tr>
<td><code>cat f.txt | Sort-Object | Select-String "e"</code></td>
<td>Example: Gets content, <b>sorts</b> it, then <b>pipes</b> to <b>Select-String</b>.</td>
</tr>
<tr>
<td><code>></code> (Redirect)</td>
<td>Redirects output to a file (<b>overwrites</b>).</td>
</tr>
<tr>
<td><code>ls > files.txt</code></td>
<td>Example: Puts the output of <code>ls</code> into <code>files.txt</code>.</td>
</tr>
<tr>
<td><code>>></code> (Append)</td>
<td>Redirects output to a file (<b>appends</b> to end).</td>
</tr>
<tr>
<td><code><</code> (Input)</td>
<td>Redirects standard input from a file.</td>
</tr>
<tr>
<td><code>Get-Content name.txt | ./reader.exe</code></td>
<td>Example: Feeds <code>name.txt</code> to <code>reader.exe</code>.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Permissions & Execution</h2></div>
<div class="card-content">
<p>File permissions are usually managed via the File Explorer GUI (Right-click > Properties > Security).</p>
<table>
<tr>
<td><code>Get-ExecutionPolicy</code></td>
<td>Shows if you are allowed to run scripts.</td>
</tr>
<tr>
<td><code>Set-ExecutionPolicy [Policy]</code></td>
<td>Changes the policy. (e.g., <code>Restricted</code>, <code>RemoteSigned</code>).</td>
</tr>
<tr>
<td><code>Set-ExecutionPolicy Unrestricted -Scope CurrentUser</code></td>
<td>Allows running scripts for just your user.</td>
</tr>
<tr>
<td><code>./myScript.ps1</code></td>
<td>To run a PowerShell script, you must use <code>./</code></td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Processes & Networking</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>Test-Connection [host]</code></td>
<td>Pings a host (e.g., <code>Test-Connection 8.8.8.8</code>).</td>
</tr>
<tr>
<td><code>tracert [host]</code></td>
<td><b>Trace</b>s the network <b>r</b>ou<b>t</b>e to a host.</td>
</tr>
<tr>
<td><code>Get-NetIPAddress</code></td>
<td>Shows network IP addresses (like <code>ip addr</code>).</td>
</tr>
<tr>
<td><code>ipconfig</code></td>
<td>(Cmd.exe command, but works) Shows network configuration.</td>
</tr>
<tr>
<td><code>Get-Process</code></td>
<td>Shows your active <b>p</b>rocesse<b>s</b>. (Like <code>ps</code>).</td>
</tr>
<tr>
<td><code>Stop-Process -Name [name]</code></td>
<td>Stops a process by its name.</td>
</tr>
<tr>
<td><code>Stop-Process -Id [PID]</code></td>
<td>Stops a process by its <b>P</b>rocess <b>ID</b>.</td>
</tr>
<tr>
<td><code>Start-Job { [cmd] }</code></td>
<td>Starts a command as a background job.</td>
</tr>
<tr>
<td><code>Get-Job</code></td>
<td>Lists background jobs.</td>
</tr>
<tr>
<td><code>Receive-Job [ID]</code></td>
<td>Gets the output of a completed background job.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Archive, Transfer & Disk</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>Compress-Archive [path] [zip]</code></td>
<td>Creates a <code>.zip</code> file from a folder.</td>
</tr>
<tr>
<td><code>Expand-Archive [zip] [dest]</code></td>
<td>Unzips a <code>.zip</code> file.</td>
</tr>
<tr>
<td><code>scp [file] [user]@[host]:~</code></td>
<td><b>S</b>ecure <b>C</b>o<b>p</b>y. Sends <code>[file]</code> to a remote host. (Requires SSH client).</td>
</tr>
<tr>
<td><code>chkdsk</code></td>
<td><b>Ch</b>ec<b>k</b>s <b>D</b>i<b>sk</b> for errors.</td>
</tr>
<tr>
<td><code>Get-Volume</code></td>
<td>Shows disk volumes and free space (like <code>df</code>).</td>
</tr>
<tr>
<td><code>hostname</code></td>
<td>Shows the computer's name.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Package Mgmt (Added)</h2></div>
<div class="card-content">
<table>
<tr>
<td><code>winget search [name]</code></td>
<td>(Windows Package Manager) Searches for software.</td>
</tr>
<tr>
<td><code>winget install [name]</code></td>
<td>(Winget) Installs software.</td>
</tr>
<tr>
<td><code>choco search [name]</code></td>
<td>(Chocolatey) Searches for software.</td>
</tr>
<tr>
<td><code>choco install [name]</code></td>
<td>(Chocolatey) Installs software.</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-header"><h2>Example: PowerShell Script</h2></div>
<div class="card-content">
<p>A file like <code>firstScript.ps1</code>. Run with <code>./firstScript.ps1</code>.</p>
<pre><code># Variables in PowerShell start with $
Write-Host "Enter a number"
$number = Read-Host # Read user input
$i = 1
while ($i -le $number) { # -le means "Less than or Equal"
Write-Host "$i"
if ($i % 2 -eq 0) { # -eq means "Equal"
Write-Host "$i is even baby"
} else {
Write-Host "$i odd stuff..."
}
# -and operator
if (($i % 2 -eq 0) -and ($i % 3 -eq 0)) {
Write-Host "number $i is divisable by 6"
}
$i++ # Increment 'i'
}
# Runs 'ls' at the end of the script
ls
</code></pre>
</div>
</div>
</section>
<footer>
Built with 🖤 for EEE120.
</footer>
</main>
<script>
// Simple JavaScript for Tab functionality
document.addEventListener('DOMContentLoaded', () => {
const tabs = document.querySelectorAll('.tab-button');
const contents = document.querySelectorAll('.tab-content');
function showTab(tabId) {
// Hide all content sections
contents.forEach(content => {
content.setAttribute('aria-hidden', 'true');
});
// Un-select all tabs
tabs.forEach(tab => {
tab.setAttribute('aria-selected', 'false');
});
// Show the target content section
const activeContent = document.getElementById(tabId);
if (activeContent) {
activeContent.setAttribute('aria-hidden', 'false');
}
// Select the target tab
const activeTab = document.querySelector(`.tab-button[data-tab="${tabId}"]`);
if (activeTab) {
activeTab.setAttribute('aria-selected', 'true');
}
}
// Add click event listeners to tabs
tabs.forEach(tab => {
tab.addEventListener('click', () => {
const tabId = tab.getAttribute('data-tab');
showTab(tabId);
});
});
// Show the first tab by default
showTab('mac');
});
</script>
</body>
</html>