Linux Flashcards

(136 cards)

1
Q

command prompt terminal, open on windows

A

you can find it by searching for “Command Prompt” in the Start Menu.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

While “terminal”, “shell”, “command line”, “CLI”, and “command prompt” are technically different, they are often used interchangeably. What do they refer to?

A

A program that allows you to interact with your computer in a text-based way.

(Traditionally “terminal” meant a physical device you could type commands into, essentially a keyboard and a screen.

These days, when we say “terminal”, we mean “terminal emulator”, a program that emulates a physical terminal; it’s a program that lets you type commands into a window on your computer.

Which commands you can use is determined by the shell.

The terminal emulator is just responsible for drawing text on the screen and processing your keystrokes.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

GUI

A

Graphical User Interface or “Gooey”

When you use on a mouse to click on icons, buttons, or menus, you’re using a GUI.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Drawbacks to GUIs

A

-They’re weak. You are given much more control over your computer through a CLI. With a GUI you’re limited to the options that the developer of the GUI has given you.’’

-They’re slow. Once you know the commands to type, it’s much faster to type them than to click through endless menus with a mouse.

-They’re not as reproducible. If you want to share a set of instructions, you can just copy and paste commands without worrying about screen sizes and user preferences.

-They’re not automatable. It’s easy to write code that manipulates text (as you’ve seen in Python), but it’s much harder to write code that manipulates GUIs.

-They’re not as cool. You will be invited to 90% fewer romantic outings if you are a GUI user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you determine your username?

A

Type whoami in the command prompt terminal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to see what version of windows you’re running:

A

Options:
1) pressing Win + R and typing winver, or
2) go to Start > Settings > System > About and checking “Windows specifications,”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Terminal vs Terminal Emulator

A

Traditionally “terminal” meant a physical device you could type commands into, essentially a keyboard and a screen.

These days, when we say “terminal”, we mean “terminal emulator”, a program that emulates a physical terminal; it’s a program that lets you type commands into a window on your computer.

Which commands you can use is determined by the shell.

The terminal emulator is just responsible for drawing text on the screen and processing your keystrokes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Shell or REPLs

A

A terminal is just a program that lets you issue text-based commands and renders the output of those commands.

A shell runs those commands.

REPL:
Read
Eval (evaluate)
Print
Loop

That is, shells are programs that:
1. read the commands you type
2. evaluate those commands, usually by running other programs on your computer
3. print the output of those commands
4. give you a new prompt to type another command and repeat

Example:
f you’re using Ubuntu on WSL, you’re probably running a Bash shell.
If you’re using macOS, you’re probably running a Zsh shell.

The point is that you’re probably using Bash or Zsh, and for the purposes of this course, they’re basically the same.

Both Bash and Zsh are shells, and they also happen to be powerful programming languages. They have variables, functions, loops, and more.

That said, only crazy people write large programs in shell languages… shells are optimized for running other programs and writing small scripts, not for writing large applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

$

A

Starting a line $ symbol is a convention to show it’s a shell prompt, and it should not be typed. The actual command listed below as an example is echo $name.

$ echo $name
Lane

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Create and use a variable

A

Create a Variable
Example:
name=”Lane”

Notice there are no spaces between the variable name, assignment operator = and value “Lane”.

Use a variable:
$ echo $name
Lane

Unlike in Python, where you can just use a variable’s name, in your shell you need to prefix the variable name with a $ to use it, else it would just print name instead of the value.

Note: Starting a line $ symbol is a convention to show it’s a shell prompt, and it should not be typed. The actual command listed below as an example is echo $name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Variable interpolation

A

Variable interpolation is a common technique used in programming to build dynamic strings that contain values that may change over time. (f strings are an example of variable interpolation in python.)

It involves evaluating a string that contains placeholders and replacing the placeholders with their corresponding values. The placeholders are usually represented by a symbol or a keyword, and the values are usually variables or expressions that have been defined previously in the code.

$ echo Hello $name
Hello Lane

Note: Starting a line $ symbol is a convention to show it’s a shell prompt, and it should not be typed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Distros of Linux (name a few)

A

Linux distributions (distros) are different versions of the Linux operating system.

(Linux (icon: penguin))

command prompt (the built-in windows command prompt; viewed as terrible by some–those people recommend using ubuntu instead). icon: windows.

ubuntu (icon: white circle on orange background)

RHEL (icon: guy in a red hat) (pronunce rell rhymes with bell)

Raspberry Pi OS (previously called Raspbian): (raspberry logo).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Top print out the history of commands you’ve typed in your shell, you can use the __ command

A

history

Example:
$department=”engineering”
$team=”opps”
echo I work in $department on $team
I
work
in
engineering
on
opps

Id CommandLine
– ———–
1 $department=”engineering”
2 $team=”opps”
3 echo I work in $department on $team

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Up & down arrow keys

A

You can use the up and down arrows to quickly cycle through your command history.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

clear command

A

ctrl+l

This will clear your terminal

Note: This won’t delete your history; it’ll just clear the screen.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Terminal Alternatives

A

Editor/IDE Built-In Terminals
Most text editors for developers have a built-in terminal.

For example, VS Code, Zed, and Cursor are popular text editors that also have a built-in terminal. While I do use Zed’s terminal for most of my coding work, in this course, I do not recommend using a built-in terminal because we don’t need the extra text editor features.

Ghostty
Ghostty is a very new terminal emulator that differentiates itself by being fast, feature-rich, and native. It’s a great option if you love to customize, and want a modern, fast, and feature-rich terminal.

Alacritty
Alacritty is another popular terminal emulator that is known for its speed and extensibility. Before Ghostty, Alacritty was the go-to terminal for many developers who wanted a fast and customizable terminal.

Windows Terminal
Windows Terminal is the terminal emulator for Windows. Use the “cmd.exe” program settings to change the default terminal. Be sure to start WSL whenever you open a new terminal window.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Terminal Emulators

A

Windows Terminal, Ghostty, and Alacritty are all terminal emulators — programs whose whole job is to show you a terminal window and let you run shells/commands inside it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Linux Operating System

A

Ubuntu is a Linux operating system (distribution). It includes terminals (like GNOME Terminal), but Ubuntu itself is not a terminal program.
So you can run terminal emulators inside Ubuntu, but Ubuntu is the OS, not the emulator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Directories & Files

A

Also known as “folders” on windows are containers that hold files and other directories

Files are just a dump of raw binary data (i.e., the 1s and 0s). The bytes in a file can represent anything: text, images, videos, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

The filesystem tree starts with a single directory called the ____

A

root directory

The root directory contains files and directories, which can contain more files and directories, and so on.

When you open your terminal, your working directory (i.e., the one you’re in) is going to be somewhere…most commonly it’s your home directory (e.g., /home/kasey)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

pwd

A

print working directory

This command will show you the filepath of your current working directory (i.e., the one you’re in).

Linux/Windows WSL
/home/wagslane

The first slash (/) represents the root directory. It’s the tippy-top of the filesystem tree.
The next part (home) is the name of a directory inside the root directory.
Finally, the last part (wagslane) is the name of a directory inside the home directory.
So this path represents a directory 2 levels down from the root directory:

root
└── home
└── wagslane

macOS
/Users/wagslane

The first slash (/) represents the root directory. It’s the tippy-top of the filesystem tree.
The next part (Users) is the name of a directory inside the root directory.
Finally, the last part (wagslane) is the name of a directory inside the Users directory.
So this path represents a directory 2 levels down from the root directory:

root
└── Users
└── wagslane

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

filepath

A

A filepath is a string that describes the location of a file or directory on your computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

ls

A

list command
It will show you the contents of your current working directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

cd

A

cd: change directory command

Example: If you do
cd worldbanc

It will move into the worldbanc directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
..
The cd command "changes directory" to move into a directory. But how do you move back out of the current directory? The answer is two dots: .. .. is a special alias that refers to "the parent directory". It's a shortcut that you can use to move up one level in the directory tree. Tip: you can use .. as an alias for a parent directory. So if you're in worldbanc/private/transactions/ and you want to get to worldbanc, you can run cd .. twice: cd .. cd .. Alternatively, you can just run: cd ../.. once.
26
Absolute path
An Absolute Path: -Always starts from / (the root of the filesystem) -Describes the full route from / to the target Example: cd /home/alex/projects/my_app An absolute path always begins from the absolute start of your hard drive (usually indicated by a forward slash / or unix-like systems (like macOs or Linux)) and describes every step you must take through the filesystem to end up at the target location Example: For instance, suppose you write a note to your work colleague that says, "Push the button every 108 minutes." Without telling your colleague where the button is located, these instructions are useless. So you change the instruction to: "Push /usr/share/widgets/button every 108 minutes." Now your colleague knows exactly where to locate the button, and the path to the button is the same whether you or your colleague are following the path. From your home directory, the button is located in /usr/share/widgets/button, and from your colleague's home directory, the button is also located in /usr/share/widgets/button.
27
Relative path
Relative Path: -Does not start with / -Interpreted starting from your current working directory Example: # if you're currently in /home/alex cd projects/my_app Absolute paths are useful, but they're not always efficient. If you know where the widgets directory, which contains button, is located. then you don't necessarily have to go all the way back to / and then usr and then share and so on. Think of it this way: When you stop at a diner on your way to work, you don't have to go all the way back home to resume your journey to the office. You just step outside the diner and continue on your way, because you know where your office is relative to your current location. Relative paths use the same principle. Suppose you're in /var/log/foo and you want to view a file in /var/log/bar. There's no reason to "travel" all the way back to /var. Instead, use a relative path to look outside of foo and into bar. $ sudo cat ../bar/file.txt Two dots (..) represent moving to a parent directory, so ../bar/file.txt means to move up one directory (into /var/log) and then descend into /var/log/bar, which contains file.txt. You may notice that using .. isn't very descriptive. That's both the advantage and disadvantage of a relative path. It's an advantage because it can be quicker to type and it's flexible. The statement ../bar/file.txt doesn't care what comes before bar. It only knows that the bar directory contains a file called file.txt. That makes it equally true whether a user keeps the foo and bar directories in /var/log or in /opt or in /home/tux/.var/log or any other location
28
How to determine whether to use the absolute path or the relative path?
It depends. Relative paths are easier to read and write, and as long as you're in the correct directory (or the directory you expect), they're easier to reason about. Absolute paths are more explicit. They're useful when you're not sure what directory you're currently in. For example, maybe you're giving someone instructions on how to find a file on their computer. You can't be sure what directory they'll be in when they start following your instructions, so you'll need to use an absolute path.
29
Special directories: . means ___ .. means ___
Special directories: . means "this directory" .. means "the parent directory" Examples: cd .. # go up one directory cd ../logs # go up one directory, then into logs cd ./src # go into src inside the current directory Tip: you can use .. as an alias for a parent directory. So if you're in worldbanc/private/transactions/ and you want to get to worldbanc, you can run cd .. twice: cd .. cd .. Alternatively, you can just run: cd ../.. once.
30
cat
The cat command is used to view the contents of a file. It's short for "concatenate", which is a fancy way of saying "put things together". It can feel like a confusing name if you're using the cat command to view a single file, but it makes more sense when you're using it to view multiple files at once. Print the contents of a file to the terminal cat file1.txt Concatenate the contents of multiple files and print them to the terminal cat file1.txt file2.txt
31
Ubuntu or Linux command appearing to print the same output as its input is most commonly due to...
the way standard input (STDIN) and standard output (STDOUT) interact in a terminal environment, especially when using commands like cat, tee, or shell reduction. One common scenario: 1. Using the cat command without arguments When you run the cat (concatenate) command by itself and start typing, it reads everything you type from standard input and immediately writes it back to standard output (your terminal screen). It will continue doing this until you signal the end of input, typically by pressing Ctrl+D. Example: bash $ cat hello world hello world (You press Ctrl+D here to exit)
32
head command
The head command prints the first n lines of a file, where n is a number you specify. #print first 10 lines of file1.txt: head -n 10 file1.txt
33
tail command
The tail command prints the last n lines of a file, where n is a number you specify. #print the last 10 lines of file1.txt: tail -n 10 file1.txt
34
less and more
The more and less commands let you view the contents of a file, one page (or line) at a time. As the adage goes, less is more. In the context of these commands, less is literally more. The less command does everything that the more command does but also has more features. As a general rule, you should use less instead of more. You would only use more if you're on a system that doesn't have less installed. Example: Review all lines of the 2023.csv file less 2023.csv Example 2: Re-run the less command, but this time, pass in the -N flag to show the line numbers: less -N 2023.csv
35
enter, "q", spacebar, and "b" when using less
enter: scroll down a few lines q: exit the less program spacebar: press to scroll down one page at a time b: go up a page
36
touch
The touch command updates the access and modification timestamps of a file. By default, if the specified file does not exist, touch will create an empty file with the given filename. Because of this side-effect, you’ll often see this command used to quickly create new empty files. touch new_file.txt You can also create multiple files at once by listing them: touch some_file.txt some_other_file.txt touch can be very handy when writing scripts because it ensures files exist without altering existing ones, creating new files only if necessary.
37
mkdir
The "make directory" command creates a new directory inside (or relative to) the current directory. mkdir my_directory Note: a directory is just a location in a filesystem that can contain files and other directories. On some systems, directories are called "folders", but it's the same thing.
38
rename a file
Example: mv some_file.txt some_other_name.txt
39
Moving a file from the current directory to another nested directory:
mv some_file.txt some_directory/some_file.txt
40
Moving a file from the current directory, to the parent directory:
mv some_file.txt ../some_file.txt
41
If you don't want to rename the file and you're just moving it to a different directory, you can omit the filename:
mv some_file.txt some_directory/
42
rm
The remove command deletes a file or empty directory: rm some_file.txt
43
tab
If you type cd /ho and then press tab, it'll auto-fill in the name So cd /ho + tab output: dc/home Useful when typing lengthy directory or file names
44
rm
remove command: deletes a file or empty directory Example: rm some_file.txt You can add a -r flag to tell the rm command to delete a directory and all of its contents recursively. Example: rm -r some_directory Note: Recursively: means "do it again on all of the subdirectories and their contents".
45
cp
copy command: copies a file from one location to another. Example: cp source_file.txt destination/
46
cp -R
This is how you copy a directory and all of its contents recursively by adding the -R flag. Example: cp -R my_dir new_dir Example: Copy 2020.csv saved in the transactions folder over to the backups folder: ~/worldbanc/private/transactions$ cp 2020.csv ~/worldbanc/private/transactions/backups Note: The hyphen is a tilda.
47
rm -r some_directory
You can add a -r flag to tell the rm command to delete a directory and all of its contents recursively. Example: rm -r some_directory
48
What does -r & -R flags for cp mean in most Linux systems?
recursive Note: Recursively: means "do it again on all of the subdirectories and their contents".
49
Where should you save personal files?
In a Unix-like operating system, a user's home directory is the directory where their personal files are stored. It is also the directory that a user starts in when logging into the system. I recommend doing all of your development work in your home directory. For example, I like to create a workspace directory in my home directory, and all my programming projects live in subdirectories there.
50
/bin /etc /var warning
Your home directory is where you want to spend most of your time. Many of the other directories on your machine are critical to the operating system or other programs. Be careful when working in other directories like /bin, /etc, /var, etc. You can mess up your system if you're not careful.
51
Tilda
My home directory (on Mac) is located at /Users/wagslane. The ~ character is an alias for your home directory. So when I want to go home, I don't have to type out cd /Users/wagslane, I can just type: cd ~ Note: the hyphen is actually a tilda
52
CLI
Command Line Interface (e.g., Bash is a CLI shell program) a text-based way to interact with computers by typing commands like cd or ls
53
grep
Allows you to search for text in file (similar to ctrl+f). Basic Usage The most basic use for grep is to search for a string in a file. For example, if we wanted to search for the word "hello" in the file words.txt, we could run: grep "hello" words.txt This will print out every line in words.txt that contains the word "hello". It's a case-sensitive search, so it will only match "hello", not "Hello" or "HELLO".
54
Use grep to search multiple files
You can also search multiple files at once. For example, if we wanted to search for the word "hello" in hello.txt and hello2.txt, we could run: grep "hello" hello.txt hello2.txt
55
Recursive search with grep
Recursive Search You can also search an entire directory, including all subdirectories. For example, to search for the word "hello" in the current directory and all subdirectories: grep -r "hello" . The . is a special alias for the current directory.
56
.
The . is a special alias for the current directory.
57
find
tool for finding files and directories by name, not by their contents. Find a file by name: example: find a file named "hello.txt" find some_directory -name hello.txt Pattern Search: example: find all files that end in .txt find some_directory -name "*.txt" Search for a specific word: If you want to find filenames that contain a specific word, you can use the * character to match the rest of the filename. Example: Find all filenames that contain the word "chad": find some_directory -name "*chad*"
58
*
Wildcard that matches anything. If you want to find filenames that contain a specific word, you can use the * character to match the rest of the filename. Find all filenames that contain the word "chad" find some_directory -name "*chad*"
58
sudo
short for "superuser do" pronunciation: sue-dough sudo grants unrestricted access and can risk system damage if you don't know what you're doing To use sudo, you need a password with superuse privileges, which you should already have if you're the only user of your machine.
59
Permissions
r: read w: write x: execute In a Unix-like operating system, permissions control who can do what to which files and directories. The permissions of an individual file or directory are represented by a 10-character string. d: directory (e.g. drwxrwxrwx are the permissions for a directory) -: file (e.g. -rwxrwxrwx are the permissions for a file) The next 9 characters are broken up into 3 sets of rwx and represent themselves consecutively as the permissions for the owner, group, and others. Each group of 3 represents the permission for reading, writing, and executing in that order. Owner: the user who created the file or directory, though the owner can be manually changed. Group: Unix-like systems support groups of users and each file or directory is assigned to exactly one owning group. Anyone who is not the owner and not a member of that group falls under "others". (tbh unless you're a system admin, you won't often worry about groups.) Others: everyone else rwx: all permissions (read, write, execute) rw-: read, write, but no execute r-x: read and execute, but no write *Note: Unix is the foundation for Linux. Linux is a unix-like operating system, meaning it follows Unix design principles and concepts but was built from scratch as an open-source clone. Example: -rwxrwxrwx: A file where everyone can do everything -rwxr-xr-x: A file where everyone can read and execute, but only the owner can write drwxr-xr-x: A directory where everyone can read (ls the contents) and execute (cd into it), but only the owner can write (modify the contents) drwx------: A directory where only the owner can read, write and execute
60
chmod command
change mode lets you change the permissions of a file or directory.
61
ls -l (lowercase "L")
This will print out the permissions of each file and directory in long format. Example: ~/worldbanc$ ls -l total 12 -rwxr-xr-x 1 kasey kasey 145 Jan 13 2025 README.md -rw-r--r-- 1 kasey kasey 0 Dec 15 16:01 credithistory.txt drwx------ 8 kasey kasey 4096 Dec 16 17:06 private drwxr-xr-x 3 kasey kasey 4096 Jan 13 2025 public
62
.sh
Files with a .sh extension are shell scripts. They're just text files that contain shell commands.
63
How do you run a file in your shell?
By typing its filepath: mydir/program.sh Note: If the program is in the current directory (in this example, the mydir directory), you need to prefix it with ./ to run it: ./program.sh ./program.sh and program.sh are the same The dot (.) is an alias for the current directory. We need the prefix when running executables so the shell knows we're trying to run a file from a file path, not an installed command like ls, mkdir, chmod, etc.
64
executable files
files where the data is stored inside a program that you can run on your computer
65
NEVER do this command. Which command?
rm -rf This command PERMANENTLY deletes all files and directories; they are not moved to a trash or recycling bin. Your computer will be wiped clean of all files, including files needed to function (on windows, never do *.* as that selects all file extensions with . if you removed those you'd have no files left)
66
root user
The "root" user is a super user with unrestricted access to all commands and files. The sudo stands for "superuser do" and allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. When you use the sudo command, you're running it as the root user (as long as your system hasn't been configured differently.
67
chown
Stands for "change owner" It allows you to change the owner of a file or a directory, and it requires root privileges. Example: We want to change the owner of a directory (in this case, contacts) sudo chown -R root contacts Here's an explanation of the command: sudo - Run as the root user chown - Command to change the owner -R - "Recursive", meaning also apply the changes to everything inside the directory root - The name of the new owner contacts - The directory to change the owner of Note: You need to use sudo when you want to change the permissions of any file or directory that you don't own. (Otherwise, you can use chmod.)
68
Practice Problem: You try to delete a directory, but you can't, because you don't own it. What do you do?
Use sudo. Example: rm -r contacts #output: rm: cannot remove 'contacts': Permission denied sudo rm -r contacts ls #contacts is no longer listed as a directory
69
Program
A bunch of instructions written in a way that a computer can carry out
70
Compiled vs Interpreted Programs
In a nutshell, there are two types of programs: compiled and interpreted. Compiled Programs: Don't rely on any other programs in order to run. (Language>(compiling) Machine Code>Ready to Run! They're standardly written in a language like C, Rust, or Go, but are then compiled down to binary, the raw language of the computer's hardware. When you run a program on your machine that has no other dependencies, you can run the program by typing the name of the program into your shell (e.g., ./your_program_name.exe Interpreted Programs: require other software in order to be executed. Python, Ruby, JavaScript, or ShellScript rely on an interpreter to read the code as they run. If you run an interpreted program, you need to tell your machine which interpreter to use. for example: -to run a compiled program called texteditor, you might just run ./texteditor. (Because its a compiled binary; it's just 1s and 0s that your machine knows how to execute.) -to run an interpreted texteditor program, you would have to type something like: python texteditor.py (Because it's a file of python source code, so it needs access to the python interpreter.)
71
Machine Code
A set of instructions that a computer can execute directly; your computer's CPU is hardware that's been designed to execute machine code. (it's binary.)
72
Interpreter
An interpreted program is a program that is executed by another program. The program that executes the interpreted program is called an interpreter. The interpreter reads the source code of the interpreted program and executes it. Programming languages like Python, Ruby, and JavaScript, are typically interpreted as they run, which means your computer needs to have the interpreter installed to run the program. Another example is the .sh shell script files we talked about. Those are interpreted by the shell program.
73
which
The which command tells you the location of an installed command line program. Example: Ask for the location of the sh (shell) program. which sh #output: cat /bin/sh So, the sh program is located at /bin/sh
74
What do you see when you try to read the output of 'cat'ing a compiled executable.
Think about what a compiled executable is. It's a program that has already been translated from human-readable source code (like C or Go) into machine code (binary). This machine code is a series of instructions and data that your computer's CPU can understand and execute directly. It's not designed to be read by humans as text. So, when you cat a compiled executable like /bin/sh, the cat command tries its best to interpret all those binary bytes as if they were text characters. Since the binary data isn't actually text in any human language, the result is often a jumbled mess of symbols, non-printable characters, and random letters that appear to be "gibberish." It's the computer's attempt to show you something that isn't meant to be seen as plain text. It's like trying to read a book written in a language you don't know – it would just look like a collection of unfamiliar symbols!
75
shebang
A special line at the top of a script that tells your shell which program to use to execute the file.
76
WSL
Windows Subsytem for Linux: Allows you to run a full-fledged Linux environment directly on your Windows Operating System. For example: I know that I'm running WSL, because when I open PowerShell, wsl -l -v shows installed distributiions. In my case, it shows that I'm running Ubuntu version 2. (I'm running a Bash shell.)
77
3 shells you're likely to encounter
sh: The Bourne shell. This is the original Unix shell and is POSIX-compliant. It's very basic and doesn't have many quality-of-life features. bash: The Bourne Again shell. This is the most popular shell on Linux. It builds on sh, but also has a lot of extra features. zsh: The Z shell. This is the most popular shell on macOS. Like bash, it does what sh can do, but also has a lot of extra features. Notes: -zsh shell is pronounced zee shell If you're using Ubuntu on WSL, you're probably running a Bash shell. If you're using macOS, you're probably running a Zsh shell. If you're running a raw Linux installation, I pray you already know what you're using.
78
Configuration Files
Bash and Zsh both have configuration files that run automatically each time you start a new shell session. These files are used to set up your shell environment. They can be used to set up aliases, functions, and environment variables.
79
Where are configuration files stored?
These files are located in your home directory (~) and are hidden by default. The ls command has a -a flag that will show hidden files: ls -a ~ If you're using Bash, .bashrc is probably the file you want to edit. If you're using Zsh, .zshrc is probably the file you want to edit or create if it doesn't yet exist. Example: You need to figure out what shell commands run automatically when a user logs in on the machine. You need to confirm which shell configuration file is being used. Edit the file you believe to be your shell configuration file. You can use the nano command to edit files in your terminal: nano ~/.bashrc Add the following line to the bottom: echo "Hello from the shell!" You can use Ctrl+O to save the file (confirm any prompts with "enter"), and then Ctrl+X to exit the editor. (There should be a list of commands at the bottom of the screen.) (When you restart your shell you'll see "Hello from the shell!" because the config file runs automatically when you start a new shells session.
80
Environment Variable
They're available to all programs that run in your shell.
81
env
You can view all environment variables that are currently set in your shell with the env command
82
export
# Lane To set a variable in your shell, use the export command: Example: export NAME="Lane" You can then use that variable in your shell: echo $NAME Note: Programs and scripts you run in you shell can also use that variable. Example: We create a file called introduce.sh with the following contents: #!/bin/sh echo "Hi I'm $NAME" Then we run it: chmod +x ./introduce.sh ./introduce.sh #Hi I'm Lane
83
What can you do instead of exporting an environment variable?
Exporting means the variable will persist until you close the shell. You could temporarily set a variable for a single command.
84
PATH
A variable that is built into your shell. The PATH variable is a list of directories that your shell will look into when you try to run a command. ("built-in" means that different programs and parts of your system know about them and how to use them. ) Example: If you type ls, your shell will look in each directory listed in your PATH variable for an executable called ls. If it finds one, it will just run it. If it doesn't, it will give you an error like: "command not found".
85
How do you see your current PATH variable?
echo $PATH You should see a giant list of directories separated by colons (:). Each of those directories is a place where your shell will look for executables. For example, with a PATH like this: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin Your shell will look for executables in the following directories: /usr/local/bin /usr/bin /bin /usr/sbin /sbin
86
Why would the following error occur? #install a new program $ my-new-program -bash: my-new-program: command not found
9/10 times it's because the program is installed in a directory that's not in your PATH variable. Oftentimes when you install a program using CLI, it will print a message during installation that tells you where the command was installed. Don't let your eyes glaze over when your terminal prints important messages! Sometimes you just gotta rtfm.
87
man
manual command. It will only work for programs that have a manual, but most built-in commands and Unix programs are supported. Just pass the name of the command as an argument. Example: #open the manual for the grep command man grep
88
/-r n N spacebar q
The following are used to navigate manuals: /-r: type to start searching n: press 'n' to jump to the next result N: press 'N' to go back if you went too far spacebar: use the spacebar to page through the manual q: quit with q
89
Flags
Some commands accept flags. Flags are options that you can pass to a command to change its behavior. For example, the ls command can take a -l flag to show a "long" listing of files: ls -l Or the -a flag to show "all files, including hidden files: ls -a You can also combine flags: ls -al
90
How many dashes for flags?
Single-character flags are prefixed with a single dash (.e.g -a) Multi-character flags are prefixed with two dashes (e.g. --help) Sometimes the same flag can be used with a single dash or two dashes (e.g. -h or --help)
91
[] square brackets in documentation (like manuals) mean what?
Square brackets [] in documentation mean optional — you do not type them
92
Most production-ready CLI tools have a "help" option that prints information about how to use the tool. How do you access it?
--help (flag) -h(flag) help (first positional argument) Example: Print out the help manual for help: #any of the following options may work: curl --help curl -h curl -help curl --help all curl -h all
93
Exit Codes What's the exit code for success? What's the exit code for an error?
0 is the exit code for success. Any other exit code is a zero. 9 times out of 10, if a non-zero code is returning (meaning an error), it will be a 1, which is the "catch-all" error code.
94
How can you access the exit code of the last program you ran in a shell?
With the question mark variable ($?) For example, if you run a program that exits, you can see what it was with the echo command: echo $? # non-zero (depends on your OS. echo $? # 0
95
Standard Output/Standard Out/Stdout
"Standard Output", usually called "standard out" or "stdout", is the default place where programs print their output. It's just a stream of data that prints to your terminal, but we'll talk later about how it can be redirected to other places. All programming languages have a simple way to print to stdout. In Python, it's the print function: print("Hello world") # Hello world In a shell, it's the echo command: echo "Hello world" # Hello world
96
Standard Error/stderr
standard error/stderr is a data stream just like standard output, but is intended to be used for error messages. It's a separate stream so that you can redirect it to a different place if need be, but by default, it prints to your terminal just like stdout.
97
Redirecting Streams (i.e., redirecting stdout and stderr to different places)--what operators are used?
Redirecting Streams You can redirect stdout and stderr to different places using the > and 2> operators. > redirects stdout, and 2> redirects stderr. Redirect stdout to a File echo "Hello world" > hello.txt cat hello.txt # Hello world Redirect stderr to a File cat doesnotexist.txt 2> error.txt cat error.txt # cat: doesnotexist.txt: No such file or directory
98
"Standard Input", usually called "standard in" or "stdin",
It's the default place where programs read their input. It's just a stream of data that programs can read from as they run.
99
Piping
One of the most beautiful things about the shell is that you can pipe the output of one program into the input of another program. With this one simple concept, you can run incredibly powerful automation tasks. Pipe The pipe operator is |. It's the character that looks like a vertical line. It's usually on the same key as the backslash (\) above the enter key. The pipe operator takes the stdout of the program on the left and "pipes" it into the stdin of the program on the right. echo "Have you heard the tragedy of Darth Plagueis the Wise?" | wc -w # 10 In the example above, the echo command sends "Have you heard the tragedy of Darth Plagueis the Wise?" to stdout. However, instead of that text being sent to your terminal, the pipe operator pipes it into the wc (word count) command. The wc command counts the number of words in the input it receives. The -w flag tells wc to only count words.
100
SIGINT/ctrl + c
Sometimes a program will get stuck and you'll want to stop it. Common reasons for this are: You made a typo in the command and it's not doing what you want It's trying to access the internet but you're not connected It's processing too much data and you don't want to wait for it to finish There is a bug in the program causing it to hang In these cases, you can stop the program by pressing ctrl + c. This sends a "SIGINT" signal to the program, which tells it to stop.
101
PID
stands for "process ID". Every process that's running on your machine has a unique ID.
102
ps
The ps, "process status" command can be used to list the processes running on your machine, and their IDs. Example: ps aux The "aux" options just mean "show all processes, including those owned by other users, and show extra information about each process".
103
kill
Kill process ID manually kill a program. Use when it doesn't respond to SIGINT (ctrl + c)
104
Text Stream
A text stream is just a sequence of characters that can be read or written sequentially. In other words, a text stream is just text.
105
Unix Philosophy
The Unix Philosophy is a simple set of principles that have guided the development of Unix-like operating systems for decades. It can be summarized as: Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
105
top
The top command is a powerful tool that allows you to see which programs are using the most resources on your computer.
106
How to use nvim to open a file
nvim FILEPATH_HERE
107
How to edit a file that was opened using nvim
Use the arrow keys (I know, Vim sacrilege) to move your cursor down to the last line. Enter "insert" mode by pressing the i key. You should see -- INSERT -- appear at the bottom of the screen.
108
How to save changes to a file opened with nvim and then exit nvim
When you're done, press the esc key to return to normal mode. Then type :w and press enter to save your changes. Finally, type :q and press enter to quit Neovim.
109
What is Neovim?
A terminal editor
110
with
A with block can be used to open a file: with open(path_to_file) as f: # do something with f (the file) here
111
If nvim has clipboard support, how do you copy and paste code?
To copy the whole file to system clipboard: Go to the top: gg Start visual line mode: V Go to the bottom: G Yank to system clipboard: "+y Now you should be able to paste here with your normal system paste (Ctrl+V / Cmd+V). To check if clipboard is supported, run inside nvim: :echo has("clipboard") If clipboard doesn’t work You can: Use your terminal’s mouse selection to highlight the text in nvim and copy it. Or, write the file and open it with a normal editor to copy: :w cat main.py Then select from the terminal output and copy.
112
Kernel
A kernel is the core part of an operating system. It acts as a bridge between software applications and the hardware of a computer
113
Software Application
software application (or app) is a computer program designed for end-users to perform specific tasks, like writing documents, browsing the web, playing games, or managing finances.
114
System Software
runs the computer itself.
115
Software Application vs System Software
A software application (or app) is a computer program designed for end-users to perform specific tasks, like writing documents, browsing the web, playing games, or managing finances, distinguishing itself from system software that runs the computer itself
116
How do you run a Python code file in Linux?
python main.py (python3 main.py)
117
Ubuntu
is an operating system (a Linux distribution)
118
WSL
WSL (Windows Subsystem for Linux) is a Microsoft feature letting you run a native Linux environment, including command-line tools, utilities, and apps, directly on Windows without a separate virtual machine or dual-booting
119
Linux Distribution/Distro
A Linux distribution is an operating system built on the Linux kernel, bundled with essential software, tools, and package managers, customized to serve different users like developers, enterprises, cybersecurity professionals, and general users. Includes the Linux kernel, system tools, package manager, and optional desktop environment. Comes with pre-installed tools, reducing manual setup. Built for different purposes like hacking, servers, development, or desktop use. Offers flexibility and customization based on user needs. Common Linux Distros: -Ubuntu (beginner friendly) -Kali Linux (cybersecurity) -Debian (advanced users and devs) -Fedora (devs) -Arch (advanced users who want to customize their system) -Mint (beginners and those transitioning from Windows) -Omarchy (dev, software engineer, and power user)
120
Software Engineer vs Software Developer vs Programmer
Software Engineer (Architectural & Scientific Focus) Role: Uses engineering principles to design, build, and test software systems. Focus: High-level design, scalability, and performance. Distinction: Focuses on the "how" of complex systems, often involving data structures and algorithms. Software Developer (Life Cycle & Creative Focus) Role: Involved in the entire development process, from conception to deployment. Focus: Creating applications, managing features, and user interaction. Distinction: More involved in the overall product vision compared to a pure programmer. Programmer (Implementation Focus) Role: Writes, debugs, and maintains code for software. Focus: Turning requirements into executable instructions in programming languages. Distinction: Often considered a more narrow, technical role focused on the specific syntax and logic of code.
121
Bash
Bourne Again Shell It's a shell. A program that interprets the commands you type and passes them to the operating system's kernel for execution. It also provides features like scripting, variables, loops, and conditional statements, essentially acting as its own programming language.
122
xterm-256color
A terminal type. Most modern terminals (e.g., Windows Terminal, VS Code Terminal, etc. use it.
123
Windows Terminal
The Terminal emulator that I'm using. (On Windows 11, WSL defaults to Windows Terminal unless explicitly overridden.)
124
My setup
A Microsoft feature letting you run a native Linux environment, including command-line tools, utilities, and apps, directly on Windows without a separate virtual machine or dual-booting: Windows Subsytem for LInux: (WSL) Linux Distro: Ubuntu Terminal Emulator: Windows Terminal Shell: Bash
125
Virtual Machine (VM)
A virtual machine (VM) is a software emulation that splits a single physical computing device into many isolated computing environments, each with its allocated CPU, memory, storage, and operating system. Much of the technology we benefit from today, such as cloud computing and artificial intelligence, is rooted in the concept of the virtual machine, which allows operating systems and software to be separated from a physical machine. Benefits: -Scalable: Cloud-based VMs make it easier to scale your applications, increasing availability and performance. -Portable: You can easily move VMs (which are a single software package with hardware resources, an operating system, and all of its applications) from one server to another or even from on-premises hardware into cloud environments -Reduced footprint and costs: VMs allow you to run multiple environments from a single machine, helping reduce your physical infrastructure footprint, electricity bill, and maintenance, and management costs. -Faster Provisioning: VMs can be easily duplicated, enabling businesses to spin up new, identical environments without having to set them up from scratch. -Reliability: -Reliability: VMs and their components exists virtually and remain isolated from other guest VMs. If a VM crashes, the other guest VMs will remain operational and the host machine won't be affected. -Better security: VMs allow you to run multiple operating systems without impacting the host operating system. VMs let you create safe, virtual environments to test apps or even study security vulnerabilities without high risk to the host machine. Challenges: -Performance Cost: Funning multiple operating systems and a hypervisor layer can come with a performance cost if the host machine isn't robust enough. -Efficiency Decrease: Virtual hardware may not be as efficient as the physical hardware of a physical machine. -Inefficient use of resources: Cloud providers offer virtual machines that are fixed in CPU and memoy they provide. Use Cases: -Server Consolidation: Running a single server application on a single physical computer is often a waste of resources, because hardware components such as memory and CPU are only partially utilized by the single application. Running VM applications helps with optimizing resource utilization, especially if containers run on top of each VM. -Risk Management: VMs can perform specific tasks considered too risky to carry out in a host environment, such as accessing virus-infected data or testing operating systems. -Development & Testing: Software testing ensures an application behaves as expected on all platforms and operating systems. Developers use VMs to access these various environments for testing purposes. VMs also create fully isolated environments for experimentation, as you can deploy various code updates without affecting the production environment. -Disaster Recovery: VMs are a convenient solution for backup and recovery as they are easily replicated, provisioned, and restored. Their portability allows for quick migration to various hosts, guaranteeing business continuity with minimal downtime during outages or security breaches. -Cloud Computing: Cloud environments are incredibly dynamic. Clients are continually provisioning and decommissioning compute instances with a wide variety of resource configurations. Without VMs, the flexibility and elasticity of the cloud wouldn’t be nearly as seamless as it is today.
126
App vs Feature
An app (application) is a complete software product or service designed to solve a user's problem, while a feature is a specific, individual function, capability, or "flashy selling point" within that app
127
crtl+l
Use to clear your terminal when it's cluttered.
128
129
cat vs less
cat (concatenate) Purpose: cat reads files sequentially and prints their entire contents to the standard output (your terminal screen) without pausing. Its main purpose is concatenation, such as combining multiple files into one. Best for: Quickly viewing small files that fit entirely on one screen. Concatenating multiple files (cat file1.txt file2.txt > combined.txt). Piping output to other commands (cat file.txt | grep "pattern"). Creating small files quickly from the command line (cat > newfile.txt, then type content and press Ctrl+D). Disadvantage: For large files, the content scrolls by rapidly, making it impossible to read or scroll back through easily (unless your terminal emulator has a large scroll-back buffer). The output remains in the terminal buffer after execution is complete. less (pager) Purpose: less is a powerful, interactive file viewer (or "pager") designed to display large files efficiently. It loads content one screen at a time and allows you to navigate forward and backward through the file. It stays active until you explicitly quit. Best for: Viewing large files without overwhelming the terminal or system memory, as it doesn't load the entire file at once. Interactive navigation (scrolling up/down using arrow keys, spacebar for next page, b for previous page). Searching within a file (type / followed by your search term and press Enter). Viewing documentation (the man command typically uses less as its pager). Disadvantage: Requires pressing q to exit and return to the shell prompt. By default, the text viewed in less disappears from the terminal screen upon exit, returning you to your previous prompt.
130
How do you navigate to desktop in WSL-Ubuntu?
cd /mnt/c/Users/YourUsername/Desktop
131
Indentation is off in nano text editor. What to do?
In nano, there are a few tricks to make your life easier: (In below example, file is called player.py) Launch with settings: Try opening your file with nano -ET 4 player.py. The -E tells nano to convert tabs to spaces, and -T 4 sets the tab width to 4 spaces, which is the Python standard. Show your position: While inside nano, press Alt + C (or Meta + C). This will show you the current line and column number at the bottom of the screen. If your def starts at column 5, the code inside it should start at column 9! Consistency is key: Never mix actual tabs and spaces. If you started using spaces, stick to them for the entire file.
132
What does -p stand for?
parents For example: Create a new directory called calculator and a pkg subdirectory inside of calculator. mkdir -p calculator/pkg
133
What do the following mean? . .. ../ ../something
"." = current directory ".." = parent directory "../" = parent directory "../something" = a sibling folder/file through the parent
134
How to open multiple panes/windows in a terminal-only environment
Open multiple terminal panes/windows If you're using a terminal multiplexer like tmux, you can split your screen: tmux then Ctrl+b % splits vertically, Ctrl+b " splits horizontally This lets you have one pane editing a file and another browsing the project If you're not using tmux, just opening a second terminal window works too. View a file without leaving your current directory You don't need to cd anywhere to read a file: cat functions/get_files_info.py Or for a paginated view: less functions/get_file_content.py Press q to exit less. List the project tree find . -type f -name "*.py" Or if tree is installed: tree . Use an editor with split views If you're using vim or neovim, you can open multiple files side by side: vim -O functions/get_files_info.py functions/get_file_content.py Ctrl+w w switches between panes.