Lecture 1 Flashcards

1
Q

How many namespaces do operating systems like Windows and Unix have?

A

Windows can have many. i.e. C:\, D:\, etc.
Unix has 1. /

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

What is a path name?

A

A description of where a file can be found.
In Unix example: dir1/dir2/dir3/file.c

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

What are some special directories in the Unix root?

A

/bin
/sbin
/lib
/usr
/etc
/home
/boot
/dev
/opt
/var
/tmp
/proc

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

/bin directory.

A

Where most executables or binaries are found. Things like gcc or vim. Essential for operation of the system itself.

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

Home directory shorthand.

A

~/
Know this well.

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

/sbin directory.

A

System binaries that should only be executed by the root (admin) user.

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

/lib directory.

A

Libraries.

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

/usr directory.

A

User binaries, libraries, etc. Meant for the end-user and not required for the system itself.

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

/etc directory.

A

Editable Text Configurations. Where configuration files are found.

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

/home directory.

A

User home (or personal) directories found here.

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

/boot directory.

A

Files needed to boot the system like the operating system kernel.

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

/dev directory.

A

Device files. Allows interface with I/O devices.

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

/opt directory.

A

Optional software located here. Rarely used.

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

/var directory.

A

Variable files that change as the system operates. Like log files.

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

/tmp directory.

A

Temporary files not persistent between system reboots.

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

/proc directory.

A

An imaginary directory created by the kernel to keep track of a currently running process.

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

Change directory command.

A

cd

18
Q

How to go to home directory?

A

~

19
Q

What does BASH stand for?

A

Bourne Again Shell.

20
Q

General format of commands.

A

command [arg1] [arg2] … [argn] RETURN

21
Q

Two ways to get help on a command through BASH.

A

command –help
or man command

22
Q

What command is EOF?

A

ctrl+d

23
Q

Output redirection.

A

> overwrites
> appends
command [arguments] > filename

24
Q

Input redirection

A

<
command [arguments] < filename

25
Q

Pipelines (review).

A

One or more commands separated by |
Connects standard output of the command preceding the pipe symbol to standard input of the following.
command_a [arguments] | command_b [arguments]

26
Q

echo command

A

Takes input and puts it in output.

27
Q

tr command

A

tr string1 string2
It then looks for characters that match string1 and finds the corresponding in string2.

Example:
tr abc xyz
a
x
abab
xyxy

28
Q

printf command

A

Different than C function.
Can be used in pipelines to pass input.

29
Q

What is BASH scripting?

A

One or more shell commands in a text file.
Running a BASH script makes it run the commands one by one.

Everything a BASH script can do can be done in the command line, and vice versa.

This includes variables and control structures.

30
Q

First line of a BASH script.

A

!/bin/bash

31
Q

How to write comments in BASH script?

A

comment goes here

32
Q

Variables in BASH.

A

They are strings.
name=value
or
let name=value
Leave no spaces around ‘=’

33
Q

Variable reassignment in BASH.

A

Use let.
Example:
let x=x+1

34
Q

Accessing command line arguments.

A

$1 gives first positional argument (‘arg1’).

35
Q

Using if-else in BASH.

A

if test-command
then
commands
fi

or

if test-command
then
commands
else
commands
fi

36
Q

test-command in BASH

A

Example:
[ $variable conditional-operator value ]
Such as [ $1 == “apple”]
Checks if arg1 passed to the command is “apple”.

37
Q

Conditional operators in BASH

A

== equality
!= not equality
< if string1 sorts before string2 lexicographically
> opposite of <

Also,

arg1 OP arg2
If OP is one of -eq, -ne, -lt, -le, -gt, -ge, they act as equal to, not equal to, less than, and so on

38
Q

How to chain if-else statements in BASH?

A

if test-command
then
commands
elif test command
then
commands

else
commands
fi

39
Q

! pneumonic to remember BASH scripts.

A

!, shabang

#!/bin/bash

40
Q

While loops in BASH.

A

while test-command
do
commands
done

41
Q

How to make a bash scipt?

A

vim myscript.sh
(.sh or .bash by convention)
convert to executable by using
chmod +x myscript.sh
run using
./myscript.sh